Q1 — Best First Search, A* and Branch-and-Bound on a Grid Map
Three algorithms, one map — why each returns a different path, and why only Branch-and-Bound finds the shortest one.
The Question
A map on a uniform grid (each tile 10×10). Start S, goal G. MoveGen returns neighbours in alphabetical order. Heuristic = Manhattan Distance. Tie-breaker: node labels.
Subquestions
| # | Question | Official answer |
|---|---|---|
| 1.1 | Path found by Best First Search | S,D,F,G |
| 1.2 | Path found by A* | S,B,E,G |
| 1.3 | Path found by Branch-and-Bound (acyclic) | S,A,C,G |
| 1.4 | Which algorithm finds the shortest path? | B — Branch-and-Bound |
| 1.5 | Is the heuristic admissible? | B — Not admissible |
The Topic in 60 Seconds
All three algorithms keep a list of partial paths and repeatedly pick one, expand it — they differ only in how they pick:
| Algorithm | Picks the node with smallest | Ignores |
|---|---|---|
| Best First Search (greedy) | — estimated distance to goal | cost already paid |
| A* | nothing — balances both | |
| Branch-and-Bound | — exact cost so far | the heuristic entirely |
- = exact cost of the path from S to
- = heuristic estimate from to G
Deep-dive: A* Search, Best First Search, Branch and Bound.
Step 0 — Precompute the heuristic table
Manhattan distance on the grid: with G at (90, 60).
| Node | Coordinates | |
|---|---|---|
| S | (0, 30) | |
| A | (30, 0) | |
| B | (30, 30) | |
| D | (20, 50) | |
| E | (50, 60) | |
| F | (50, 90) | |
| C | (70, 0) | |
| G | (90, 60) |
Build this table before tracing anything — every subquestion reads from it.
1.1 — Best First Search → S,D,F,G
Best First picks the open node with the smallest only.
| Step | Open list (node : ) | Pick | Expand → add |
|---|---|---|---|
| 1 | S : 120 | S | D : 80, B : 90, A : 120 |
| 2 | D : 80, B : 90, A : 120 | D | F : 70 (B, S already seen) |
| 3 | F : 70, B : 90, A : 120 | F | E : 40, G : 0 |
| 4 | G : 0, E : 40, B : 90, A : 120 | G — goal! | — |
Path: S → D → F → G. Notice BFS never looked at edge costs — it just slid downhill on . Step through the trace exactly as you would write it in the exam:
1.2 — A* → S,B,E,G
A* picks the open node with the smallest .
| Step | Open list (node : , , ) | Pick | Updates |
|---|---|---|---|
| 1 | S : 0, 120, 120 | S | B : 40, 90, 130 · A : 50, 120, 170 · D : 60, 80, 140 |
| 2 | B : 130, D : 140, A : 170 | B | A via B: → 190 (worse than 170, keep 50/170) · E : 90, 40, 130 · D via B: → 160 (worse than 140, keep) |
| 3 | E : 130, D : 140, A : 170 | E | G : 130, 0, 130 · C : 150, 80, 230 |
| 4 | G : 130, D : 140, A : 170, C : 230 | G — goal! | — |
Path: S → B → E → G, cost .
A* returned cost 130, but 1.4 says the shortest path costs 100 (via A and C). A* can only be trusted to be optimal when is admissible — and 1.5 shows it is not. A single inadmissible node poisoned the search: the inflated scared A* away from the genuinely cheap S–A–C–G route.
1.3 — Branch-and-Bound → S,A,C,G
BnB picks the open path with the smallest and never extends a path that revisits a node (the "avoids cyclic expansions" note).
| Step | Open paths (path : ) | Pick | Extend with |
|---|---|---|---|
| 1 | S : 0 | S | SB : 40, SA : 50, SD : 60 |
| 2 | SB : 40, SA : 50, SD : 60 | SB | SBA : 70, SBE : 90, SBD : 80 |
| 3 | SA : 50, SD : 60, SBA : 70, SBD : 80, SBE : 90 | SA | SAC : 70 |
| 4 | SD : 60, SBA : 70, SAC : 70, SBD : 80, SBE : 90 | SD | SDF : 120, SDB : 100 |
| 5 | SBA : 70, SAC : 70, SBD : 80, SBE : 90, SDB : 100, SDF : 120 | SBA | SBAC : 90 |
| 6 | SAC : 70, SBD : 80, SBE : 90, SBAC : 90, SDB : 100, SDF : 120 | SAC | SACG : 100 ← goal on the queue |
| 7 | SBE : 90, SBAC : 90, SACG : 100, SDB : 100, SDF : 120 | SBD | SBDF : 140 |
| 8 | SBE : 90, SBAC : 90, SACG : 100, SDB : 100, SDF : 120, SBDF : 140 | SBE | SBEG : 130, SBEC : 150 |
| 9 | SBAC : 90, SACG : 100, SDB : 100, SDF : 120, SBEG : 130, SBDF : 140, SBEC : 150 | SBAC | SBACG : 120 |
| 10 | SACG : 100, everything else ≥ 100 | SACG — cheapest, done | — |
Path: S → A → C → G, cost .
Every remaining open path already costs , so none of them can ever beat SACG. That is the whole trick of Branch-and-Bound: the first goal node pulled from the queue while all alternatives are no cheaper is provably optimal.
1.4 — Which algorithm finds the shortest path? → B
Compare the three answers:
| Algorithm | Path | Cost |
|---|---|---|
| Best First | S,D,F,G | |
| A* | S,B,E,G | |
| Branch-and-Bound | S,A,C,G |
Only B (Branch-and-Bound) found the shortest path — because it optimizes on exact costs alone and never trusts the heuristic.
1.5 — Admissibility → B (not admissible)
is admissible iff it never overestimates the true remaining cost: . Compute the true cheapest cost-to-go for each node and compare:
| Node | True cost | Verdict | |
|---|---|---|---|
| C | 80 | C→G = 30 | overestimates! |
| F | 70 | F→G = 60 | overestimates |
| A | 120 | A→C→G = 50 | overestimates |
One counter-example is enough: , so the heuristic is not admissible → option B.
Tricks & Tips for This Question Family
Answers: 1.1 S,D,F,G · 1.2 S,B,E,G · 1.3 S,A,C,G · 1.4 B · 1.5 B