All mock tests are FREE till 31 December — register to save your progress
Unit 7 · Data Structures and Algorithms Paper 2 CS · November 2020

Consider the undirected graph below:

Figure

Using Prim's algorithm to construct a minimum spanning tree starting with node a, which one of the following sequences of edges represents a possible order in which the edges would be added to construct the minimum spanning tree?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: C. (a,b), (b,c), (c,i), (c,f), (f,g), (g,h), (c,d), (d,e)

Explanation

From a: (a,b) 4; then (b,c) 8 (tie with (a,h) 8); (c,i) 2; (c,f) 4; (f,g) 2; (g,h) 1; (c,d) 7; (d,e) 9. Each step adds the cheapest edge leaving the tree, matching option C.

More Data Structures and Algorithms questions