Short answer: IDA* applies iterative deepening to A*. Each pass is a depth-first search that refuses to step onto a vertex whose f = g + h exceeds the current bound. The next bound is the smallest f that was blocked. With an admissible heuristic, the first time the goal is reached the path is optimal. Memory is the current path, O(d), instead of A*’s frontier.
What the problem actually asks
A stores every generated vertex so it can pop the best f. In a puzzle or a planning graph that set is too large, while a single path down the tree is not. A depth-first search that prunes any branch whose f already exceeds a threshold explores exactly the vertices A would have considered inside that threshold, and it forgets them on the way back.
The thresholds have to increase to the next useful f, not by one, or a real-valued or sparse set of f values produces a pass that expands nothing new. The minimum blocked f is the next threshold at which some new vertex becomes legal.
What the algorithm guarantees
If h is admissible and edge weights are positive, the first time a pass reaches the goal, the goal’s g equals the optimal cost. Consistency of h is not required for that optimality claim, because the search is a tree search over paths and does not settle a vertex forever. Time can still be exponential, and a graph with many paths to the same vertex can re-expand that vertex on every path unless a transposition table is added. The stack uses O(d) memory. A transposition table uses more, up to A*-sized memory if it stores everything.
Each pass expands the vertices with f at or below the bound. The number of passes equals the number of distinct f values along an optimal decision, which for integer weights and an integer heuristic is at most the optimal cost. The last pass dominates when the tree grows geometrically.
The working steps
- Set the bound to h(source). The source has g = 0.
- Depth-first search from the source. On entering a vertex, if g+h exceeds the bound, record that f as a candidate for the next bound and backtrack without expanding.
- If the vertex is the goal, return the path. Admissibility makes this first success optimal.
- If the search returns without a goal, replace the bound by the minimum recorded overflow. If no overflow was recorded, the goal is unreachable.
- Repeat. Optional: a transposition table keyed by vertex and g can skip a path that already visited the vertex with an equal or better g in this pass.
Optimality needs an admissible heuristic and nonnegative costs. A heuristic that overestimates can return a suboptimal first success. The memory win disappears if the transposition table stores the whole graph. IDA is the memory-tight sibling of A, not a faster one on a graph that A* already fits.
Approaches that look simpler and fail
| Approach | Why it fails when the next bound is chosen poorly |
|---|---|
| Increase the bound by 1 regardless of the blocked f values | Correct when every f is an integer and every integer occurs, and wasteful or non-terminating in its logic when the next real f jumps. The minimum blocked f is the next bound that admits a new vertex. |
| Return the first goal an ordinary DFS finds | That path ignores f. IDA* is optimal because a cheaper goal would have had a smaller f and would have been admitted at an earlier bound. |
| Use an inadmissible h | The pass that first reaches the goal may have pruned the true optimal branch for exceeding a bound it would have survived under a lower estimate. |
| Store every generated vertex and still call the memory O(d) | That store is A*’s frontier. The O(d) claim is the path stack alone. |
A frontier that fits belongs to A*. No heuristic and a hop limit belongs to iterative deepening DFS. A consistent heuristic with plenty of memory does not need this repeated expansion.
A working example
This Python fragment deepens an f-cost bound. h is the number of hops still required in an unweighted sense, and it is admissible. The first time the goal is reached, the cost is optimal. It prints 3.
adj = {0: [(1, 1), (2, 4)], 1: [(2, 1), (3, 5)], 2: [(3, 1)], 3: []}
h = {0: 2, 1: 1, 2: 1, 3: 0}
def search(u, g, bound, path):
f = g + h[u]
if f > bound:
return f
if u == 3:
return True
minimum = 10**9
for v, w in adj[u]:
if v in path:
continue
path.add(v)
t = search(v, g + w, bound, path)
if t is True:
return True
minimum = min(minimum, t)
path.remove(v)
return minimum
bound = h[0]
while True:
t = search(0, 0, bound, {0})
if t is True:
break
bound = t
assert bound == 3
print(bound)
Where it is used
IDA* solves the 15-puzzle and other memory-tight pathfinding problems by deepening an f-cost bound instead of storing the open set. Game and puzzle solvers use it when A* would run out of memory. A* is the same scoring with a stored frontier.
When you can drop this algorithm
Drop IDA when A‘s frontier fits in memory. A expands each vertex less often. Keep IDA for a large state space with an admissible heuristic, where storing the frontier is the constraint and re-expanding paths is acceptable.
Why this stays published
We publish this so a search for IDA returns the f-bound, the minimum overflow that sets the next bound, and the admissible heuristic the first success relies on. IDA finds an optimal path with O(d) memory by depth-first searches capped at increasing f values, and the next cap is the smallest f the previous pass refused.**
本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。
