Passer au contenu

Labs · AI search · BFS, DFS, A*

Search the Maze: BFS, DFS and A*

Build walls, then race four searches from S to E. Watch breadth-first spread like a wave, depth-first dive deep, and A* head straight for the end.

4 levelsFree bench

In the exam

Exam questions on what this lab teaches, with the points that gain marks.

9618/31 May/June 2023 · Question 2(b)2 marks

Describe the purpose of both the A* algorithm and Dijkstra's algorithm.

Points that gain marks

  1. Both find the best (shortest or cheapest) route between two nodes in a graph.
  2. The best route is measured by distance, cost or time on the edges.

In this lab: On the grid every step costs 1, so BFS works like Dijkstra here: it finds a shortest route. A* finds a route just as short but visits fewer squares, because h points it at the end.

9618/32 May/June 2026 · Question 9(b)(i)3 marks

The A* and Dijkstra's algorithms are used to perform searches on a graph. Outline how the A* algorithm is different from Dijkstra's algorithm.

Points that gain marks

  1. A* tries to find the shortest path using heuristics (intelligent guesses).
  2. A* does not necessarily pass through all the nodes or paths.
  3. Dijkstra's algorithm finds the shortest path to all the nodes, checking each vertex.
  4. Dijkstra's algorithm always finds the shortest path.

In this lab: Level 2 shows both: A* heads for E and visits far fewer squares, while BFS (Dijkstra on a grid, where every step costs 1) spreads out in every direction. Level 4 shows the catch: with a guess that is too big, A* is no longer sure to find the shortest path.

The question as printed in the exam paper

More real experiments

All labs →

Se connecter ou créer un compte

IGCSE, A-Level & AP