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

A tie at f=20 makes A* work hard for the win — full traces for all three algorithms on an admissible map.

The Question

1×1-tile grid. Start S, goal G. MoveGen alphabetical. Heuristic = Manhattan Distance. Tie-breaker: node labels.

#QuestionOfficial answer
1.1Best First Search pathS,E,C,G
1.2A* pathS,F,B,A,G
1.3Branch-and-Bound pathS,F,B,A,G
1.4Who finds the shortest path?C — both
1.5AdmissibilityA — admissible

The Topic in 60 Seconds

AlgorithmSorts OPEN byIgnores
Best Firsth(n)h(n)g(n)g(n)
A*f(n)=g(n)+h(n)f(n) = g(n) + h(n)nothing
Branch-and-Boundg(n)g(n)h(n)h(n)

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

Step 0 — Heuristic table (Manhattan to G)

NodehhNodehh
S8B6
F9A4
D7E4
C2G0

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

StepOPEN (node : hh)PickAdd
1S : 8SD : 7, F : 9, E : 4
2E : 4, D : 7, F : 9EC : 2
3C : 2, D : 7, F : 9CG : 0
4G : 0, …G — goal!—

Path: S → E → C → G, cost 16+8+4=2816+8+4 = 28.

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

StepOPEN (node : ff)PickUpdates
1S : 0+8 = 8SF : 6+9 = 15 · D : 8+7 = 15 · E : 16+4 = 20
2F : 15, D : 15, E : 20F (tie F before D)B : 12+6 = 18 · D via F: 14+7 = 21 (keep 15)
3D : 15, B : 18, E : 20DB via D: 16+6 = 22 (keep 18) · E via D: 18+4 = 22 (keep 20)
4B : 18, E : 20BA : 16+4 = 20 · C : 20+2 = 22
5A : 20, E : 20, C : 22A (tie A before E)G : 20+0 = 20
6E : 20, G : 20, C : 22E (tie E before G)C via E: 26 (keep)
7G : 20, C : 22G — goal!—

Path: S → F → B → A → G, cost 6+6+4+4=206+6+4+4 = 20. (The step-6 tie E vs G is why this trace is worth practising — labels keep E first, but G pops next anyway.)

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

PopOPEN (path : gg) after extending
S : 0SF : 0+60+6 = 6 · SD : 0+80+8 = 8 · SE : 0+160+16 = 16
SF : 6SFB : 6+66+6 = 12 · SFD : 6+86+8 = 14
SD : 8SDF : 8+88+8 = 16 · SDB : 8+88+8 = 16 · SDE : 8+108+10 = 18
SFB : 12SFBA : 12+412+4 = 16 · SFBC : 12+812+8 = 20 · SFBD : 12+812+8 = 20
SFD : 14SFDB : 14+814+8 = 22 · SFDE : 14+1014+10 = 24
SDB : 16 (first of the 16-tie — labels)SDBA : 16+416+4 = 20 · SDBF : 16+616+6 = 22 · SDBC : 16+816+8 = 24
SDF : 16SDFB : 16+616+6 = 22
SE : 16SEC : 16+816+8 = 24 · SED : 16+1016+10 = 26
SFBA : 16SFBAG : 16+416+4 = 20 ← goal queued
SDE : 18SDEC : 18+818+8 = 28
SDBA : 20 (tie at 20: S-D before S-F)SDBAG : 20+420+4 = 24
SFBAG : 20 — next at the tie, a complete toureverything left ≥ 20 → optimal

Path: S → F → B → A → G, cost 20 ✓

1.4 — Shortest path → C (both)

Routes: S-F-B-A-G = 20 · S-D-B-A-G = 24 · S-F-D-B-A-G = 6+8+8+4+46+8+8+4+4 = 30 · S-E-C-G = 28. Both algorithms returned 20 → C.

1.5 — Admissibility → A

h(A)=4=h∗(A)h(A) = 4 = h^*(A) (exact), h(C)=2≤4h(C) = 2 \le 4, h(B)=6≤8h(B) = 6 \le 8, h(F)=9≤14h(F) = 9 \le 14, h(D)=7≤16h(D) = 7 \le 16, h(E)=4≤12h(E) = 4 \le 12, h(S)=8≤20h(S) = 8 \le 20 — no overestimate anywhere → admissible ✓ (and that's why A* hit the optimum).

Interactive A* trace

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

Tricks & Tips

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