Data Structures & AlgorithmsModerateProduct-company MCQ pattern

Prim's algorithm starts at A on the undirected graph with edges A–B (3), A–C (1), B–C (7), B–D (5), C–D (2), C–E (7), D–E (3), D–F (8), E–F (4), B–F (6). If ties are broken in favour of the alphabetically smaller edge, which edge is added THIRD, and what is the MST weight?

  1. A. A–B (3); total 13
  2. B. B–D (5); total 15
  3. C. A–B (3); total 12
  4. D. D–E (3); total 13

Correct answer: A. A–B (3); total 13

Prim adds A–C (1), then C–D (2); now the cheapest edges leaving {A, C, D} are A–B (3) and D–E (3), and the tie goes to A–B (it is also found first by listing order). Then D–E (3) and E–F (4): 1 + 2 + 3 + 3 + 4 = 13. D–E would be third only with a different tie-break.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic