Problem Solving as Search
Formulating a problem as states, actions, and a goal test; the four criteria every strategy is judged on; and why memory, not time, is what usually stops breadth-first search.
Before a problem can be searched it has to be described in a particular way. The description is deliberately spare, and that spareness is what lets one algorithm solve route planning, puzzle solving, and scheduling without knowing which of them it is working on.
The five parts of a search problem
A search problem is given by an initial state, a set of actions available in each state, a transition model saying which state each action leads to, a goal test, and a step cost for each action. Together the first three implicitly define the state space: the graph of every state reachable from the start.
The word implicitly is doing the work. The state space is never written down. It is generated on demand, one successor at a time, which is what makes it possible to search spaces with more states than there are atoms in the observable universe. A solution is a sequence of actions from the initial state to a goal, and an optimal solution is one of least total cost.
Four questions to ask about any strategy
Every strategy in this lesson is judged on the same four criteria:
- Completeness - if a solution exists, is the algorithm guaranteed to find it?
- Optimality - does it find the cheapest solution?
- Time complexity - how many nodes does it generate?
- Space complexity - how many does it hold in memory at once?
Complexity is expressed in the branching factor , the number of successors per node, and the depth of the shallowest goal.
Breadth-first and the memory wall
Breadth-first search expands the shallowest unexpanded node, so it finds a shallowest goal. It is complete when is finite, and it generates on the order of nodes provided the goal test is applied to each node as it is generated. Delay the test to expansion, as uniform-cost search has to, and the whole next level is generated first: .
The trap is the space. The whole frontier is held at once, so memory is too - the same exponential as the time. Russell & Norvig tabulate what that means with at a million nodes per second and a kilobyte per node, and draw the lesson plainly:
the memory requirements are a bigger problem for breadth-first search than is the execution time.
A search to depth 12 takes about thirteen days, which one might wait out. It also needs a petabyte of memory, which no ordinary machine has. Time is a nuisance; memory is a wall.
There is a second limitation. Breadth-first search returns the shallowest goal, which is the cheapest goal only if every step costs the same. When step costs differ, the fix is uniform-cost search: expand the node with the lowest path cost rather than the lowest depth. It is optimal for any non-negative step costs, though it can waste effort exploring large trees of tiny steps before it ever tries a big one.
Depth-first and iterative deepening
Depth-first search goes as deep as it can before backtracking, so it stores only the current path and its unexpanded siblings: memory for maximum depth . That is a dramatic saving. The price is that it is neither optimal nor - on an infinite or looping space - complete.
Iterative deepening takes the good half of each. Run a depth-limited search with limit 0, then 1, then 2, until a goal is found:
| Strategy | Complete | Optimal | Time | Space |
|---|---|---|---|---|
| Breadth-first | yes | if costs equal | ||
| Uniform-cost | if step costs | yes | - | large |
| Depth-first | no | no | ||
| Iterative deepening | yes | if costs equal |
The two rows, and the thirteen days and the petabyte above, assume the goal test on generation; at expansion each becomes .
The obvious objection is that the upper levels are regenerated on every iteration. The answer is that in a tree with a roughly constant branching factor almost all the nodes are in the bottom level, which is generated only once, so the repetition costs a constant factor while the memory saving is exponential. That is why iterative deepening is the standard uninformed method when the space is large and the solution depth is unknown.
Interactive: the same map, searched three ways
Every h here is honest: none overestimates the true remaining cost.
- Route found
- S - D - G
- Cost
- 13
- Cheapest possible
- 9
- On the frontier
- C:4
Greedy took S - D - G at cost 13, against a cheapest possible 9. It went to D because h(D) = 2 looks closer than h(C) = 4 - and it is closer. The estimate was not wrong. What greedy ignored is the 4 already spentgetting there, and by the time the detour reveals its price the node is expanded and never reconsidered. Switch the priority to f = g + h and watch the same map, the same heuristic, produce the cheaper road.
Before the quiz
Be able to state the five parts of a search problem, list the four evaluation criteria, give the time and space complexity of each strategy above, say precisely when breadth-first search is optimal, and explain the trade that makes iterative deepening worth its repeated work. The next module adds a heuristic and asks how much of this space can be skipped.
References & further reading
- Stuart Russell, Peter Norvig, Artificial Intelligence: A Modern Approach, Pearson (3rd edition), 2010· Kudos AI reference library
Copyrighted works are cited for reference only and are not hosted here; please consult the publisher for access.
Unlock the full path
This first lesson is free. Enrol to take the mastery quiz, earn XP, and unlock every module, with more interactive, runnable examples throughout.