Q1 — Best First Search, A* and Branch-and-Bound on the Grid Map

One map, three algorithms — this time the heuristic is honest, so A* and Branch-and-Bound agree on the optimal path.

The Question

A 1×1-tile grid map. Start S, goal G. MoveGen returns neighbours alphabetically. Heuristic = Manhattan Distance. Tie-breaker: node labels.

#QuestionOfficial answer
1.1Path found by Best First SearchS,C,F,G
1.2Path found by A*S,B,A,E,G
1.3Path found by Branch-and-Bound (acyclic)S,B,A,E,G
1.4Which algorithm finds the shortest path?C — both A* and BnB
1.5Admissibility of the heuristicA — admissible

The Topic in 60 Seconds

All three keep a list of partial paths and repeatedly pick one to expand — they differ only in the sorting key:

AlgorithmPicks smallestBlind to
Best Firsth(n)h(n) (guess to goal)cost paid so far
A*f(n)=g(n)+h(n)f(n) = g(n) + h(n)nothing
Branch-and-Boundg(n)g(n) (exact cost paid)the heuristic

Deep-dive: A* Search, Best First Search, Branch and Bound.

Step 0 — Heuristic table (Manhattan distance to G, read off the grid)

Nodeh(n)h(n)Nodeh(n)h(n)
S8D6
A9E7
B8F4
C5G0

1.1 — Best First Search → S,C,F,G

StepOPEN (node : hh)PickAdd
1S : 8SB : 8, C : 5
2C : 5, B : 8CF : 4
3F : 4, B : 8FG : 0
4G : 0, B : 8G — goal!—

Path: S → C → F → G. Greedy on hh alone — cost 16+8+8=3216+8+8 = 32 (far from optimal, but that's not BFS's job).

1.2 — A* → S,B,A,E,G

StepOPEN (node : gg, hh, ff)PickUpdates
1S : 0, 8, 8SB : 4, 8, 12 · C : 16, 5, 21
2B : 12, C : 21BA : 8, 9, 17 · D : 10, 6, 16 · C via B: 16, 5, 21 (no gain)
3D : 16, A : 17, C : 21DE : 16, 7, 23 · F : 18, 4, 22 · C via D: 28 (keep 21)
4A : 17, C : 21, E : 23, F : 22AE via A: 12, 7, 19 (improves 23!)
5E : 19, C : 21, F : 22EG : 20, 0, 20
6G : 20, C : 21, F : 22G — goal!—

Path: S → B → A → E → G, cost 4+4+4+8=204+4+4+8 = 20.

1.3 — Branch-and-Bound → S,B,A,E,G

PopOPEN (path : gg) after extending
S : 0SB : 4 · SC : 16
SB : 4SBA : 4+44+4 = 8 · SBD : 4+64+6 = 10 · SBC : 4+124+12 = 16
SBA : 8SBAE : 8+48+4 = 12
SBD : 10SBDA : 10+410+4 = 14 · SBDE : 10+610+6 = 16 · SBDF : 10+810+8 = 18 · SBDC : 10+1210+12 = 22
SBAE : 12SBAED : 12+612+6 = 18 · SBAEG : 12+812+8 = 20 ← goal queued
SBDA : 14SBDAE : 14+414+4 = 18
SBC : 16 (tie with SC — labels)SBCF : 24 · SBCD : 28
SC : 16SCF : 24 · SCB : 28 · SCD : 28
SBDE : 16SBDEA : 20 · SBDEG : 24
SBAED, SBDAE, SBDF : 18SBAEDC : 30 · SBAEDF : 26 · SBDAEG : 26 · SBDFG : 26 · SBDFC : 26
SBAEG : 20 — cheapest at the 20-tie (S-A before S-B), a complete toureverything left ≥ 20 → optimal, stop

Path: S → B → A → E → G, cost 20.

Interactive A* trace — watch f=g+hf = g + h steer the search around to the cheap northern route:

1 / 7
OPEN = { S(g=0, h=8, f=8) }
expandingin OPEN (f = g+h)expandedreturned path

1.4 — Shortest path → C (both A* and BnB)

Enumerate the plausible routes: S-B-A-E-G = 20 · S-B-D-E-G = 24 · S-B-D-F-G = 26 · S-C-F-G = 32. Both A* and BnB returned 20 → option C.

1.5 — Admissibility → A (admissible)

Check h(n)≤h∗(n)h(n) \le h^*(n) everywhere:

Nodehhh∗h^* (true best to G)OK?
S820✓
B816 (B-A-E-G)✓
A912 (A-E-G)✓
D614 (D-E-G)✓
E78✓
C516 (C-F-G)✓
F48✓

No overestimate anywhere → admissible → option A. (That's exactly why A* succeeded in 1.4.)

Tricks & Tips

Answers: 1.1 S,C,F,G · 1.2 S,B,A,E,G · 1.3 S,B,A,E,G · 1.4 C · 1.5 A