Mathster Maths topics Free worksheets Coverage Mathster for schools

Maths topics › A level Further Maths › D1, algorithms and graphs

Find the shortest distances and routes between all pairs of vertices using Floyd's algorithm

A level Further Maths · D1, algorithms and graphs

A question

The table shows the direct distances between five places; \(\infty\) means there is no direct link. The route table starts with every entry in column \(j\) equal to \(j\).
Apply Floyd’s algorithm, one iteration for each place: complete the distance table and the route table after each iteration (type inf for \(\infty\)). Then use your final tables to find the shortest route from B to C and its length.

Free worksheet

10 questions on this objective, ready to print.

Download the worksheet (PDF)

We use this address to send you the answers, and for news only if you tick the box.

Worked solution

The working

  1. (a) In iteration 1, each entry is compared with (row entry in column \(A\)) + (column entry in row \(A\)). For row B, column E this gives \(25\), which is less than a dash, so it is replaced. After the first iteration:
  2. ABCDE
    A–1342012
    B13–17525
    C417–159
    D20515–4
    E122594–
  3. (b) The route table entry becomes the entry in column \(A\) of row B, which is \(A\): go to \(A\) first.
  4. (c) One iteration for each place: \(5\).
  5. (d) The final distance table is
  6. ABCDE
    A–1341612
    B13–1759
    C417–139
    D16513–4
    E12994–
  7. so the shortest distance from B to C is \(17\).
  8. (e) The shortest route is BAC, so the first place to go to from B is A.

Mathster is maths homework, practice and assessment for schools, with animated worked solutions. Try Mathster free for 60 days →

Objectives from the AS and A level subject content for further mathematics (Department for Education). Contains public sector information licensed under the Open Government Licence v3.0.