Algorithm Search⌘K

Proofs: Depth-limited search

These are the human proofs of Depth-limited search, at full length.

Depth-limited search stops, and its answer of path, cutoff or failure is exact full

This proof shows: correctness, termination.

We use the pseudocode of the page with the check for cycles. Without the check, read "path" below as "path that may repeat states" and treat onpath as always empty; each step of the proof stays the same. Let TT be the tree of paths from s0s_0 that repeat no state. A call DLS(s,k)(s, k) is made for a node π\pi of TT that ends at ss, and π\pi has depth ℓ−k\ell - k.

Invariant 1. When DLS(s,k)(s, k) is called for the path π\pi, the set onpath is exactly the set of states of π\pi, and each call leaves onpath as it found it.

Proof. At line L2 the path is (s0)(s_0) and onpath ={s0}= \{s_0\} by line L1. A call adds s′s' at line L9 before the recursive call for the path π\pi followed by s′s', and removes it at line L11 after the call returns, and s′s' was not in onpath by the test of line L8. The call returns at lines L3, L5, L6, L12 or L14, and each recursive call that it made has already undone its own addition. □\square

Theorem 1 (termination). If each state has finitely many successors, the search stops after at most N=∑i=0ℓbiN = \sum_{i=0}^{\ell} b^i calls, where bb is the largest number of successors.

Proof. Each call with k>0k > 0 makes at most bb calls with k−1k - 1, and a call with k=0k = 0 makes none. By induction on kk, a call with budget kk makes at most ∑i=0kbi\sum_{i=0}^{k} b^i calls in total, itself included. Each call does finitely many other steps. □\square

Lemma 2 (meaning of a returned path). If DLS(s,k)(s, k) returns a list rr for the path π\pi, then rr starts at ss, follows SUCCESSORS, ends at a goal state, has at most kk actions, and π\pi followed by rr without its first state repeats no state.

Proof. By induction on kk. A list is returned at line L3, where r=[s]r = [s] and ss is a goal, or at line L12, where r=[s]r = [s] followed by the list r′r' of a call DLS(s′,k−1)(s', k-1) for a successor s′s' of ss not on π\pi. By induction, r′r' is a path from s′s' to a goal with at most k−1k - 1 actions that avoids the states of π\pi followed by s′s', apart from s′s' itself. So rr has at most kk actions and the claim holds. □\square

Applied to the first call, Lemma 2 shows that a returned path goes from s0s_0 to a goal with at most ℓ\ell actions and repeats no state.

Lemma 3 (completeness within the budget). Let DLS(s,k)(s, k) be called for the path π\pi. If some goal state can be reached from ss by a path of at most kk actions that avoids the states of π\pi other than ss, then the call returns a path.

Proof. By induction on kk. If ss is a goal, line L3 returns. Otherwise the path to a goal has at least one action, so k≥1k \ge 1, and its second state s′s' is a successor of ss that is not on π\pi. So line L8 tries s′s', unless an earlier child already returned a path at line L12. By Invariant 1 the call DLS(s′,k−1)(s', k-1) is made for π\pi followed by s′s', and the rest of the path to the goal has at most k−1k - 1 actions and avoids that path. By induction it returns a path, and line L12 returns. □\square

A path to a goal of at most ℓ\ell actions can be shortened to one that repeats no state, by cutting out each cycle. So by Lemma 3 with π=(s0)\pi = (s_0) and k=ℓk = \ell, the search returns a path when some goal is within ℓ\ell actions of s0s_0.

Lemma 4 (meaning of failure). If DLS(s,k)(s, k) for the path π\pi returns failure, then no path from ss that avoids the states of π\pi other than ss has more than kk actions, and none of them ends at a goal.

Proof. By induction on kk. For k=0k = 0, failure comes from line L6: ss is not a goal and each successor of ss is on π\pi, so each path that avoids π\pi has 0 actions. For k≥1k \ge 1, failure comes from line L14 with cut false: ss is not a goal, no child returned a path, and no child returned cutoff, so each child s′s' not on π\pi returned failure. A path from ss that avoids π\pi and has at least one action starts with such an s′s', and by induction its remainder has at most k−1k - 1 actions and does not end at a goal. □\square

Theorem 5 (the answer is exact).

  1. The search returns a path if and only if some goal has a path of at most ℓ\ell actions from s0s_0, and the path is such a path.
  2. If it returns failure, no goal can be reached from s0s_0.
  3. If it returns cutoff, no goal has a path of at most ℓ\ell actions, and some path from s0s_0 that repeats no state has more than ℓ\ell actions.

Proof. Part 1 is Lemma 2 and Lemma 3 for the first call. For part 2, Lemma 4 for the first call says that each path from s0s_0 that repeats no state has at most ℓ\ell actions and does not end at a goal. Each reachable goal has a path that repeats no state, so no goal is reachable. For part 3, the first half is part 1. For the second half, follow the chain of calls that returned cutoff, from the first call down. A call returns cutoff at line L14 only if one of its children returned cutoff, and at line L5 only if k=0k = 0 and ss has a successor not on the path. So the chain ends at a call with k=0k = 0, for a path of ℓ\ell actions, which extends to a path of ℓ+1\ell + 1 actions that repeats no state. ■\blacksquare

Back to Depth-limited search