Depth-Limited Search (DLS)
Prerequisites
- DFS — Standard DFS algorithm and its limitations
🎯 Learning Objectives
- Modify DFS to include a depth limit l
- Understand the distinction between failure and cutoff return values
- Choose an appropriate depth limit using the diameter of the state space
- Analyze DLS properties: completeness, optimality, time, space
1. Motivation
DFS can go infinitely deep in trees with unbounded depth or cycles. Depth-Limited Search solves this by imposing a predetermined depth limit l. Nodes at depth l are treated as if they have no successors—the search does not expand them.
DLS is essentially DFS with an additional “depth ≥ l? stop.” check. This guarantees termination but introduces a new problem: what if the goal is deeper than l?
2. DLS Algorithm
function DEPTH-LIMITED-SEARCH(problem, limit):
return RECURSIVE-DLS(Node(problem.INITIAL-STATE), problem, limit)
function RECURSIVE-DLS(node, problem, limit):
if problem.GOAL-TEST(node.STATE): return SOLUTION(node)
else if limit == 0: return CUTOFF // depth limit reached
else:
cutoff_occurred = false
for each child in EXPAND(problem, node):
result = RECURSIVE-DLS(child, problem, limit - 1)
if result == CUTOFF: cutoff_occurred = true
else if result ≠ FAILURE: return result // solution found
if cutoff_occurred: return CUTOFF
else: return FAILURE
CUTOFF: No goal found within the depth limit, but there may be solutions at greater depths. The search space was not fully explored.
FAILURE: The entire search space (within the limit) was explored and no goal exists. This distinction is critical for Iterative Deepening Search, which uses CUTOFF to decide whether to try a deeper limit.
3. Choosing the Depth Limit
The depth limit l should be at least as large as the solution depth d. But d is usually unknown! We can use problem-specific knowledge:
The diameter of a state space is the longest shortest-path between any two states. If we know the diameter, we can use it as l because no solution can be longer than the diameter.
Examples:
- Romania map: 20 cities ⇒ diameter = 19 (at most 19 steps from any city to any other). So l = 19 is sufficient, but very loose if the actual solution is at depth 4.
- 8-puzzle: Maximum solution depth is 31 moves (from hardest start to goal). So l = 31 guarantees completeness.
If the depth limit is less than the solution depth, DLS will return CUTOFF and miss the solution entirely. There is no way to distinguish “no solution exists” from “solution is deeper than l” without trying a larger limit.
4. Properties of DLS
| Property | Value |
|---|---|
| Complete? | No, if l < d. Yes, if l ≥ d. |
| Optimal? | No. May find a deeper solution before a shallower one within the limit. |
| Time | O(bl) |
| Space | O(bl) — same as DFS but bounded by l instead of m. |
5. Worked Examples
Example 1: DLS with l = 2
S (depth 0)
/ \
A B (depth 1)
/ \ \
C D G (depth 2)
|
G' (depth 3, another goal)
DLS with l=2: Explores S, A, C (depth 2, leaf), D (depth 2, leaf—D’s child G′ at depth 3 is NOT expanded). Then B, G (depth 2, GOAL TEST → SUCCESS!).
Path found: S → B → G. Note that G′ at depth 3 was missed because l=2.
Example 2: DLS with l = 1
Same tree. DLS with l=1: Explores S (depth 0). Children A, B at depth 1. They are at the limit, so their children are not expanded. Neither A nor B is a goal → returns CUTOFF.
The goal at depth 2 was missed. This tells us l=1 is too shallow.
Summary
- DLS = DFS with a depth limit l. Nodes at depth l are not expanded.
- Returns CUTOFF if the limit was reached without finding a goal, or FAILURE if no goal exists within the limit.
- Choose l based on the diameter of the state space or domain knowledge.
- Complete only if l ≥ d. Not optimal. Time O(bl), space O(bl).
- DLS is the building block for Iterative Deepening Search.
References
- Russell & Norvig, AIMA, Chapter 3.4.4.