Data Structures & AlgorithmsHardProduct-company placement

Prim's algorithm starts at E on the weighted undirected graph A–C (13), A–D (1), A–G (11), B–D (16), B–G (6), C–D (14), C–E (18), C–F (28), C–G (9), D–F (19), F–G (4). In what order are the vertices added to the tree?

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

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

Prim always adds the cheapest edge leaving the current tree (not the vertex closest to E, which is Dijkstra's rule): edges E–C (18), C–G (9), G–F (4), G–B (6), G–A (11), A–D (1), total 49.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic