Data Structures & AlgorithmsHardICPC regional · algorithm theory

Problem: What is the time complexity of Prim's algorithm on a graph stored as an adjacency matrix with V vertices?

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

Correct answer: A. O(V^2)

The simple Prim loop scans the matrix row of each newly added vertex, giving O(V^2) overall.

More Coding Interview Problems questions

Exams that ask this topic