Iterative deepening combines the memory economy of depth first search with the completeness and optimality of breadth first search.

The Idea

Iterative deepening depth-first search (IDS or IDDFS) runs depth-limited DFS repeatedly with limit L = 0, 1, 2, 3, ... until a goal is found. Each iteration explores the tree to depth L using a stack, so memory is small; and since the limit grows one level at a time, the first goal found is at the shallowest depth, as with BFS. Thus IDS is complete (for finite branching) and optimal for equal step costs, with space only O(b·d).

Definition: Iterative deepening search. A strategy that performs depth-limited depth-first search with increasing limits 0, 1, 2, ... until a goal is found, combining DFS's low memory with BFS's completeness and optimality.

Is Repeating Work Wasteful

Nodes near the top are generated many times, but in a tree most nodes are at the bottom level, so the repetition costs little. If the branching factor is b and the goal is at depth d, the nodes at depth d are generated once, those at depth d − 1 twice, and so on. The total is N(IDS) = (d)b + (d − 1)b² + ... + (1)bᵈ, which is O(bᵈ), the same order as BFS. For b = 10 and d = 5: IDS generates 123,450 nodes against 111,110 for BFS, only about 11 percent more. So the repeated work is a minor price for the memory saving.

When to Use IDS

IDS is the preferred uninformed method when the search space is large and the depth of the solution is unknown. A related method, iterative lengthening, increases path-cost limits instead of depth. Bidirectional search runs two searches, one from the start and one from the goal, which meet in the middle and reduce the time to O(b^(d/2)), but needs predecessors to be computable.

Table 2.2: Uninformed strategies summary

Strategy Complete Optimal Time Space
BFS Yes Yes* O(bᵈ) O(bᵈ)
DFS No No O(bᵐ) O(b·m)
Depth-limited No No O(bˡ) O(b·l)
Iterative deepening Yes Yes* O(bᵈ) O(b·d)

Example 2.2: Node counts for IDS and BFS

Problem: Compare nodes generated by BFS and IDS for b = 10 and d = 3.

Solution:

  1. BFS generates 10 + 100 + 1,000 = 1,110 nodes (plus the root).
  2. IDS generates level-1 nodes 3 times, level-2 nodes 2 times and level-3 nodes once: 3(10) + 2(100) + 1(1,000) = 1,230.
  3. The extra work is 1,230 − 1,110 = 120, about 11 percent.
  4. Memory: BFS stores about 1,000 nodes; IDS only about 30 along one path.

Result: IDS generates 1,230 nodes against 1,110, but needs a tiny fraction of the memory.

def bfs_nodes(b, d):
    return sum(b**i for i in range(1, d + 1))
def ids_nodes(b, d):
    return sum((d - i + 1) * b**i for i in range(1, d + 1))
for d in (3, 5):
    x, y = bfs_nodes(10, d), ids_nodes(10, d)
    print(f"d={d} BFS={x} IDS={y} extra={100*(y-x)/x:.1f}%")

Output

d=3 BFS=1110 IDS=1230 extra=10.8%
d=5 BFS=111110 IDS=123450 extra=11.1%

Common mistakes

  • Thinking IDS wastes most of its work; the repeated top levels are cheap.
  • Forgetting that IDS needs only O(b·d) memory.
  • Using DFS with a fixed limit and assuming a solution exists within it.
  • Confusing iterative deepening with bidirectional search.

Key takeaways

  • IDS repeats depth-limited DFS with limits 0, 1, 2, ...
  • It is complete and optimal (equal costs) with O(bᵈ) time and O(b·d) space.
  • Repeated work is small because most nodes lie at the bottom level.
  • It is the preferred uninformed method for large spaces with unknown depth.

Practice questions

  1. What is the space complexity of iterative deepening?
  2. Why is the repetition in IDS acceptable?
  3. What does IDS combine?

Answers to the practice questions

  1. O(b·d).
  2. Most nodes are at the deepest level, so regenerating upper levels adds little.
  3. The low memory of DFS with the completeness and optimality of BFS.

Sources

  • Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit II