Depth-limited Search
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, iterative deepening search or more specifically iterative deepening depth-first search (IDS or IDDFS) is a
state space A state space is the set of all possible configurations of a system. It is a useful abstraction for reasoning about the behavior of a given system and is widely used in the fields of artificial intelligence and game theory. For instance, the toy ...
/graph search strategy in which a depth-limited version of
depth-first search Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible alon ...
is run repeatedly with increasing depth limits until the goal is found. IDDFS is optimal like
breadth-first search Breadth-first search (BFS) is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next de ...
, but uses much less memory; at each iteration, it visits the
node In general, a node is a localized swelling (a "knot") or a point of intersection (a vertex). Node may refer to: In mathematics *Vertex (graph theory), a vertex in a mathematical graph *Vertex (geometry), a point where two or more curves, lines, ...
s in the
search tree In computer science, a search tree is a tree data structure used for locating specific keys from within a set. In order for a tree to function as a search tree, the key for each node must be greater than any keys in subtrees on the left, and less ...
in the same order as depth-first search, but the cumulative order in which nodes are first visited is effectively breadth-first.


Algorithm for directed graphs

The following pseudocode shows IDDFS implemented in terms of a recursive depth-limited DFS (called DLS) for
directed graph In mathematics, and more specifically in graph theory, a directed graph (or digraph) is a graph that is made up of a set of vertices connected by directed edges, often called arcs. Definition In formal terms, a directed graph is an ordered pa ...
s. This implementation of IDDFS does not account for already-visited nodes and therefore does not work for
undirected graph In discrete mathematics, and more specifically in graph theory, a graph is a structure amounting to a set of objects in which some pairs of the objects are in some sense "related". The objects correspond to mathematical abstractions called '' v ...
s. function IDDFS(root) is for depth from 0 to ∞ do found, remaining ← DLS(root, depth) if found ≠ null then return found else if not remaining then return null function DLS(node, depth) is if depth = 0 then if node is a goal then return (node, true) else return (null, true) ''(Not found, but may have children)'' else if depth > 0 then any_remaining ← false foreach child of node do found, remaining ← DLS(child, depth−1) if found ≠ null then return (found, true) if remaining then any_remaining ← true ''(At least one node found at depth, let IDDFS deepen)'' return (null, any_remaining) If the goal node is found, then DLS unwinds the recursion returning with no further iterations. Otherwise, if at least one node exists at that level of depth, the ''remaining'' flag will let IDDFS continue. 2-tuples are useful as return value to signal IDDFS to continue deepening or stop, in case tree depth and goal membership are unknown ''a priori''. Another solution could use
sentinel value In computer programming, a sentinel value (also referred to as a flag value, trip value, rogue value, signal value, or dummy data) is a special value in the context of an algorithm which uses its presence as a condition of termination, typically in ...
s instead to represent ''not found'' or ''remaining level'' results.


Properties

