Search Strategies and Heuristics
Compare breadth-first, depth-first, uniform-cost, and A* search.
artificial intelligence, search, a-star, heuristicsDifferent questions, different frontiers
The frontier contains discovered paths waiting to be explored. Breadth-first search (BFS) explores by edge depth; depth-first search (DFS) follows a branch before returning. Their graph mechanics are explained in the existing BFS and DFS lesson. BFS finds a fewest-edge route in an unweighted graph; DFS does not generally find a shortest route.
Uniform-cost search (UCS) selects the lowest accumulated cost g. A* selects
the smallest f = g + h, where h estimates remaining cost. Use non-negative
edge costs in this example. Record best costs and discard outdated frontier
entries; test for the goal when removing a path for expansion, not merely
when first discovering it.
Compare a weighted map
Directed edges are S → A (2), S → B (1), A → G (2), B → G (5).
For A* use h(S)=3, h(A)=2, h(B)=4, h(G)=0.
- Expand S: A has
g=2, f=4; B hasg=1, f=5. - A* expands A and adds G with
g=4, f=4. - G is removed next, giving S → A → G at cost 4. UCS would expand B first
because B has the lowest
g, then A, and also return cost 4.
See the reasoning
Follow the example one step at a time
Trace A* on the weighted map using the lesson's heuristic. This is a prepared teaching demonstration, not live code execution.
Expand S
A: g=2 h=2 f=4 B: g=1 h=4 f=5
A has the lowest estimated total, even though B has lower cost so far.
Conditions matter
An admissible heuristic never overestimates the true remaining cost; a
consistent heuristic also obeys h(u) ≤ cost(u,v) + h(v) on each edge,
with zero at a goal. Under standard conditions A* graph search using a
consistent heuristic and goal-on-removal finds an optimal path; admissible but
inconsistent heuristics can require reopening improved states. Ties affect
visit order. Infinite spaces, zero-cost cycles, insufficient memory and
incorrect models require additional care.
Reflect on the concept
Four fixed questions to reinforce the reasoning. Answers are not saved or scored.
