Skip to content

Dijkstra's shortest paths

networks

Level 2 of 3

Also called Dijkstra's algorithm and Single-source shortest paths.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from dijkstra's shortest paths's own run on the numbers shown.

choose one

question 1

The search runs from A to G on this map. What distance does it settle G at?

5222451A0BCEFG
the answer, and why

the answer is D

The shortest way is A, E, F, G, which is 2 + 2 + 5, so 9.

if you chose another

  • That is A, B, C, G, 5 + 4 + 1, longer than 9.
  • That adds only A-E and F-G, leaving out E-F.
  • That is A, E, F, B, C, G, a longer way round.

new numbers

question 2

On this map, from A to H, which place is settled fourth?

61113162A0BCEFGH
the answer, and why

the answer is B

A at 0, E at 1 and F at 2 come first. Through F, place B is 3, beating its 6.

if you chose another

  • Place C is 6 away, after place B.
  • Place F, at 2, is settled third.
  • Place G is 7 away, after place C.

new numbers

question 3

The search runs from the first place after the semicolon to the second. On which map does it weigh up the most places?

the answer, and why

the answer is C

Settling A writes a distance at all 3 others, so 1, then 3, 2 and 1, which is 7.

if you chose another

  • A line of 4 weighs up one place each round, 4.
  • H is on another part of the map, so the run ends after A and B, 2.
  • B is nearest and is the place to reach, so the run stops after A, then B and E, 3.

new numbers