Data Structures & AlgorithmsHardGATE CS · Product-company placement

Prim's algorithm starts at D on the weighted undirected graph A–D (23), A–F (5), A–G (28), B–C (17), B–E (15), B–G (2), C–E (21), C–G (18), D–E (1), D–G (3), F–G (22). In what order are the vertices added to the tree?

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

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

Prim always adds the cheapest edge leaving the current tree (not the vertex closest to D, which is Dijkstra's rule): edges D–E (1), D–G (3), G–B (2), B–C (17), G–F (22), F–A (5), total 50.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic