Leaving Certificate Applied Mathematics2.7 Minimum spanning trees: Prim's algorithm

All books

2.7 Minimum spanning trees: Prim's algorithm — Practise

Work independently. The questions and answers are shown together at the end.

State the starting vertex first, then at each step state the tree so far and the cheapest edge leaving it.

  1. Prim's algorithm starts from one vertex. A network has edges AB=4AB = 4, AC=2AC = 2, BC=1BC = 1, BD=5BD = 5, CD=8CD = 8, CE=10CE = 10, DE=2DE = 2, DF=6DF = 6, EF=3EF = 3. Starting from AA, which edge is chosen first, and why?
  2. Continue Prim's algorithm from AA on that network and find the total weight of the minimum spanning tree.
  3. Prim's and Kruskal's algorithms gave the same total weight. State the one thing they have in common and the one thing that differs.
  4. Prim's algorithm, part-way through, has a tree on {P,Q,R}\{P, Q, R\}. The edges leaving the tree are PS=7PS = 7, QT=7QT = 7 and RT=9RT = 9. Which edge does it take next?
  5. State the rule Prim's algorithm follows at each step, and say why the chosen edge can never close a cycle.
  6. H Starting Prim's algorithm from a different vertex gives the same total weight. Explain why this does not depend on the starting vertex.

Answers and concise solutions

1. Show the answer

1. The first edge

Answer: The edges at AA are AB=4AB = 4 and AC=2AC = 2. Prim's algorithm takes the cheapest edge leaving the chosen set, so it takes AC=2AC = 2 first. (Kruskal would also start at BC=1BC = 1, so the two algorithms begin differently — and still end the same.)

2. Show the answer

2. Total weight

Answer: From AA, take AC=2AC = 2. From {A,C}\{A, C\} the cheapest edge out is CB=1CB = 1; take it. From {A,C,B}\{A, C, B\} the cheapest is BD=5BD = 5 (AB=4AB = 4 would close the cycle A−B−C−AA-B-C-A and is not considered). From {A,C,B,D}\{A, C, B, D\} the cheapest is DE=2DE = 2. From {A,C,B,D,E}\{A, C, B, D, E\} the cheapest is EF=3EF = 3. All 6 vertices are now in the tree, with 55 edges and total weight 2+1+5+2+3=132 + 1 + 5 + 2 + 3 = 13 — the same total Kruskal found.

3. Show the answer

3. The common thing, then the difference

Answer:

Both algorithms always produce a minimum spanning tree, so on a network with distinct weights they give the same total weight, and even the same tree. They differ in how they grow it. Kruskal considers all edges in order of weight and adds the cheapest that does not close a cycle, so it can build several separate pieces before joining them. Prim starts from one vertex and always extends that single connected tree by its cheapest edge out, so the tree is connected at every step.

4. Show the answer

4. The next edge

Answer: The cheapest edge leaving the tree has weight 77, and there are two of them: PSPS and QTQT. Either may be taken. If both are taken in turn, both are added, since neither closes a cycle — they reach different new vertices. So the answer is an edge of weight 77, and the tie may be broken either way.

5. Show the answer

5. The rule, and why no cycle

Answer:

At each step Prim's algorithm takes the cheapest edge joining a vertex already in the tree to a vertex not yet in it. The chosen edge must reach a vertex outside the tree, because any edge between two vertices already in the tree would not be a candidate — it is not an edge leaving the tree. Adding an edge that brings in a new vertex cannot close a cycle, because a cycle needs every one of its vertices already in the tree. So the tree grows by one vertex and one edge each step, and stays a tree.

6. Show the answer

6. Why the start does not matter

Answer:

Prim's algorithm is proved to produce a minimum spanning tree from any starting vertex: at each step the cheapest edge leaving the tree is safe to take, so no choice can make the final total larger. The minimum total weight is a property of the network, not of the starting point, so every start reaches the same total. The tree found can differ when weights are tied, but the total cannot. Starting elsewhere is a useful check: if two starts give different totals, one of the runs has an arithmetic mistake in it.

Settings

Colour scheme

Light or dark pages. Your colour and layout stay the same.

Colour

The paper, ink and lettering. Your layout stays the same.

Quiet colours
Bold colours
Layout

How pages are arranged. Your colours stay the same.

Reading offline

Keep this book on this device and read it offline.