Data Structures & AlgorithmsHardICPC regional · MST

Problem: What is the time complexity of finding a minimum spanning tree in a complete graph with V vertices using Prim's algorithm and an adjacency matrix?

  1. A. O(V^2)
  2. B. O(V log V)
  3. C. O(V^3)
  4. D. O(V)

Correct answer: A. O(V^2)

The matrix version scans all V candidate edges per added vertex, giving O(V^2) overall.

More Coding Interview Problems questions

Exams that ask this topic