Iterative Deepening Depth-First Search (IDDFS)
Prerequisites
- BFS — Completeness, optimality, space problem
- Depth-Limited Search — DLS with cutoff return value
🎯 Learning Objectives
- Understand how IDDFS combines BFS completeness with DFS space efficiency
- Write the IDDFS algorithm: run DLS for limit = 0, 1, 2, …
- Prove the overhead of re-expansion is only a factor of b/(b−1)
- Know IDDFS properties: Complete, Optimal (unit cost), Time O(bd), Space O(bd)
- Recognize IDDFS as the preferred uninformed search for large state spaces
1. The Key Idea
IDDFS asks: “What if we don’t know the right depth limit?” Answer: try all limits! Run depth-limited search with limit 0, then 1, then 2, then 3, … until a solution is found.
This seems wasteful—we re-explore shallow nodes many times. But the overhead is surprisingly small, and we get the best of both worlds:
- From BFS: Completeness and optimality (unit cost)
- From DFS: O(bd) space—linear, not exponential!
2. IDDFS Algorithm
function ITERATIVE-DEEPENING-SEARCH(problem):
for depth = 0, 1, 2, 3, ...:
result = DEPTH-LIMITED-SEARCH(problem, depth)
if result ≠ CUTOFF: return result // SOLUTION or FAILURE
// never reaches here if state space is finite
Each call to DLS is a fresh search from scratch. When DLS returns CUTOFF, the goal might be deeper—increase the limit and try again. When it returns a SOLUTION or FAILURE (not cutoff), we’re done.
3. Step-by-Step Trace
Binary tree (b=2) with goal at depth 3:
S
/ \
A B
/ \ / \
C D E F
/
G (goal, depth 3)
Iteration 0 (limit=0): DLS explores only S. No goal → CUTOFF.
Iteration 1 (limit=1): DLS explores S, A, B. No goal → CUTOFF.
Iteration 2 (limit=2): DLS explores S, A, C, D, B, E, F. No goal → CUTOFF.
Iteration 3 (limit=3): DLS explores S, A, C, G → GOAL!
Path: S → A → C → G.
| Iteration | Limit | Nodes Expanded | Result |
|---|---|---|---|
| 0 | 0 | 1 (S) | CUTOFF |
| 1 | 1 | 3 (S, A, B) | CUTOFF |
| 2 | 2 | 7 (S, A, C, D, B, E, F) | CUTOFF |
| 3 | 3 | 4 (S, A, C, G) | SOLUTION |
Total nodes expanded: 1 + 3 + 7 + 4 = 15.
4. Overhead Analysis
The apparent waste of re-expanding nodes is much less than it appears. The total number of node generations is:
N(IDS) = (d+1)·b0 + d·b1 + (d−1)·b2 + … + 2·bd−1 + 1·bd
The root is generated (d+1) times, depth-1 nodes d times, …, depth-d nodes once.
Ratio to BFS: BFS generates N(BFS) = 1 + b + b² + … + bd nodes. The ratio is:
N(IDS) / N(BFS) ≈ b / (b − 1)
Numerical examples:
| b | Overhead Factor b/(b-1) | % Extra Work |
|---|---|---|
| 2 | 2.0 | 100% (nodes doubled) |
| 3 | 1.5 | 50% |
| 5 | 1.25 | 25% |
| 10 | 1.11 | 11% — negligible! |
| 100 | 1.01 | 1% |
For b=10 (common in GATE problems), IDDFS does only 11% more work than BFS—but uses exponentially less memory (O(bd) vs O(bd)). This is why IDDFS is the preferred uninformed search when the search space is large and the solution depth is unknown.
Detailed Calculation (b=10, d=5)
BFS: 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
IDS: 6·1 + 5·10 + 4·100 + 3·1,000 + 2·10,000 + 1·100,000 = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456
Ratio: 123,456 / 111,111 = 1.111 = b/(b−1) = 10/9. Confirmed!
5. Properties of IDDFS
| Property | Value | Explanation |
|---|---|---|
| Complete? | Yes (if b is finite) | Equivalent to BFS—it will eventually try limit = d and find the goal. |
| Optimal? | Yes (if step cost = 1) | Finds the shallowest goal first, just like BFS. |
| Time | O(bd) | Same asymptotic order as BFS (the overhead factor is constant). |
| Space | O(bd) | Same as DFS! Only stores one path at a time. This is the key advantage. |
“Which uninformed search strategy is preferred when the state space is large and the solution depth is unknown?” Answer: Iterative Deepening Search. It has BFS’s completeness and optimality, DFS’s memory efficiency, and only a small constant overhead factor.
6. More Worked Examples
Example 2: Total Nodes for b=3, d=4
IDS: 5·1 + 4·3 + 3·9 + 2·27 + 1·81 = 5 + 12 + 27 + 54 + 81 = 179
BFS: 1 + 3 + 9 + 27 + 81 = 121
Ratio: 179/121 = 1.48 ≈ 3/2 = b/(b−1). ✅
Example 3: Space Comparison
b=10, d=10. BFS space: O(1010) = 10 billion nodes (≈ 10 TB at 1 KB/node).
IDS space: O(10 × 10) = 100 nodes (≈ 100 KB). That’s a 100-billion-fold reduction!
Summary
- IDDFS runs DLS with limits 0, 1, 2, … until a solution is found.
- Combines BFS completeness + optimality with DFS space efficiency.
- Overhead factor: b/(b−1). For b=10, only 11% extra work.
- Time: O(bd), Space: O(bd).
- Preferred uninformed search for large state spaces with unknown solution depth.
References
- Russell & Norvig, AIMA, Chapter 3.4.5.