Menu
Sign up Sign in

AI HL · AHL 1

Graph Theory

AHL 1.8

Minimum spanning trees: Kruskal's algorithm

AHL 1.8

Minimum spanning trees: Kruskal's algorithm

Target: I can explain what a minimum spanning tree is. (+4 more)

By the end of this section

Key points

Minimum spanning trees

  • A spanning tree joins every vertex of a connected graph using edges that make no cycle.
  • A tree on n vertices has exactly n − 1 edges.
  • A minimum spanning tree is a spanning tree with the least possible total weight. Use it to join places with the least cable, pipe or road.

Kruskal's algorithm

  • List the edges in order of weight, smallest first.
  • Take each edge in turn. Add it unless it makes a cycle with the edges already chosen. If it does, reject it.
  • Stop when you have n − 1 edges. The edges left over are not needed.
  • Give the edges in the order they are added, then the total weight.

Working from a table

  • In a weighted adjacency table each edge appears twice. Read it once, from above the diagonal, and list the edges in order of weight.
  • A dash means there is no edge: leave it out of the list.
  • In a complete table every pair of vertices has an edge. Many edges will be rejected, so write a short reason: the cycle they would make.

Explore: minimum spanning trees

Choose Kruskal or Prim, then press Next to watch the tree grow, or switch to "Try it yourself" and press the edge you would add. Another graph gives a new example.

The edges in order of weight ()

    Vertices, n
    Edges in a spanning tree, n − 1
    Edges chosen so far

    1. Before you press Next, say whether Kruskal will take the next edge or reject it. How can you tell?
    2. Run Kruskal, then Prim on the same graph. Are the edges the same? Is the total the same? Is the order the same?
    3. With Prim, change the start vertex. What changes, and what stays the same?
    4. On Graph 4, two edges have the same weight. Does it matter which one you take first?

    Worked examples

    Problems like the ones in class. Pick one, try it, then open the working.
    Kruskal on a drawn graph

    The graph shows the cost, in £ thousand, of laying a cable between six offices. Use Kruskal's algorithm to find a minimum spanning tree. List the edges in the order they are added and find the total weight.

    20177132114183028ABCDEF
    Working
    1. Edges in order of weight

      DE 7, BE 13, AE 14, AB 17, EF 18, AD 20, CE 21, CF 28, BC 30

      List every edge from the smallest weight to the largest. All the weights are different, so the order is clear.

    2. Add or reject

      DE 7: add; BE 13: add; AE 14: add; AB 17: reject, cycle A–E–B; EF 18: add; AD 20: reject, cycle A–E–D; CE 21: add

      Take the edges in order. Add an edge unless it makes a cycle with the edges already chosen. Check by looking for a path between its two ends.

    3. Stop

      5 edges chosen: DE, BE, AE, EF, CE

      A spanning tree on 6 vertices has 5 edges. Stop when you reach that number: the later edges are not needed.

    4. 20177132114183028ABCDEF
      Total weight

      7 + 13 + 14 + 18 + 21 = 73

      Add the weights of the edges in the tree.

    Video walkthrough coming
    Kruskal from a table

    The table shows the distances, in km, between six villages. Roads are to be built so that every village can be reached from every other village, using the least total length. Use Kruskal's algorithm to find which roads to build, in the order they are added, and the total length.

    ABCDEFA–325987233B32–61683449C5961–767563D86876–6523E72347565–64F3349632364–
    Working
    1. Edges in order of weight

      AD 8, DF 23, AB 32, AF 33, BE 34, BF 49, AC 59, BC 61, CF 63, EF 64, DE 65, BD 68, AE 72, CE 75, CD 76

      List every edge from the smallest weight to the largest. All the weights are different, so the order is clear.

    2. Add or reject

      AD 8: add; DF 23: add; AB 32: add; AF 33: reject, cycle A–D–F; BE 34: add; BF 49: reject, cycle B–A–D–F; AC 59: add

      Take the edges in order. Add an edge unless it makes a cycle with the edges already chosen. Check by looking for a path between its two ends.

    3. Stop

      5 edges chosen: AD, DF, AB, BE, AC

      A spanning tree on 6 vertices has 5 edges. Stop when you reach that number: the later edges are not needed.

    4. Total weight

      8 + 23 + 32 + 34 + 59 = 156

      Add the weights of the edges in the tree.

    Video walkthrough coming
    A table with missing roads

    The table shows the cost, in €1000, of laying a cable directly between six schools. A dash means a cable cannot be laid between those two schools. Use Kruskal's algorithm to find a minimum spanning tree: give the edges in the order they are added and the total cost.

    ABCDEFA–744210–17B74––75–57C42––51–37D107551–61–E–––61–30F175737–30–
    Working
    1. Edges in order of weight

      AD 10, AF 17, EF 30, CF 37, AC 42, CD 51, BF 57, DE 61, AB 74, BD 75

      List every edge from the smallest weight to the largest. All the weights are different, so the order is clear.

    2. Add or reject

      AD 10: add; AF 17: add; EF 30: add; CF 37: add; AC 42: reject, cycle A–F–C; CD 51: reject, cycle C–F–A–D; BF 57: add

      Take the edges in order. Add an edge unless it makes a cycle with the edges already chosen. Check by looking for a path between its two ends.

    3. Stop

      5 edges chosen: AD, AF, EF, CF, BF

      A spanning tree on 6 vertices has 5 edges. Stop when you reach that number: the later edges are not needed.

    4. Total weight

      10 + 17 + 30 + 37 + 57 = 151

      Add the weights of the edges in the tree.

    Video walkthrough coming
    Kruskal on a larger graph

    The graph shows the lengths, in metres, of possible paths between eight sheds on an allotment. Use Kruskal's algorithm to find a minimum spanning tree. List the edges in order and give the total length.

    1718132321412285320ABCDEFGH
    Working
    1. Edges in order of weight

      EH 2, DE 3, EF 4, FH 5, AC 8, AB 12, DF 13, BC 17, GH 18, FG 20, DG 21, BD 23

      List every edge from the smallest weight to the largest. All the weights are different, so the order is clear.

    2. Add or reject

      EH 2: add; DE 3: add; EF 4: add; FH 5: reject, cycle F–E–H; AC 8: add; AB 12: add; DF 13: reject, cycle D–E–F; BC 17: reject, cycle B–A–C; GH 18: add; FG 20: reject, cycle F–E–H–G; DG 21: reject, cycle D–E–H–G; BD 23: add

      Take the edges in order. Add an edge unless it makes a cycle with the edges already chosen. Check by looking for a path between its two ends.

    3. Stop

      7 edges chosen: EH, DE, EF, AC, AB, GH, BD

      A spanning tree on 8 vertices has 7 edges. Stop when you reach that number: the later edges are not needed.

    4. 1718132321412285320ABCDEFGH
      Total weight

      2 + 3 + 4 + 8 + 12 + 18 + 23 = 70

      Add the weights of the edges in the tree.

    Video walkthrough coming