Memra

Search & heuristic drills

◈ 5 cards

Hand-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.
Question shows…NameBecausefewest moves, unweightedBFS — FIFO queuelevel order = shortest inmovestight memory, deep treeDFS — LIFO stackone branch at a time; needsCLOSEDedge costs, no heuristicuniform costA* with h = 0edge costs + admissible hA* — f = g + hoptimal while h ≤ h*
Read the question, not the algorithm: the phrase it uses picks the search. Note the bottom two rows are the same algorithm — A* with and without a heuristic — which is the cleanest way to state the relationship under time pressure.
14251Sh=5Ah=4Bh=1Gh=0Optimal S→A→B→G, cost 4.
Expansion order and f at each step: S (0+5), A (1+4), B (3+1 on the cheaper route through A), G (4+0). The highlighted three-hop path costs 4, beating S→A→G at 6 and S→B→G at 5 — the heuristic steered without ever overestimating, so optimality held.
NORMAL ~/memra/learn/comp-456/search-heuristic-drills utf-8 LF