Skip to content
ml-recall

Topic notes

Search & Planning

State-space search (uninformed, A*, heuristics), constraint satisfaction, local search, game-tree search and classical planning, with the guarantees and costs of each.

5-min read AI-checked

Practise 86 questions Take a test

Key ideas

A search problem has states, actions (successors), step costs, a start and a goal test. Let bb = branching factor, dd = depth of the shallowest goal, mm = maximum depth.

Strategy Expands Complete? Optimal? Memory
BFS shallowest first (FIFO) yes (finite bb) fewest edges, so optimal only if all steps cost the same O(bd)O(b^d)
DFS deepest first (LIFO) no on infinite/cyclic graphs without a check no O(bm)O(bm)
Uniform-cost (UCS) lowest path cost gg yes, costs ≥ ε>0\varepsilon>0 yes can be large
Iterative deepening (IDS) DFS with limits 0, 1, 2, … yes fewest edges O(bd)O(bd)
Greedy best-first lowest hh no no —
A* lowest f=g+hf=g+h yes (see below) yes with admissible hh large

IDS repeats the shallow levels, but most nodes sit at the deepest level, so the overhead is small: for b=10b=10, d=5d=5 it generates 123,456 nodes against 111,111 for a single pass (about 11% more), while memory stays that of one DFS. UCS is Dijkstra's algorithm, i.e. A* with h=0h=01. BFS may goal-test when a node is generated; UCS and A* must test when it is popped, otherwise a cheaper path found later is missed.

Heuristics. hh is admissible if it never overestimates the true cost h∗h^*; consistent (monotone) if h(m)≤c(m,n)+h(n)h(m)\le c(m,n)+h(n) on every edge1 and h(goal)=0h(\text{goal})=0. Summing that inequality along a path to the goal shows consistent ⇒ admissible, and since f(n)=g(m)+c(m,n)+h(n)≥g(m)+h(m)=f(m)f(n)=g(m)+c(m,n)+h(n)\ge g(m)+h(m)=f(m), ff never decreases along a path. So with a consistent hh, A* expands nodes in non-decreasing ff, pops each node with its optimal gg and never needs to process it twice1. With an admissible but inconsistent hh, A* is optimal only if a node reached again by a cheaper path is put back on the open list1; a strict expanded list can return a suboptimal path. On an infinite graph A* still finds a solution, if one exists, when bb is finite and every edge costs at least some ε>0\varepsilon>01. Good admissible heuristics come from relaxed problems (e.g. Manhattan distance for the 8-puzzle), and the maximum of several admissible heuristics is admissible and at least as informed. Weighted A* (f=g+w hf=g+w\,h, w>1w>1) usually expands fewer nodes and returns a path costing at most w C∗w\,C^*1. A* keeps every generated node, its main drawback; memory-bounded variants such as IDA* (iterative deepening on ff) need memory linear in depth but re-expand nodes1.

Constraint satisfaction (CSP). Variables, domains, constraints; solved by backtracking2. Forward checking removes, after each assignment, the values of unassigned neighbours that conflict with it and backtracks when a domain empties; arc consistency (AC-3, MAC) also checks pairs of unassigned variables, so it prunes more3. Put the most critical variables first2: the one with the fewest remaining values (MRV)3, and on ties the one in the most constraints with unassigned variables (degree heuristic), whose value prunes the most other domains. Try first the value that removes the fewest values from other domains3.

Local search keeps one complete state. Hill climbing (greedy descent) moves to the best neighbour and stops at a local optimum4. Simulated annealing accepts a worse neighbour with probability e−ΔE/Te^{-\Delta E/T}: close to a random walk at high TT, greedy descent as T→0T\to 04. Tabu search keeps taking the best allowed move, even a worse one, but forbids undoing recent changes for a few steps (the tabu tenure), so it does not cycle back4. TSP 2-opt removes two edges and reconnects by reversing a segment. Beam search keeps the kk most probable prefixes; k=1k=1 is greedy search, cost grows as O(k ∣Y∣ T′)O(k\,|\mathcal{Y}|\,T') versus O(∣Y∣T′)O(|\mathcal{Y}|^{T'}) for exhaustive search5. A finite beam is guaranteed optimal only if it can hold every prefix.

