Cook's construction from 1971 [4] shows that any two-way deterministic pushdown automaton (2DPDA) can be simulated in time O(n), where n is the length of its input string, and the more general [5] s analogous results for other abstract machines. The goal of this paper is to make Cook's result usable for a broader spectrum of practical problems. We introduce a family of one-stack programs that includes 2DPDAs, and present a uniform way to compile any imperative stack program into a new and often faster version by using memoization. The method only explores the computational configurations that are reachable on the current input, in contrast to Cook's method, and builds programs that run in linear time if the original was a 2DPDA in program form. The transformation applies to algorithms not previously dealt with by Cook's method, e.g. fast computation of functions such as Fibonacci and (m n ).
Nils Andersen, Neil D. Jones