GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Prim's algorithm starts at A on a graph with edges AB 6, AC 1, AD 5, BC 5, BE 3, CD 7, CE 8, CF 4, DF 2, EF 9, FG 10, EG 11, DG 12, AG 13. In what order are vertices added to the tree?

  1. A. A, C, F, D, B, E, G
  2. B. A, C, F, D, E, B, G
  3. C. A, C, D, F, B, E, G
  4. D. A, C, F, B, D, E, G

Correct answer: A. A, C, F, D, B, E, G

From A the cheapest edge is AC 1; then CF 4 (cheaper than AD 5 or BC 5), then FD 2, then BC 5 beats AB 6 so B joins, then BE 3 adds E and finally FG 10 adds G. The MST weight is 1 + 4 + 2 + 5 + 3 + 10 = 25.

More Algorithms questions

Exams that ask this topic