Games. Minimax backs up max at MAX nodes and min at MIN nodes. Alpha–beta prunes branches that cannot change the decision, so it returns the same value and move6. With perfect move ordering the leaf count follows b×1×b×1⋯b\times1\times b\times1\cdots, about bd/2b^{d/2} instead of bdb^d, and iterative deepening supplies good ordering6. As an AND/OR tree, MAX needs one good move (OR node) that works against every MIN reply (AND node).

Planning (STRIPS). Each action has pre(a)pre(a), add(a)add(a), del(a)del(a). Forward (progression) planning picks the first action first; backward (regression) planning picks the last action first; a partial-order planner commits to an order only when forced7. It starts from a dummy start action (achieves the initial state) and finish action (preconditions = goal), keeps causal links a2→Pa3a_2\xrightarrow{P}a_3, and resolves a threat (an action that may undo PP between them) by ordering it before a2a_2 or after a3a_37. The Sussman anomaly (C on A; goal A on B and B on C) defeats planners that finish one subgoal before starting the other: whichever subgoal is achieved first must be undone to achieve the second8.

Formulas

f(n)=g(n)+h(n),admissible: h(n)≤h∗(n),consistent: h(m)≤c(m,n)+h(n)f(n)=g(n)+h(n),\qquad \text{admissible: } h(n)\le h^*(n),\qquad \text{consistent: } h(m)\le c(m,n)+h(n) IDS generations=∑i=0d(d+1−i) bi=O(bd),BFS (goal test on generation)≤∑i=0dbi\text{IDS generations}=\sum_{i=0}^{d}(d+1-i)\,b^{i}=O(b^d),\qquad \text{BFS (goal test on generation)}\le\sum_{i=0}^{d}b^{i}

Regression of goal gg through a relevant action (add(a)∩g≠∅add(a)\cap g\ne\emptyset, del(a)∩g=∅del(a)\cap g=\emptyset)7:

g′=(g∖add(a))∪pre(a)g'=\big(g\setminus add(a)\big)\cup pre(a)

Worked example

Edges S→A (2), S→B (5), A→B (1), B→G (3); h(S)=0h(S)=0, h(A)=4h(A)=4, h(B)=0h(B)=0, h(G)=0h(G)=0. True costs to G are 6, 4, 3, 0, so hh is admissible, but h(A)=4>c(A,B)+h(B)=1h(A)=4>c(A,B)+h(B)=1: not consistent. A* with a strict expanded list: pop S; push A (f=2+4=6f=2+4=6) and B (f=5f=5). Pop B, push G (f=g=8f=g=8). Pop A, push S–A–B (g=3g=3, f=3f=3); when it is popped, B is already expanded, so it is dropped. Pop G and return cost 8, while S–A–B–G costs 6. Re-opening B (non-strict list) gives the optimum.

Common pitfalls

References

  1. Wikipedia: A* search algorithm — Description (Pseudocode remark; Special cases); Properties (Termination and completeness; Admissibility); Bounded relaxation; Complexity (Space complexity)
  2. Wikipedia: Backtracking — Introduction; Examples — Constraint satisfaction (variable ordering)
  3. Wikipedia: Look-ahead (backtracking) — Look ahead techniques; Use of look ahead
  4. Poole & Mackworth, Artificial Intelligence — Foundations of Computational Agents, 3rd ed. (2023) — Sec. 4.6 Local Search (4.6.1 Iterative Best Improvement; 4.6.3 Local Search Variants — tabu search, Simulated Annealing)
  5. Dive into Deep Learning — Sec. 10.8 Beam Search (10.8.1 Greedy Search; 10.8.2 Exhaustive Search; 10.8.3 Beam Search)
  6. Wikipedia: Alpha–beta pruning — Core idea; Improvements over naive minimax
  7. Poole & Mackworth, Artificial Intelligence — Foundations of Computational Agents, 3rd ed. (2023), Ch. 6 Deterministic Planning — Sec. 6.3 Regression Planning; Sec. 6.5 Partial-Order Planning
  8. Wikipedia: Sussman anomaly — Introduction (the problem and both subgoal orders)