Hirschberg's algorithm (1975) reduces the space complexity for the longest common subsequence problem from $O(N^2)$ to $O(N)$ via recursive midpoint bisection on a grid dynamic program (DP). We show that the underlying idea generalizes to a broad class of dynamic programs with local dependencies on directed acyclic graphs (DP DAGs). Modeling a DP as deterministic time evolution over a topologically ordered DAG with frontier width $ω$ and bounded in-degree, and assuming a max-type semiring with deterministic tie breaking, we prove that in a standard offline random-access model any such DP admits deterministic traceback in space $O(ω\log T + (\log T)^{O(1)})$ cells over a fixed finite alphabet, where $T$ is the number of states. Our construction replaces backward dynamic programs by forward-only recomputation and organizes the time order into a height-compressed recursion tree whose nodes expose small "middle frontiers'' across which every optimal path must pass. The framework yields near-optimal traceback bounds for asymmetric and banded sequence alignment, one-dimensional recurrences, and dynamic-programming formulations on graphs of bounded pathwidth. We also show that an $Ω(ω)$ space term (in bits) is unavoidable in forward single-pass models and discuss conjectured $\sqrt{T}$-type barriers in streaming settings, supporting the view that space-efficient traceback is a structural property of width-bounded DP DAGs rather than a peculiarity of grid-based algorithms.
Dynamic programming (DP) is a central paradigm for discrete optimization and combinatorial problems. Given a DP formulation on a directed acyclic graph (DAG), we typically distinguish two tasks:
• Value computation: compute the optimal value x t at a designated sink t;
• Witness reconstruction: reconstruct a specific optimal witness: e.g., a path from a source to t, an alignment, a labeling, or other structured solution.
For many DP formulations-on grids, banded lattices, and pathwidth-or treewidth-based decompositionsthe value x t can be computed in space proportional to a structural width parameter, such as a frontier width ω or a pathwidth pw(G), by storing only a single frontier of DP states at a time. In contrast, witness reconstruction is usually implemented by storing the entire DP table or a large fraction of it, requiring Θ(T ) space where T is the number of states. This raises a question:
For width-bounded DPs where the decision problem can be solved in O(ω) space, how much additional space is actually needed to recover a single optimal witness? Hirschberg as a motivating example. A classical exception to the Θ(T ) traceback pattern is Hirschberg’s algorithm for LCS/edit distance [1]. On an m × n grid DP (T = Θ(mn), frontier width ω = min{m, n} under a natural row-or column-major topological order), naive traceback requires O(mn) space. Hirschberg’s divide-and-conquer algorithm recursively bisects along the longer dimension, uses forward and backward DPs to identify a midpoint on some optimal alignment, and recurses on the two subproblems. This reconstructs an optimal alignment in O(m + n) space. The standard presentation is tightly coupled to the 2D grid geometry and the fact that the reverse DP has the same frontier width as the forward DP. This work: a structural “Universal Hirschberg” theorem. We generalize Hirschberg’s idea from grids to arbitrary time-ordered DP DAGs with bounded frontier width, in an offline model with random access to the instance and inexpensive recomputation. Informally: Theorem 1 (Informal main result). Let G be a DP DAG on T vertices equipped with a fixed topological order τ , frontier width ω = ω(G, τ ), bounded in-degree, and a max-type semiring recurrence with deterministic tie-breaking, so that each vertex has a unique witness predecessor. In the standard random-access multitape Turing-machine (or RAM) model, there is a deterministic algorithm that, given an encoding of G and a designated sink t,
• computes x t and outputs the canonical optimal source-to-t witness path (as determined by the fixed tie-breaking rule),
• runs in time poly(T ), and Thus, up to polylogarithmic factors, traceback can be done in essentially the same space as value computation for any DP DAG whose frontier width is bounded under some topological order. No geometric symmetry, band structure, or small-width backward DP is required; the only structural parameter that enters the space bound is the frontier width ω.
Techniques and scope. Our algorithm organizes the fixed topological order into a balanced binary recursion tree over intervals of “time”. Each node induces a subproblem whose internal vertices lie in a time window I, with small interfaces to the rest of the DAG. At each level, we:
• identify a middle frontier F mid I across which every optimal path relevant to the subproblem must pass;
• compute prefix values from the left boundary to each v ∈ F mid I by a single forward DP on I;
• compute suffix values from each v ∈ F mid I to the sink t via forward-only recomputation on subintervals (no backward DP on the reversed graph);
• select a canonical midpoint vertex v ⋆ using the max-type semiring and deterministic tie-breaking; and
• recurse on the left and right subintervals, carrying only boundary values and a small amount of recursion metadata.
The working frontier buffer always stores at most ω DP values at any time, and the recursion tree has depth O(log T ); recursion metadata fits in O(polylog T ) space. We work throughout with finite DAGs of bounded in-degree, max-type semirings with deterministic witnesses, and deterministic algorithms in a random-access model with running time polynomial in T .
• for asymmetric sequence alignment on an m×n grid with m ≤ n, traceback in space O(m log(mn)+ polylog(mn));
• for one-dimensional recurrences with constant in-degree, traceback in space O(polylog T );
• for banded alignment with bandwidth B, traceback in space O(B log(BN ) + polylog(BN )); and
• for DPs on DAGs of pathwidth pw(G), traceback in space O pw(G) log |V | + polylog |V | .
We also show that an Ω(ω) term (in bits) is unavoidable in any forward, single-pass model where the input is streamed once in topological order, and we discuss conjectured √ T -type barriers in genuinely streaming settings, in contrast to the offline random-access model we analyze.
The rest of the paper develops the formal model and assumptions (Section 2), recasts Hirschberg’s algorithm i
This content is AI-processed based on open access ArXiv data.