Complexity Analysis of Uninformed Search
Prerequisites
- Comparison of Strategies — Overview of all uninformed search algorithms
- State Space — Branching factor b, depth d, maximum depth m
🎯 Learning Objectives
- Review Big-O notation in the context of search algorithms
- Formally derive time and space complexity for each uninformed strategy
- Compute numerical memory requirements for realistic problem sizes
- Understand the amortized analysis of IDDFS and why repeated work is negligible
- Recognise when exponential blowup makes uninformed search impractical
1. Big-O Notation Review
Big-O describes the upper bound on the growth rate of a function as the input size increases. For search algorithms, the “input size” is characterised by:
| Symbol | Meaning | Example |
|---|---|---|
| b | Branching factor — maximum number of successors per node | Chess ≈ 35, 8-puzzle = 3.5 avg |
| d | Depth of the shallowest goal node | 8-puzzle easy = 5, hard = 20+ |
| m | Maximum depth of the search tree (can be ∞) | Graph with cycles: m = ∞ |
| l | Depth limit (for DLS) | User-specified parameter |
| C* | Optimal solution cost | Shortest path cost in UCS |
| ε | Minimum step cost (> 0) | Smallest edge weight in graph |
💡 Key Asymptotic Facts
- In a uniform tree with branching factor b, level k has exactly bk nodes.
- Total nodes from level 0 to level k: 1 + b + b2 + … + bk = (bk+1 − 1) / (b − 1) = O(bk).
- The dominant term is always the last level: bk dwarfs all previous levels combined (for b ≥ 2).
2. BFS Complexity Derivation
2.1 Time Complexity
BFS explores nodes level by level. In the worst case, the goal is at depth d, and BFS must explore all nodes at levels 0 through d (and possibly generate level d+1 before the goal test at level d fires in some formulations):
T(BFS) = 1 + b + b2 + … + bd = (bd+1 − 1) / (b − 1) = O(bd)
With early goal test (at generation), BFS can detect the goal as soon as it is generated at depth d, saving the cost of expanding that level. At worst, it generates all of level d: O(bd) nodes.
2.2 Space Complexity
BFS stores the entire frontier (all nodes at the current level) plus the explored set. The frontier at depth d can have up to bd nodes:
S(BFS) = O(bd)
Memory is typically the bottleneck, not time. Generating nodes is fast; storing them is expensive.
2.3 Numerical Example
b = 10, d = 6. Nodes at level 6: 106 = 1,000,000. At 1 KB per node: 1 GB just for the frontier.
Total nodes explored (levels 0–6): 1,111,111. Total memory: ≈ 1.06 GB.
3. DFS Complexity Derivation
3.1 Time Complexity
DFS explores to the maximum depth m of the tree. In the worst case, DFS visits every node in the entire tree:
T(DFS) = 1 + b + b2 + … + bm = O(bm)
If m ≫ d (the tree is much deeper than the shallowest solution), DFS can be catastrophically slower than BFS. If m = d, DFS and BFS have the same time complexity.
3.2 Space Complexity
DFS stores only the nodes on the current path from root to the deepest node, plus the unexpanded siblings at each level. At each of the m levels, there are at most (b−1) unexpanded siblings:
S(DFS) = m × (b − 1) + 1 = O(b · m)
This is linear in the maximum depth — dramatically better than BFS’s exponential space.
3.3 Why O(b·m) Not O(m)?
⚠ Common GATE Mistake
Students often say DFS uses O(m) space. This is wrong! At each level of the path, DFS must remember (b−1) siblings yet to be explored. So the stack holds up to b·m nodes. Only if b is treated as a constant can you say O(m), but in asymptotic analysis b is typically a variable.
4. DLS Complexity Derivation
Depth-Limited Search is simply DFS truncated at depth l. The analysis mirrors DFS with m replaced by l:
T(DLS) = O(bl), S(DLS) = O(b · l)
If l < d, DLS fails to find the solution (incomplete). If l = d, it has the same complexity as BFS in time but vastly better space.
5. IDDFS Complexity & Amortized Analysis
5.1 Time Complexity
IDDFS performs DLS with limits 0, 1, 2, …, d. The total number of node generations is:
Level d nodes generated: 1 time (only in the final iteration) Level d-1 nodes: 2 times (in iterations d-1 and d) Level d-2 nodes: 3 times ... Level 1 nodes: d times Level 0 (root): d+1 times
Total node generations:
N(IDDFS) = (d+1)·1 + d·b + (d−1)·b2 + … + 2·bd−1 + 1·bd
5.2 The Overhead Factor
To find the ratio of IDDFS work to BFS work, we compute:
N(IDDFS) / N(BFS) ≈ b / (b − 1)
| b | b/(b−1) | Overhead |
|---|---|---|
| 2 | 2.00 | 100% extra work (2× BFS) |
| 3 | 1.50 | 50% extra work |
| 5 | 1.25 | 25% extra work |
| 10 | 1.11 | 11% extra work |
| 35 | 1.03 | 3% extra work |
💡 Key Insight
For b ≥ 10 (typical in AI problems), IDDFS does only ~11% more work than BFS, while using exponentially less memory. The “wasted” work is dominated by the last iteration’s fresh nodes.
5.3 Detailed Calculation for b = 10, d = 5
BFS total: 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
IDDFS total:
Iter 0: 1 = 1
Iter 1: 1 + 10 = 11
Iter 2: 1 + 10 + 100 = 111
Iter 3: 1 + 10 + 100 + 1,000 = 1,111
Iter 4: 1 + 10 + 100 + 1,000 + 10,000 = 11,111
Iter 5: 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
Total = 123,456
Ratio: 123,456 / 111,111 = 1.111 — exactly b/(b−1) = 10/9.
5.4 Space Complexity
Each iteration of IDDFS is a DLS call, which uses O(b·l) space. The deepest iteration has l = d:
S(IDDFS) = O(b · d)
6. UCS Complexity Derivation
6.1 The C*/ε Bound
UCS expands nodes in order of increasing path cost g(n). It will explore all nodes with g(n) < C* before finding the optimal goal. The “effective depth” is the number of steps to accumulate cost C* using minimum step cost ε:
Effective depth = ⌊C* / ε⌋
Therefore:
T(UCS) = S(UCS) = O(b1+⌊C*/ε⌋)
6.2 Special Case: Unit Costs
When all step costs equal 1 (i.e., ε = 1 and C* = d):
O(b1+⌊d/1⌋) = O(bd+1) = O(bd)
UCS reduces to BFS in the unit-cost case, as expected.
6.3 Worst Case: Tiny ε
b = 10, C* = 100, ε = 0.01. Effective depth = 100/0.01 = 10,000. Time = O(1010,001)—astronomically large! This shows that UCS can be impractical when step costs are very small relative to the optimal cost.
7. Bidirectional Search Complexity
7.1 Derivation
Each direction (forward and backward) runs BFS to depth d/2. The number of nodes per direction:
Nfwd = O(bd/2), Nbwd = O(bd/2)
Total: T(Bidirectional) = S(Bidirectional) = O(bd/2)
7.2 Comparison with BFS
The ratio of BFS to Bidirectional:
bd / (2 · bd/2) = bd/2 / 2
For b = 10, d = 10: speedup = 105 / 2 = 50,000×. The square root in the exponent makes a massive practical difference.
8. Memory Requirements: Comprehensive Table
Assuming 1 KB per node, b = 10:
| Depth d | BFS / UCS (unit) | DFS (m=d) | IDDFS | Bidirectional |
|---|---|---|---|---|
| 2 | 100 KB | 20 KB | 20 KB | 20 KB |
| 4 | 10 MB | 40 KB | 40 KB | 200 KB |
| 6 | 1 GB | 60 KB | 60 KB | 2 MB |
| 8 | 100 GB | 80 KB | 80 KB | 20 MB |
| 10 | 10 TB | 100 KB | 100 KB | 200 MB |
| 12 | 1 PB | 120 KB | 120 KB | 2 GB |
| 14 | 100 PB | 140 KB | 140 KB | 20 GB |
| 16 | 10 EB | 160 KB | 160 KB | 200 GB |
💡 Reading This Table
BFS becomes impractical beyond d ≈ 6–8 for b = 10. IDDFS remains feasible for any practical d. Bidirectional search is practical up to d ≈ 12–14, while offering much faster time than IDDFS.
9. When Exponential Blowup Matters
9.1 The Exponential Wall
All uninformed search strategies have exponential time complexity (at minimum O(bd) or O(bd/2)). This means:
- Doubling d squares the search time.
- Increasing b from 10 to 20 is far more devastating than increasing d by 1.
- For real-world problems with b = 35 (chess) and d = 80 (game length), uninformed search is completely infeasible.
9.2 Practical Limits
Assuming 106 nodes/second processing speed and 16 GB RAM:
| Algorithm | Max Feasible Depth (b=10) | Bottleneck |
|---|---|---|
| BFS | ~7 | Memory (16 GB holds ~1.6 × 107 nodes) |
| IDDFS | ~6 (time) / unlimited (memory) | Time (106 nodes/sec ⇒ d=6 takes ~1 sec, d=8 takes ~100 sec) |
| Bidirectional | ~14 | Memory and time both ≈ b7 = 107 |
| DFS | ~6 (time) / unlimited (memory) | Time; may also not find a solution at all |
9.3 Overcoming the Wall: Informed Search
The exponential barrier is the fundamental motivation for informed (heuristic) search strategies like A*, which reduce the effective branching factor using domain knowledge. See Chapter 3.
10. GATE Numerical Problems
Problem 1: Counting Nodes
Q: A search tree has b = 3 and d = 4. How many total nodes does BFS generate (including the goal node)?
A: Levels 0–4: 1 + 3 + 9 + 27 + 81 = 121 nodes. (Using the formula: (35−1)/(3−1) = 242/2 = 121.)
Problem 2: IDDFS Overhead
Q: For b = 4 and d = 3, compute the total nodes generated by IDDFS and compare to BFS.
A:
BFS: 1 + 4 + 16 + 64 = 85 IDDFS: Iter 0: 1 Iter 1: 1 + 4 = 5 Iter 2: 1 + 4 + 16 = 21 Iter 3: 1 + 4 + 16 + 64 = 85 Total: 1 + 5 + 21 + 85 = 112 Ratio: 112 / 85 = 1.318 ≈ b/(b-1) = 4/3 = 1.333
Problem 3: UCS Effective Depth
Q: In a weighted graph with b = 5, minimum edge cost ε = 2, and optimal solution cost C* = 12. What is the time complexity of UCS?
A: Effective depth = ⌊C*/ε⌋ = ⌊12/2⌋ = 6. Time = O(b1+6) = O(57) = O(78,125).
Problem 4: Memory Calculation
Q: A BFS search with b=10, d=5 stores 1.5 KB per node. How much RAM is needed?
A: Frontier at level 5: 105 = 100,000 nodes. Memory: 100,000 × 1.5 KB = 150 MB. Including explored set (all previous levels ≈ 11,111 nodes × 1.5 KB ≈ 16.7 MB), total ≈ 167 MB.
Problem 5: Bidirectional Savings
Q: Why is bidirectional search’s space complexity O(bd/2) and not O(bd)?
A: Each direction stores nodes only up to depth d/2. The forward frontier has O(bd/2) nodes and the backward frontier has O(bd/2) nodes. Total: 2·O(bd/2) = O(bd/2). The product bd/2·bd/2 = bd is the search space we avoid exploring.
Summary
- BFS: Time O(bd), Space O(bd) — memory is the bottleneck.
- DFS: Time O(bm), Space O(b·m) — great space, poor time guarantees.
- DLS: Time O(bl), Space O(b·l) — limited DFS, not complete if l < d.
- IDDFS: Time O(bd), Space O(b·d) — best of both worlds, overhead ≈ b/(b−1).
- UCS: Time O(b1+⌊C*/ε⌋), Space same — optimal for variable costs.
- Bidirectional: Time O(bd/2), Space O(bd/2) — dramatic speedup, still exponential.
- All uninformed strategies hit an exponential wall — motivating informed search (Chapter 3).
References
- Russell & Norvig, AIMA, Chapter 3.4 & 3.5.
- Korf, R. E. (1985). “Depth-First Iterative-Deepening.” Artificial Intelligence, 27(1), 97–109.
- Cormen, Leiserson, Rivest & Stein. Introduction to Algorithms, Chapter 3 (Asymptotic Notation).