Depth-Limited Search (DLS)
Last updated
Last updated
The Depth-Limited Search (DLS) algorithm is an extension of the Depth-First Search (DFS) algorithm, designed to address the challenge of infinite paths in certain problem spaces. DLS introduces a predetermined depth limit to the search process, treating nodes at this limit as though they have no successors. By constraining the depth, DLS avoids the pitfalls of exploring infinite paths while maintaining the advantages of depth-first traversal. This makes it a valuable tool in solving problems with large or potentially unbounded search spaces, provided a suitable depth limit is chosen.
Depth Limitation: The algorithm restricts the search depth to a specified limit, ensuring that nodes beyond this depth are not expanded.
Failure Conditions:
Standard Failure: Indicates that the problem has no solution within the explored search space.
Cutoff Failure: Signals that the solution exists but lies beyond the specified depth limit.
Behavior with Cycles: By not revisiting nodes, DLS avoids infinite loops caused by cycles in the search graph, a common issue in classical DFS.
Memory Efficiency: DLS requires less memory than algorithms like Breadth-First Search (BFS), as it does not need to store all levels of the search tree simultaneously.
Complexity
Time Complexity: - same as DFS.
Space Complexity: - same as DFS.
Use Case: Solving problems with known depth constraints.
Memory Conservation: By limiting the depth, DLS reduces the memory requirements compared to BFS and Iterative Deepening Depth-First Search (IDDFS). It avoids the need to hold the entire search tree in memory, making it more efficient for certain problems.
Cycle Handling: DLS naturally mitigates issues with infinite loops in graphs containing cycles, as it stops expanding nodes at the depth limit.
Focused Exploration: The depth restriction ensures that unnecessary exploration of deeper levels is avoided, leading to faster processing in cases where the solution lies within the set limit.
Incompleteness: DLS is not guaranteed to find a solution if one exists, especially if the depth limit is set too low.
Non-Optimal Solutions: The algorithm may not produce the optimal solution when multiple solutions exist at different depths.
Dependency on Depth Limit: The effectiveness of DLS heavily relies on choosing an appropriate depth limit. A limit set too low may miss the solution, while a limit set too high can result in unnecessary exploration, reducing efficiency.
Depth-Limited Search strikes a balance between the exhaustive exploration of BFS and the memory constraints of DFS. Its utility lies in its ability to prevent infinite exploration while maintaining a structured approach to problem-solving. However, careful consideration must be given to the choice of the depth limit to ensure effective results, making it a trade-off between completeness and resource efficiency.
In the search tree below, the flow of the depth-first search follows this order:
The algorithm starts at the root node S (depth 0). It explores node A (depth 1), then moves to C (depth 2), and its children E and F (depth 3), which are not expanded further due to the depth limit. After that it backtracks to A and explores D (depth 2). Once A’s children are explored, the algorithm backtracks to S and explores B (depth 1), then I (depth 2), and finally reaches the goal node J at depth 3, terminating the search successfully.
Completeness:
The DLS algorithm is complete if the solution exists within the specified depth limit.
Time Complexity:
Space Complexity:
Optimality:
In PHP it can be written as a class UninformedSearchGraph
with implementation of a set of graph operations.
Example of Use:
To try this code yourself, install the example files from the official GitHub repository: https://github.com/apphp/ai-with-php-examples
The time complexity of the DLS algorithm is , where b represents the branching factor of the search tree, and is the depth limit.
The space complexity of the DLS algorithm is , where b is the branching factor and is the depth limit.
As a variation of DFS, depth-limited search is not optimal, even when the depth limit () exceeds the depth of the shallowest solution ().