Model a problem, then choose a frontier
01 / The story
Imagine a delivery robot inside a museum. A state might record only its room, but that description fails if some doors require a key: two visits to the same room can have different futures. Recording the room and key status repairs the model. The robot then keeps a tray of unfinished routes.
A queue explores nearby rooms first; a stack follows one corridor deeply; a priority tray follows the cheapest journey so far. The analogy separates two decisions: describe enough of the world to predict legal moves, then choose which unfinished route deserves attention.
02 / The principle
A search problem specifies an initial state, actions, a transition model, a goal test and path costs. Search nodes also store parent links and accumulated cost; multiple nodes may represent the same state. Breadth-first search uses a FIFO frontier and finds a shallowest goal with finite branching, giving minimum cost when steps have equal cost.
Depth-first search uses a stack, needs little frontier memory, but can follow an infinite branch and is not generally optimal. Depth-limited search can miss deeper goals.
Iterative deepening repeats increasing limits, retaining depth-first memory with shallowest-goal completeness under finite branching. Uniform-cost search removes the smallest accumulated cost and tests goals on removal; on infinite spaces its usual completeness guarantee needs costs bounded below by a positive number.
Words to know
- State
- Information sufficient to determine legal future actions.
- Frontier
- Generated routes waiting to be explored.
- Path cost
- The sum of step costs on one route.
03 / The formula, unpacked
g(n) = Σ edge costs along the route to n BFS: minimum depth; DFS: maximum current depth; UCS: minimum g(n) BFS tree frontier: O(bᵈ); DFS tree frontier: O(bm); IDS: O(bd)
The symbol g(n) is the cost already paid to reach search node n. The summation adds every edge on that route, not just the last edge. Here b is the finite branching factor, d the shallowest solution depth, and m the maximum search depth.
The memory bounds describe conventional tree-search frontiers; a graph-search visited set adds storage. Frontier order describes which node is expanded next, not the final path itself.
04 / A first worked example
A robot has routes S→A costing 1, A→G costing 9, S→B costing 4 and B→G costing 2. Both goals lie two edges away. If A is generated first, breadth-first search can return S→A→G, costing 10.
Uniform-cost search removes S, then A with cost 1, then B with cost 4. Its goal candidates have costs 10 and 6, so it removes the cost-6 candidate and returns S→B→G. Parent links reconstruct that route. The expansion list S,A,B,G is not itself a legal route.
Let us work through it
Why include a key in the state?
It changes which doors can be opened.
Why test UCS goals on removal?
An earlier generated goal may be more expensive than another unfinished route.
Is an expansion list a path?
Usually not; use parent links to reconstruct one connected route.
Work through a problem · 01
Two equal-depth routes
Directed edges are S→A:2,A→G:8,S→B:3,B→G:2. No other edges exist. A is generated before B. Compare BFS and UCS.
Choose the method
Separate the number of edges from the sum of their costs.
Both routes have two edges, so BFS can select A’s route by the stated order.
Add costs: S-A-G costs 2+8=10; S-B-G costs 3+2=5.
UCS removes A at 2, B at 3, then the goal at 5 before the goal at 10.
Interpret the answer
BFS can return cost 10; UCS returns S-B-G with cost 5.
Check the reasoning
The graph has only these two complete routes, and 5 is the smaller total.
Work through a problem · 02
A depth limit misses a solution
A chain S→A→B→G has unit costs. Root depth is zero. Try depth limit 2, then iterative deepening limits 0,1,2,3.
Choose the method
Label depths before deciding which nodes are reachable within a limit.
S,A,B,G have depths 0,1,2,3 respectively.
Limit 2 reaches B but cannot generate a permitted goal at depth 3.
Limits 0,1,2 fail; limit 3 reaches G and reconstructs all three edges.
Interpret the answer
The depth-2 search terminates without a solution; iterative deepening finds cost 3 at limit 3.
Check the reasoning
Three edges are unavoidable because the graph is a single chain.
Leon's further thinking
Cost changes the algorithm choice
Counting edges solves cheapest travel only when every edge has equal cost. With differing costs, compare accumulated sums.
State merging needs justification
Merging two room visits is safe only if their future legal actions and costs match. A remaining battery budget can matter just as a key does.
Check your understanding: When does breadth-first search behave like uniform-cost search?
When every step has the same positive cost and tie handling is aligned: accumulated cost is a constant times depth, so both expand layers in the same order.