Question bank › A-level Computer Science › Fundamentals of algorithms

Graph traversal and Dijkstra's shortest path

Answer on paper first, then reveal the mark scheme one mark at a time.

1Hard6 marks

The weighted graph below shows the distances, in km, between six locations.

Dijkstra's algorithm is used to find the shortest route from A to every other node. At each step, the unfinalised node with the smallest working distance is permanently labelled (finalised), and the working distance of each of its unfinalised neighbours is updated if the route through the finalised node is shorter.

(a) State the order in which the nodes are permanently labelled (finalised). [2]

(b) State the length of the shortest path from A to F. [1]

(c) State the shortest path from A to F. [1]

(d) Explain why the working value for B changes from 4 to 3 during the algorithm. [1]

(e) State one real-world application of Dijkstra's shortest path algorithm. [1]

4215810263ABCDEF
2Hard6 marks

The undirected graph below is stored as an adjacency list. When choosing which neighbour to visit next, always choose the neighbour that is earliest alphabetically.

(a) Write the order in which nodes are visited in a breadth-first traversal starting at A. [2]

(b) Write the order in which nodes are visited in a depth-first traversal starting at A. [2]

(c) State the data structure used to hold nodes waiting to be visited in a breadth-first traversal. [1]

(d) State the data structure that a depth-first traversal uses, either explicitly or through recursion. [1]

ABCDEFG

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session