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?
- A. O(V^2)
- B. O(E log V)
- C. O(V^3)
- 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
- Problem: By the Sprague-Grundy theorem, what is the Grundy value of a sum of independent impartial games?
- Problem: What is the minimum number of comparisons in the worst case to find both the maximum and the minimum of n = 10 distinct elements…
- Problem: What is the information-theoretic lower bound on comparisons (in the worst case) for sorting 5 distinct elements?
- Problem: Which of the following decision problems is NP-complete?
- Problem: Which statement about the subset-sum problem with target S and n items is correct in the standard sense?
- Problem: Binary lifting on a rooted tree with n nodes uses O(n log n) preprocessing. What is the time for one LCA query?