IDDFS combines depth-first search's space-efficiency and breadth-first search's completeness (when the
branching factor In computing, tree data structures, and game theory, the branching factor is the number of children at each node, the outdegree. If this value is not uniform, an ''average branching factor'' can be calculated. For example, in chess, if a "node" i ...
is finite). If a solution exists, it will find a solution path with the fewest arcs. Since iterative deepening visits states multiple times, it may seem wasteful, but it turns out to be not so costly, since in a tree most of the nodes are in the bottom level, so it does not matter much if the upper levels are visited multiple times. The main advantage of IDDFS in
game tree In the context of Combinatorial game theory, which typically studies sequential games with perfect information, a game tree is a graph representing all possible game states within such a game. Such games include well-known ones such as chess, check ...
searching is that the earlier searches tend to improve the commonly used heuristics, such as the
killer heuristic In competitive two-player games, the killer heuristic is a move-ordering method based on the observation that a strong move or small set of such moves in a particular position may be equally strong in similar positions at the same move (ply) in t ...
and
alpha–beta pruning Alpha–beta pruning is a search algorithm that seeks to decrease the number of nodes that are evaluated by the minimax algorithm in its search tree. It is an adversarial search algorithm used commonly for machine playing of two-player games ( ...
, so that a more accurate estimate of the score of various nodes at the final depth search can occur, and the search completes more quickly since it is done in a better order. For example, alpha–beta pruning is most efficient if it searches the best moves first. A second advantage is the responsiveness of the algorithm. Because early iterations use small values for d, they execute extremely quickly. This allows the algorithm to supply early indications of the result almost immediately, followed by refinements as d increases. When used in an interactive setting, such as in a
chess Chess is a board game for two players, called White and Black, each controlling an army of chess pieces in their color, with the objective to checkmate the opponent's king. It is sometimes called international chess or Western chess to disti ...
-playing program, this facility allows the program to play at any time with the current best move found in the search it has completed so far. This can be phrased as each depth of the search ''co''recursively producing a better approximation of the solution, though the work done at each step is recursive. This is not possible with a traditional depth-first search, which does not produce intermediate results.


Asymptotic analysis


Time complexity

The
time complexity In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by ...
of IDDFS in a (well-balanced) tree works out to be the same as breadth-first search, i.e. O(b^), where b is the branching factor and d is the depth of the goal.


Proof

In an iterative deepening search, the nodes at depth d are expanded once, those at depth d - 1 are expanded twice, and so on up to the root of the search tree, which is expanded d+1 times. So the total number of expansions in an iterative deepening search is :b^ + 2b^ + 3b^ + \cdots + (d-1)b^ + db + (d + 1) = \sum_^d (d+1-i)b^i where b^ is the number of expansions at depth d, 2b^ is the number of expansions at depth d - 1, and so on. Factoring out b^ gives :b^(1 + 2b^ + 3b^ + \cdots + (d-1)b^ + db^ + (d + 1)b^) Now let x = \frac = b^. Then we have :b^(1 + 2x + 3x^2 + \cdots + (d-1)x^ + dx^ + (d + 1)x^d) This is less than the infinite series :b^(1 + 2x + 3x^2 + 4x^3 + \cdots ) = b^ \left( \sum^_n x^ \right) which converges to :b^d (1 - x)^ = b^d \frac, for abs(x) < 1 That is, we have b^(1 + 2x + 3x^2 + \cdots + (d-1)x^ + dx^ + (d + 1)x^d) \leq b^d (1 - x)^, for abs(x) < 1 Since (1 - x)^ or \left(1 - \frac \right)^ is a constant independent of d (the depth), if b > 1 (i.e., if the branching factor is greater than 1), the running time of the depth-first iterative deepening search is O(b^d).


Example

For b=10 and d=5 the number is : \sum_^ (5 + 1 - i)10^i = 6 + 50 + 400 + 3000 + 20000 + 100000 = 123456 All together, an iterative deepening search from depth 1 all the way down to depth d expands only about 11 \% more nodes than a single breadth-first or depth-limited search to depth d, when b = 10. The higher the branching factor, the lower the overhead of repeatedly expanded states, but even when the branching factor is 2, iterative deepening search only takes about twice as long as a complete breadth-first search. This means that the time complexity of iterative deepening is still O(b^d).


Space complexity

The
space complexity The space complexity of an algorithm or a computer program is the amount of memory space required to solve an instance of the computational problem as a function of characteristics of the input. It is the memory required by an algorithm until it ex ...
of IDDFS is O(d), where d is the depth of the goal.


Proof

Since IDDFS, at any point, is engaged in a depth-first search, it need only store a stack of nodes which represents the branch of the tree it is expanding. Since it finds a solution of optimal length, the maximum depth of this stack is d, and hence the maximum amount of space is O(d). In general, iterative deepening is the preferred search method when there is a large search space and the depth of the solution is not known.


Example

For the following graph: a depth-first search starting at A, assuming that the left edges in the shown graph are chosen before right edges, and assuming the search remembers previously-visited nodes and will not repeat them (since this is a small graph), will visit the nodes in the following order: A, B, D, F, E, C, G. The edges traversed in this search form a
Trémaux tree In graph theory, a Trémaux tree of an undirected graph G is a type of spanning tree, generalizing depth-first search trees. They are defined by the property that every edge of G connects an ancestor–descendant pair in the tree. Trémaux trees ar ...
, a structure with important applications in
graph theory In mathematics, graph theory is the study of ''graphs'', which are mathematical structures used to model pairwise relations between objects. A graph in this context is made up of '' vertices'' (also called ''nodes'' or ''points'') which are conne ...
. Performing the same search without remembering previously visited nodes results in visiting nodes in the order A, B, D, F, E, A, B, D, F, E, etc. forever, caught in the A, B, D, F, E cycle and never reaching C or G. Iterative deepening prevents this loop and will reach the following nodes on the following depths, assuming it proceeds left-to-right as above: *0: A *1: A, B, C, E (Iterative deepening has now seen C, when a conventional depth-first search did not.) *2: A, B, D, F, C, G, E, F (It still sees C, but that it came later. Also it sees E via a different path, and loops back to F twice.) *3: A, B, D, F, E, C, G, E, F, B For this graph, as more depth is added, the two cycles "ABFE" and "AEFB" will simply get longer before the algorithm gives up and tries another branch.


Related algorithms

Similar to iterative deepening is a search strategy called
iterative lengthening search Iteration is the repetition of a process in order to generate a (possibly unbounded) sequence of outcomes. Each repetition of the process is a single iteration, and the outcome of each iteration is then the starting point of the next iteration. ...
that works with increasing path-cost limits instead of depth-limits. It expands nodes in the order of increasing path cost; therefore the first goal it encounters is the one with the cheapest path cost. But iterative lengthening incurs substantial overhead that makes it less useful than iterative deepening.
Iterative deepening A* Iterative deepening A* (IDA*) is a graph traversal and path search algorithm that can find the shortest path between a designated start node and any member of a set of goal nodes in a weighted graph. It is a variant of iterative deepening depth ...
is a best-first search that performs iterative deepening based on ""-values similar to the ones computed in the
A* algorithm A* (pronounced "A-star") is a graph traversal and path search algorithm, which is used in many fields of computer science due to its completeness, optimality, and optimal efficiency. One major practical drawback is its O(b^d) space complexity, ...
.


Bidirectional IDDFS

IDDFS has a bidirectional counterpart, which alternates two searches: one starting from the source node and moving along the directed arcs, and another one starting from the target node and proceeding along the directed arcs in opposite direction (from the arc's head node to the arc's tail node). The search process first checks that the source node and the target node are same, and if so, returns the trivial path consisting of a single source/target node. Otherwise, the forward search process expands the child nodes of the source node (set A), the backward search process expands the parent nodes of the target node (set B), and it is checked whether A and B intersect. If so, a shortest path is found. Otherwise, the search depth is incremented and the same computation takes place. One limitation of the algorithm is that the shortest path consisting of an odd number of arcs will not be detected. Suppose we have a shortest path \langle s, u, v, t \rangle. When the depth will reach two hops along the arcs, the forward search will proceed to v from u, and the backward search will proceed from v to u. Pictorially, the search frontiers will go through each other, and instead a suboptimal path consisting of an even number of arcs will be returned. This is illustrated in the below diagrams: What comes to space complexity, the algorithm colors the deepest nodes in the forward search process in order to detect existence of the middle node where the two search processes meet. Additional difficulty of applying bidirectional IDDFS is that if the source and the target nodes are in different strongly connected components, say, s \in S, t \in T, if there is no arc leaving S and entering T, the search will never terminate.


Time and space complexities

The running time of bidirectional IDDFS is given by and the space complexity is given by where n is the number of nodes in the shortest s,t-path. Since the running time complexity of iterative deepening depth-first search is \sum_^n b^k, the speedup is roughly


Pseudocode

function Build-Path(s, μ, B) is π ← Find-Shortest-Path(s, μ) ''(Recursively compute the path to the relay node)'' remove the last node from π return π \circ B ''(Append the backward search stack)'' function Depth-Limited-Search-Forward(u, Δ, F) is if Δ = 0 then F ← F \cup ''(Mark the node)'' return foreach child of u do Depth-Limited-Search-Forward(child, Δ − 1, F) function Depth-Limited-Search-Backward(u, Δ, B, F) is prepend u to B if Δ = 0 then if u in F then return u ''(Reached the marked node, use it as a relay node)'' remove the head node of B return null foreach parent of u do μ ← Depth-Limited-Search-Backward(parent, Δ − 1, B, F) if μ \neq null then return μ remove the head node of B return null function Find-Shortest-Path(s, t) is if s = t then return <s> F, B, Δ ← ∅, ∅, 0 forever do Depth-Limited-Search-Forward(s, Δ, F) foreach δ = Δ, Δ + 1 do μ ← Depth-Limited-Search-Backward(t, δ, B, F) if μ \neq null then return Build-Path(s, μ, B) ''(Found a relay node)'' F, Δ ← ∅, Δ + 1


References

{{DEFAULTSORT:Iterative Deepening Depth-First Search Graph algorithms Search algorithms