---
title: Interval-Memoized Backtracking on ZDDs
url: https://www.emergentmind.com/topics/interval-memoized-backtracking-on-zdds
type: topic
---

# Interval-Memoized Backtracking on ZDDs

Interval-memoized backtracking on Zero-suppressed Decision Diagrams (ZDDs) is a fast and memory-efficient algorithm for exactly enumerating all feasible solutions to combinatorial problems that fall below a specified cost bound. The technique leverages the structural sharing properties of ZDDs and introduces a novel memoization approach based on cost intervals, enabling it to avoid redundant exploration of subproblems and scale efficiently with large numeric bounds whenever the underlying ZDD representations are compact [2201.08118].

## 1. Zero-suppressed Decision Diagrams (ZDDs): Structure and Semantics

Let $I = \{1,2, \ldots, n\}$ denote a universe of items. A ZDD is a directed acyclic graph (DAG) constructed with two special terminal nodes, $0$ and $1$, and a set $V$ of non-terminal nodes. Each non-terminal node $v \in V$ is represented as a triple:
- $\mathrm{lvl}(v) \in I$: the item index tested at $v$
- $\mathrm{low}(v)$: the 0-child of $v$
- $\mathrm{high}(v)$: the 1-child of $v$

Each root-to-$1$ path in the ZDD encodes a subset $X \subseteq I$ such that if the high-edge of a node at level $i$ is traversed, then $i \in X$, and if the low-edge is taken, then $i \notin X$. The "zero-suppressed" property ensures that any node whose high-child is $0$ is deleted, and any two nodes with identical $(\mathrm{lvl}, \mathrm{low}, \mathrm{high})$ triples are merged, leading to substantial compression for collections of sets with many shared prefixes. The partial evaluation function is defined by $\mathrm{Sel}_v(0) = \mathrm{low}(v)$ and $\mathrm{Sel}_v(1) = \mathrm{high}(v)$ [2201.08118].

## 2. Interval-Memoized Backtracking: Core Mechanism

The objective is to enumerate all feasible subsets $X$ represented by the ZDD $f$ such that the total cost $\mathrm{Cost}(X) = \sum_{i \in X} c_i$ does not exceed some upper bound $b$. A naïve approach would recursively traverse the ZDD and revisit the same node multiple times for different residual budgets, incurring exponential overhead in scenarios with a large cost range. Interval-memoized backtracking introduces a mechanism to sidestep this inefficiency.

For each node $v$, the algorithm maintains a set $M_v$ of disjoint cost intervals $[L, U)$, each associated with a ZDD node $h$ that represents all subsolutions below $v$ with cost at most $b$ for any $b \in [L, U)$. The crucial definition is:

- A "safe" interval $[L, U) \subseteq \mathbb{Z}$ for node $v$ is one where, for any $b, b'$ such that $L \leq b < b' < U$, the sets of subsolutions of cost $\leq b$ and $\leq b'$ are identical.

This structure enables memoization of entire ranges of budgets, significantly reducing redundant computation relative to canonical memoization schemes indexed by exact budget values [2201.08118].

## 3. Recursive Algorithm and Memo-table Structure

The main recursion is specified as $\mathrm{Rec}(v, b) \rightarrow (h, aw, rb)$, where:
- $h$ is the ZDD for all root–$v$ paths of cost at most $b$
- $aw$ ("accept_worst") is the maximum budget for which $h$ remains valid
- $rb$ ("reject_best") is the minimum budget above which $h$ would change

The memo-table $\mathrm{Memo}[v]$ is a sorted map keyed by disjoint intervals $[L, U)$, maintaining pairings to $ZDD$ nodes for quick retrieval. If a budget query $b$ falls within a stored interval, the algorithm immediately returns the associated subresult; otherwise, it descends recursively, updating $b$ for the high-child by subtracting the corresponding $\mathrm{cost}(i)$. The combined results from the 0-child and 1-child are merged via $\mathrm{MakeZDD}(i, h_\mathrm{low}, h_\mathrm{high})$.

A summary of key operations:

