1.

Worst case is the worst case time complexity of Prim’s algorithm if adjacency matrix is used?(a) O(log V)(b) O(V^2)(c) O(E^2)(d) O(V log E)I had been asked this question during an interview.Query is from Minimum Spanning Tree topic in portion Minimum Spanning Tree of Data Structures & Algorithms II

Answer»

Right answer is (b) O(V^2)

The explanation is: Use of adjacency matrix provides the SIMPLE IMPLEMENTATION of the Prim’s algorithm. In Prim’s algorithm, we need to SEARCH for the EDGE with a minimum for that VERTEX. So, worst case time complexity will be O(V^2), where V is the number of vertices.



Discussion

No Comment Found

Related InterviewSolutions