BFS explores level by level, DFS goes as deep as possible along one branch before backtracking, and DLS is DFS that stops at a fixed depth limit \(l\).
Example tree (start A):
A depth 0
/ \
B C depth 1
/ \ / \
D E F G depth 2
Breadth-first search (BFS) uses a FIFO queue. Order: A, B, C, D, E, F, G. It finds the shallowest goal first.
Depth-first search (DFS) uses a LIFO stack (or recursion). Order: A, B, D, E, C, F, G. It reaches deep nodes quickly but may wander down a long or infinite branch.
Depth-limited search (DLS) is DFS that treats nodes at depth \(l\) as having no children. With \(l = 1\): order A, B, C; D–G are never generated. If the goal is G, DLS with \(l = 1\) fails (cutoff), while \(l = 2\) finds it.
Comparison (\(b\) = branching factor, \(d\) = depth of shallowest goal, \(m\) = maximum depth, \(l\) = depth limit):
| Criterion | BFS | DFS | DLS |
|---|---|---|---|
| Data structure | Queue (FIFO) | Stack (LIFO) | Stack with depth limit |
| Complete? | Yes (finite \(b\)) | No (infinite or looping paths) | Only if \(l \ge d\) |
| Optimal? | Yes, if all step costs equal | No | No |
| Time | \(O(b^d)\) | \(O(b^m)\) | \(O(b^l)\) |
| Space | \(O(b^d)\) (high) | \(O(bm)\) (low) | \(O(bl)\) (low) |
| Main drawback | Memory | Can get stuck in deep/infinite paths | Choosing a good limit |
DLS fixes DFS's infinite-path problem; repeating DLS with \(l = 0, 1, 2, \dots\) gives iterative deepening search, which combines BFS's completeness with DFS's low memory.