| Operation                             | Description                                                    | Complexity         |
|----------------------------------------|----------------------------------------------------------------|--------------------|
| Lookup in Memo                        | Finds $[L,U)$ covering $b$ in $\mathrm{Memo}[v]$               | $O(\log k)$        |
| Recursive call on children            | 0-child (budget $b$), 1-child (budget $b-c$)                   | —                  |
| Interval update after recursion       | Computes new safe $[aw, rb)$, inserts into $\mathrm{Memo}[v]$   | $O(\log k)$        |
| Output ZDD merge/creation             | $\mathrm{MakeZDD}(i, h_\mathrm{low}, h_\mathrm{high})$         | —                  |

The result is an output ZDD containing all solutions not exceeding the given cost bound. This approach builds, shares, and memoizes subproblems efficiently by exploiting the cost-interval invariance properties emergent in many combinatorial search spaces [2201.08118].

## 4. Complexity Analysis and Theoretical Guarantees

Let $|V|$ denote the number of nodes in the input ZDD $f$, and $N = |h|$ the number of nodes in the output ZDD $h$. Assuming each interval lookup and insertion in $\mathrm{Memo}[v]$ requires $O(\log k)$ time (with $k \leq N$ current intervals per node), the total time complexity to compute the filtered ZDD is $O(|V| + N \log N)$. Each new visit to a pair $(v, b)$ not covered by existing intervals incurs such a cost and leads to a unique node in the output ZDD and insertion in the memo table.

In contrast, traditional pseudo-polynomial dynamic programming would fill a table of size $|V| \times B$, where $B$ is the numeric cost bound, resulting in $O(|V| B)$ time and space. For large costs $B$, classical DP becomes infeasible; the interval-memoized method's efficiency depends solely on the compressed sizes of the input/output ZDDs, making it practical for instances with large numeric domains but well-compressed decision diagrams [2201.08118].

## 5. Empirical Evaluation: Hamiltonian Path Instances

Practical efficiency is demonstrated on nontrivial instances, such as the Hamiltonian path problem for the 48-state US map (with $V = 48$ vertices and $E = 105$ edges), and on $n \times n$ grid graphs with random edge costs. Notable empirical results include:
- On the US map, the frontier-based ZDD has $|V_f| = 3616$. For increasing cost-bounds (up to 20% above minimum), the number of solutions expands to approximately $9.4 \times 10^5$. The interval-memoized approach constructs the filtered ZDD ($|V_h|$ up to $7.3 \times 10^4$) in about $0.09$ seconds with $1.6 \times 10^5$ recursive calls.
- In comparison, conventional memoization (by exact budgets) entails $O(10^6)$ calls and $0.66$ seconds; answer set programming solvers such as “clingo” require tens of seconds or may fail to complete.
- On $8 \times 8$ grid graphs (144 edges), up to $2.7 \times 10^9$ Hamiltonian paths are enumerated in 11 seconds, and $2.7 \times 10^{12}$ in 255 seconds.
- For $10 \times 10$ grids, as many as $1.4 \times 10^{15}$ paths are enumerated in under one hour.

These findings corroborate the significant efficiency gains of interval-memoized backtracking over more conventional methods for extensive enumeration tasks [2201.08118].

## 6. Comparison with Classical Methods and Scope of Applicability

Traditional branch-and-bound approaches are efficient for finding a single optimum but require enumeration of many intermediate solutions if all those with cost $\leq b$ are required, with minimal subproblem sharing. Pseudo-polynomial dynamic programming explodes in cost when faced with high numeric bounds, as its memory requirements scale linearly with $B$. In contrast, the ZDD-based interval-memoized approach’s performance is tied to the sizes $|V_f|$ (feasibility) and $|V_h|$ (output), both of which can be orders of magnitude smaller than a brute-force decision tree in problems exhibiting prefix-sharing, such as in path enumeration, matroid optimization, and knapsack-like problems.

A plausible implication is that for combinatorial problems where the set of all feasible solutions admits compact ZDD representations (i.e., with high prefix-sharing or exploitably sparse solution spaces), interval-memoized backtracking not only enables the enumeration of billions to trillions of constrained solutions efficiently, but also provides a practical alternative where classical paradigms are computationally infeasible [2201.08118].

Source: https://www.emergentmind.com/topics/interval-memoized-backtracking-on-zdds