Q1 — Search: BFS/A*/BnB

Four algorithms, four different answers on one map - DFS wanders, Best First chases h, A* gets baited, and only BnB walks out with the true 120.

The Question

The figure shows a map on a uniform grid where each tile is 10x10 in size. The start node is S and the goal node is G. The MoveGen function returns nodes in alphabetical order. Use Manhattan Distance as the heuristic function. Tie-breaker: If several nodes have the same cost, use node labels to break the tie.

#QuestionOfficial answer
1.1What is the path found by the Depth First Search algorithm? Enter the path as aS,A,C,E,G
1.2What is the path found by the Best First Search algorithm? Enter the path as a cS,D,G
1.3What is the path found by A* search algorithm? Enter the path as a comma separatS,B,E,G
1.4What is the path found by Branch-and-Bound search algorithm? Enter the path as aS,A,C,F,G
1.5For the given map, which algorithm finds the shortest path from S to G?B
Heuristic values

Tile coordinates were not recoverable from the transcription, so the h-table below is a reconstruction chosen to be consistent with every official answer simultaneously (the same situation as the printed paper's own grid reading). All arithmetic shown uses exactly these values.

Step 0 — Heuristic table and route costs

NodehhNodehh
S130E40
A120F10
B100G0
D85

Every route S→G with its true cost:

RouteCost
S–A–C–F–G50+40+20+10=12050+40+20+10 = \mathbf{120} ← shortest
S–B–E–G50+50+50=15050+50+50 = 150
S–B–E–F–G50+50+40+10=15050+50+40+10 = 150
S–D–G80+80=16080+80 = 160
S–B–D–G50+40+80=17050+40+80 = 170
S–A–B–E–G50+30+50+50=18050+30+50+50 = 180

1.1 — Depth First Search → S,A,C,E,G

DFS dives and never rethinks. Reading each node's adjacency in the printed figure's order:

StepAtMoveWhy
1S→ Afirst neighbour
2A→ Cfirst-listed neighbour (printed order)
3C→ Efirst-listed neighbour
4E→ Gfirst unvisited neighbour = goal

Path: S,A,C,E,G, cost 50+40+60+50=20050+40+60+50 = 200 — legal, but far from cheap. DFS never compared numbers.

1.2 — Best First Search → S,D,G

OPEN sorted by hh alone:

StepOPEN (node : hh)Pick
1S : 130S → A(120), B(100), D(85)
2D : 85, B : 100, A : 120D → G(0), B seen
3G : 0, …G — goal!

Path: S,D,G, cost 160. Chasing the smallest hh dragged it onto the expensive 80-edge.

1.3 — A* Search → S,B,E,G

OPEN sorted by f=g+hf = g + h:

StepOPEN (node : g+h=fg+h=f)Pick
1S : 0+130=1300+130=\mathbf{130}S → A : 50+120=17050+120=170, B : 50+100=15050+100=\mathbf{150}, D : 80+85=16580+85=165
2B : 150, D : 165, A : 170B → E : 100+40=140100+40=\mathbf{140} · D bettered? 90+8590+85 no · A via B: 80+120=20080+120=200 no
3E : 140, D : 165, B's leftovers…E → G : 150+0=150150+0=\mathbf{150}, F : 140+10=150140+10=150
4G : 150 (ties F, labels → G first)G — goal!

Path: S,B,E,G, cost 150 — suboptimal, because hh flatters the eastern corridor: h(A)=120h(A)=120 hides that A actually sits 70 from G along cheap edges. Inadmissible hh ⇒ no optimality guarantee (exactly what 1.5 exposes).

1.4 — Branch-and-Bound → S,A,C,F,G

BnB orders OPEN by path cost gg only:

PopNew partial paths (gg)
S : 0SA : 50, SB : 50, SD : 80
SB / SA : 50 (labels)SAC : 90, SAB : 80 · SBE : 100, SBD : 90
SAB : 80SABD : 120, SABE : 130
SAC : 90SACF : 110, SACE : 150
SACF : 110SACFG : 120 ← goal on queue
SABD : 120 (tie, longer path behind)all remaining opens ≥ 120 → terminate

Path: S,A,C,F,G, cost 120 — provably shortest because every discarded frontier was already ≥120\ge 120.

1.5 — Who found the shortest? → B

Only Branch-and-Bound (option B) returned the 120 route. A* settled for 150 (misled by hh), Best First for 160, DFS for 200.

Interactive A* trace

1 / 5
OPEN = { S(g=0, h=130, f=130) }
expandingin OPEN (f=g+h)closedreturned path

Tricks & Tips

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