Search & heuristic drills
◈ 5 cardsHand-trace BFS/DFS open–closed lists and an A* expansion, then re-run A* on a fresh graph — the Q4 task.
The search facts the exam tests
Q4 asks you to "explain, using an example, how the best-first heuristic principle is used in ." Behind that sit the uninformed searches you must also be able to hand-trace.
BFS vs DFS — the one-line distinction:
- BFS keeps OPEN as a FIFO queue (first in, first out). It explores level by level, so it finds the shortest path in number of moves. Cost: it holds a whole frontier in memory ().
- DFS keeps OPEN as a LIFO stack (or uses native recursion). It plunges down one branch first. It is memory-cheap but not shortest-path and can loop without a visited (CLOSED) set.
Both maintain a CLOSED list of already-expanded states so they never re-expand a node.
The best-first principle and
Best-first search keeps OPEN as a priority queue and always expands the node with the smallest evaluation . chooses
where is the actual cost from the start to , and is a heuristic estimate of the remaining cost from to the goal. thus expands the node that looks cheapest overall, balancing what it has spent () against what it expects to spend ().
Admissibility is the guarantee: if for all (the heuristic never overestimates the true remaining cost ), then returns an optimal (least-cost) path. Note that everywhere is admissible, and with degenerates to uniform-cost / BFS.
Worked example — Q4 on a small weighted graph
Edges (cost): , , , , . Admissible heuristics : .
- Start: OPEN . Expand .
- Generate : . Generate : .
- Tie at ; expand (it was pushed first). From : via ; via .
- Lowest now is on the cheaper path. Expand : via .
- Expand at . Optimal path , cost 4, beating the naive (cost 6) and (cost 5). The heuristic steered expansion toward the goal without ever overestimating, so optimality held.