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

#QuestionOfficial answer
1.1Path found by Best First SearchS,D,F,G
1.2Path found by A*S,B,E,G
1.3Path found by Branch-and-Bound (acyclic)S,A,C,G
1.4Which algorithm finds the shortest path?B — Branch-and-Bound
1.5Is 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:

AlgorithmPicks the node with smallestIgnores
Best First Search (greedy)h(n)h(n) — estimated distance to goalcost already paid
A*f(n)=g(n)+h(n)f(n) = g(n) + h(n)nothing — balances both
Branch-and-Boundg(n)g(n) — exact cost so farthe heuristic entirely
  • g(n)g(n) = exact cost of the path from S to nn
  • h(n)h(n) = heuristic estimate from nn to G

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

Step 0 — Precompute the heuristic table

Manhattan distance on the grid: h(n)=10×(∣xn−xG∣+∣yn−yG∣)h(n) = 10 \times (|x_n - x_G| + |y_n - y_G|) with G at (90, 60).

NodeCoordinatesh(n)h(n)
S(0, 30)90+30=12090 + 30 = 120
A(30, 0)60+60=12060 + 60 = 120
B(30, 30)60+30=9060 + 30 = 90
D(20, 50)70+10=8070 + 10 = 80
E(50, 60)40+0=4040 + 0 = 40
F(50, 90)40+30=7040 + 30 = 70
C(70, 0)20+60=8020 + 60 = 80
G(90, 60)00

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 hh only.

StepOpen list (node : hh)PickExpand → add
1S : 120SD : 80, B : 90, A : 120
2D : 80, B : 90, A : 120DF : 70 (B, S already seen)
3F : 70, B : 90, A : 120FE : 40, G : 0
4G : 0, E : 40, B : 90, A : 120G — goal!—

Path: S → D → F → G. Notice BFS never looked at edge costs — it just slid downhill on hh. Step through the trace exactly as you would write it in the exam:

1 / 5
OPEN = { S(h=120) }
picking nowin OPENexpandedfinal path

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

A* picks the open node with the smallest f(n)=g(n)+h(n)f(n) = g(n) + h(n).

StepOpen list (node : gg, hh, ff)PickUpdates
1S : 0, 120, 120SB : 40, 90, 130 · A : 50, 120, 170 · D : 60, 80, 140
2B : 130, D : 140, A : 170BA via B: g=70g=70 → 190 (worse than 170, keep 50/170) · E : 90, 40, 130 · D via B: g=80g=80 → 160 (worse than 140, keep)
3E : 130, D : 140, A : 170EG : 130, 0, 130 · C : 150, 80, 230
4G : 130, D : 140, A : 170, C : 230G — goal!—

Path: S → B → E → G, cost 40+50+40=13040 + 50 + 40 = 130.

1 / 5
OPEN = { S(g=0, h=120, f=120) }
expandingin OPEN (f = g+h)expanded / rejectedreturned path
Wait — is that really optimal?

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 hh is admissible — and 1.5 shows it is not. A single inadmissible node poisoned the search: the inflated h(C)=80h(C) = 80 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 gg and never extends a path that revisits a node (the "avoids cyclic expansions" note).

StepOpen paths (path : gg)PickExtend with
1S : 0SSB : 40, SA : 50, SD : 60
2SB : 40, SA : 50, SD : 60SBSBA : 70, SBE : 90, SBD : 80
3SA : 50, SD : 60, SBA : 70, SBD : 80, SBE : 90SASAC : 70
4SD : 60, SBA : 70, SAC : 70, SBD : 80, SBE : 90SDSDF : 120, SDB : 100
5SBA : 70, SAC : 70, SBD : 80, SBE : 90, SDB : 100, SDF : 120SBASBAC : 90
6SAC : 70, SBD : 80, SBE : 90, SBAC : 90, SDB : 100, SDF : 120SACSACG : 100 ← goal on the queue
7SBE : 90, SBAC : 90, SACG : 100, SDB : 100, SDF : 120SBDSBDF : 140
8SBE : 90, SBAC : 90, SACG : 100, SDB : 100, SDF : 120, SBDF : 140SBESBEG : 130, SBEC : 150
9SBAC : 90, SACG : 100, SDB : 100, SDF : 120, SBEG : 130, SBDF : 140, SBEC : 150SBACSBACG : 120
10SACG : 100, everything else ≥ 100SACG — cheapest, done—

Path: S → A → C → G, cost 50+20+30=10050 + 20 + 30 = 100.

Why BnB can stop

Every remaining open path already costs ≥100\geq 100, 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 / 9
OPEN = [ S:0 ]
path being extendedin OPEN (sorted by g)not reachable nowoptimal path (cost 100)

1.4 — Which algorithm finds the shortest path? → B

Compare the three answers:

AlgorithmPathCost
Best FirstS,D,F,G60+60+60=18060+60+60 = 180
A*S,B,E,G40+50+40=13040+50+40 = 130
Branch-and-BoundS,A,C,G50+20+30=10050+20+30 = \mathbf{100}

Only B (Branch-and-Bound) found the shortest path — because it optimizes on exact costs gg alone and never trusts the heuristic.

1.5 — Admissibility → B (not admissible)

hh is admissible iff it never overestimates the true remaining cost: 0≤h(n)≤h∗(n)0 \le h(n) \le h^*(n). Compute the true cheapest cost-to-go for each node and compare:

Nodeh(n)h(n)True cost h∗(n)h^*(n)Verdict
C80C→G = 30overestimates!
F70F→G = 60overestimates
A120A→C→G = 50overestimates

One counter-example is enough: h(C)=80>h∗(C)=30h(C) = 80 > h^*(C) = 30, so the heuristic is not admissible → option B.

Tricks & Tips for This Question Family

QuizIn this map, why did A* miss the shortest path S,A,C,G?

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