Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Finding the way before taking a step
A route planner on a phone does not drive around to learn the roads; it already has the map and searches it. A clever search does not look in every direction equally: it prefers roads heading towards the destination, using the straight-line distance as a hint. As long as the hint never promises a shorter trip than is possible, the planner still finds the best route, and it looks at far fewer roads on the way.
Heuristic search runs in route planners, video-game characters, robot motion planners, logistics schedulers and the planners inside language-model agents.
- 1. Planning with a known map is…
- 2. A good hint for a route planner is…
- 3. For the best route, the hint must never…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Search problem: states, actions with costs, a start state and goal states; a plan is a sequence of actions from start to goal, and an optimal plan has the least total cost.
- Dijkstra’s algorithm (uniform-cost search): expand nodes in order of g(n), the cheapest known cost from the start.
- Heuristic h(n): an estimate of the cheapest cost from n to a goal. Admissible: never overestimates. Consistent: h(n) ≤ c(n, n′) + h(n′) for every edge, and h(goal) = 0.
- A (Hart, Nilsson and Raphael 1968):* expand in order of f(n) = g(n) + h(n); optimal with an admissible heuristic.
- Weighted A:* f = g + w·h with w > 1; finds a path costing at most w times the optimum, usually with far fewer expansions.
- Greedy best-first search: expand in order of h alone; fast, but with no guarantee on cost.
- Classical (STRIPS) planning: states are sets of facts, and actions have preconditions, add lists and delete lists; planners search this space, often with heuristics computed from relaxed problems.
- 1. A* expands nodes in order of…
- 2. An admissible heuristic…
- 3. Weighted A* with weight w returns a path costing at most…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Searching grid maps with walls and mud
Exercise 1.
- Random n × n grids: each cell is a wall (25%), mud costing 5 to enter (25%) or open ground costing 1; start top left, goal bottom right, 4-connected moves.
- One best-first search function covers every method by the priority f = g_weight·g + h_weight·h with h = h_scale × Manhattan distance: Dijkstra (h_weight = 0), A* (1, 1), weighted A* (h_weight 1.5 or 3), greedy best-first (g_weight = 0), and A* with an inadmissible heuristic (h_scale = 5, as if every step cost 5).
- Measured: path cost relative to the optimum and the number of nodes expanded.
Practice.
- Use A with the tightest admissible heuristic you can compute cheaply:* straight-line or octile distance on maps, pattern databases for puzzles, landmark (ALT) bounds on road networks.
- Trade optimality for speed knowingly: weighted A* and anytime variants (ARA*) give bounded-suboptimal answers quickly and improve them if time allows.
- Precompute for repeated queries: contraction hierarchies and landmarks make continental road routing take milliseconds.
- Use sampling-based planners in continuous spaces (RRT, PRM) and graph search on lattices or roadmaps built from them.
- Tools: networkx for graph search; Fast Downward for PDDL/STRIPS planning; OMPL for motion planning.
def search(cost, start, goal, h_weight=1.0, g_weight=1.0, h_scale=1.0):
h = lambda p: h_scale * (abs(p[0] - goal[0]) + abs(p[1] - goal[1]))
g, parent, closed = {start: 0.0}, {start: None}, set()
frontier = [(h_weight * h(start), 0, start)]; tie = 0
while frontier:
_, _, p = heapq.heappop(frontier)
if p in closed: continue
closed.add(p)
if p == goal: return g[p], len(closed)
for q in neighbours(p, cost):
gq = g[p] + cost[q]
if gq < g.get(q, np.inf):
g[q], parent[q] = gq, p; tie += 1
heapq.heappush(frontier, (g_weight * gq + h_weight * h(q), tie, q))- 1. Road-network routers use…
- 2. ARA* is…
- 3. A standard planner for PDDL problems is…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
A is optimal with an admissible heuristic.* Suppose A* is about to return a goal G with cost g(G) > C*, the optimal cost. Some node n on an optimal path is still on the frontier, with g(n) equal to its optimal cost-to-come, so f(n) = g(n) + h(n) ≤ g(n) + h*(n) = C* < g(G) = f(G). A* would expand n before G, a contradiction.
Consistency. If h is consistent, f never decreases along a path, so the first time A* expands a node its g is optimal and it never has to be re-opened. Consistent heuristics are admissible; the Manhattan distance times the cheapest step cost is consistent on a 4-connected grid.
How much a heuristic saves. A* expands every node with f(n) < C*. With h = 0 that is every node cheaper than C* to reach (Dijkstra); with h = h* it is only nodes on optimal paths. Effort falls as h approaches h*, so heuristic quality, not the algorithm, decides the speed.
Weighted A’s bound.* With f = g + w·h and h admissible, when the goal G is expanded every frontier node n satisfies g(G) ≤ g(n) + w·h(n). Taking n on an optimal path gives g(G) ≤ C* + (w − 1)h(n) ≤ wC*. Greedy best-first search has no such bound.
- 1. A* with an admissible heuristic returns…
- 2. With h = 0, A* becomes…
- 3. A* expands every node with f(n)…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How many nodes do Dijkstra, A*, weighted A*, greedy best-first and A* with an inadmissible heuristic expand on maps of growing size, and how far from optimal are their paths?
History.
- E. Dijkstra (1959) published his shortest-path algorithm.
- P. Hart, N. Nilsson and B. Raphael (1968) introduced A* for the Shakey robot project; I. Pohl (1970) introduced weighted heuristic search.
- R. Fikes and N. Nilsson (1971) introduced STRIPS; G. Sussman (1975) described the anomaly that defeats goal-by-goal planning.
- A. Goldberg and C. Harrelson (2005) introduced ALT landmark heuristics; R. Geisberger and colleagues (2008) introduced contraction hierarchies.
- M. Helmert (2006) released the Fast Downward planner.
Exercise 2.
- 30 solvable random maps for each size 20 × 20, 40 × 40 and 80 × 80, with 25% walls and 25% mud.
- For each method, the mean number of nodes expanded, the mean and worst ratio of path cost to the optimum, and the share of maps where it found an optimal path.
Seed 0, 80 × 80 maps:
| method | mean expansions | mean cost / optimal | worst | share optimal |
|---|---|---|---|---|
| Dijkstra | 4,747.5 | 1.000 | 1.000 | 1.000 |
| A* | 4,149.1 | 1.000 | 1.000 | 1.000 |
| weighted A*, w = 1.5 | 1,609.2 | 1.013 | 1.055 | 0.433 |
| weighted A*, w = 3 | 275.8 | 1.181 | 1.355 | 0.000 |
| greedy best-first | 240.3 | 1.819 | 2.162 | 0.000 |
| A*, h × 5 (inadmissible) | 237.1 | 1.313 | 1.470 | 0.000 |
- A was always optimal but saved little:* 13% fewer expansions than Dijkstra on 80 × 80 maps (14% to 17% on seeds 1 and 2), and 23% on 20 × 20 maps. The Manhattan heuristic assumes every step costs 1 in a straight line, far below the true cost through mud and around walls.
- Weighted A traded a little cost for a lot of speed:* with w = 1.5 it expanded 3.0 to 3.9 times fewer nodes than Dijkstra on 80 × 80 maps over three seeds, for paths 0.8% to 1.3% more expensive on average; with w = 3, 17 to 18 times fewer for 17% to 20% more. The worst ratios (1.069 and 1.531 over all runs) stayed within the guaranteed w.
- Greedy best-first search was fastest and worst: its paths cost 1.58 to 1.87 times the optimum on average across sizes and seeds.
- Exercise 1: on one 40 × 40 map, Dijkstra and A* found cost 110 with 1,120 and 579 expansions; weighted A* (w = 3) also found 110 with 92; greedy found 180 with 93.
Search and planning in practice
- Robotics: lattice planners and A* variants (D* Lite, hybrid A*) plan paths for mobile robots and cars, replanning as the map changes; sampling-based planners (RRT*) handle arms (topic L6-4 for the control side).
- Games: A* on navigation meshes moves characters; MCTS (topic L6-2) searches when outcomes are uncertain or adversarial.
- AI planning: PDDL planners schedule logistics, space missions and manufacturing.
- Language-model agents: tree search over reasoning steps (tree of thoughts, MCTS-guided decoding) borrows the same ideas.
References
- P. Hart, N. Nilsson and B. Raphael (1968). “A formal basis for the heuristic determination of minimum cost paths.” IEEE Transactions on Systems Science and Cybernetics.
- E. Dijkstra (1959). “A note on two problems in connexion with graphs.” Numerische Mathematik.
- R. Fikes and N. Nilsson (1971). “STRIPS: a new approach to the application of theorem proving to problem solving.” Artificial Intelligence.
- S. Russell and P. Norvig (2021). “Artificial Intelligence: A Modern Approach,” 4th edition, chapters 3 and 11. Pearson.
- M. Helmert (2006). “The Fast Downward planning system.” JAIR.