2 2 votes Suppose prim’s algorithm is implemented using array as queue for a graph $G(V,E)$. Then what is the time complexity of Prim’s algorithm? $O (E \hspace{0.1cm}log\hspace{0.1cm} V)$ $O (V^2 \hspace{0.1cm}log\hspace{0.1cm} V)$ $O(V^2)$ $O(VE)$ Algorithms test-series prims-algorithm time-complexity + – Aishwarya Gujrathi 2.7k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 2 2 votes If we use min heap to implement prims algorithm time complexity is: O(E log V) without using min heap time complexity is: O$\left ( V^{2} \right )$ so answer would be option C.O$\left ( V^{2} \right )$ G Shaheena answered Mar 27, 2018 • selected Mar 29, 2018 by Aishwarya Gujrathi G Shaheena comment Share Follow See all 4 Comments 4 4 Comments reply abhishekmehta4u commented Mar 27, 2018 reply Follow flag what do mean it is implemented without binary heap take o(v^2).????/ 0 0 replyShare G Shaheena commented Mar 27, 2018 reply Follow flag without binary heap means we can implement prim's algorithm with arrays. where as using min heap(i.e, using extract-min,decrease-key,build-heap) we can implement it in with O(E log V) time. 0 0 replyShare Aishwarya Gujrathi commented Mar 29, 2018 reply Follow flag @Shaheena can you explain the significance of using array as a queue here? I do not understand what for a queue is being used. Is it related to DFS? Thanks in advance. 0 0 replyShare srestha commented Mar 29, 2018 reply Follow flag prims algorithm basically implemented using queue . but what is need of using array as queue? 0 0 replyShare Please log in or register to add a comment.
0 0 votes if we are implement prims using array then We use a boolean array to represent the set of vertices included in MST. so this implementation is done by adjacency matrix and time complexity become o(v^2). abhishekmehta4u answered Mar 27, 2018 abhishekmehta4u comment Share Follow See all 10 Comments 10 10 Comments reply Show 7 previous comments Mamta Satywali commented Mar 29, 2018 reply Follow flag I think the question is talking about the array implementation of queue, as follows- struct queue{ int *rear; int *front; int arr[]; } What do u say? 0 0 replyShare srestha commented Mar 29, 2018 reply Follow flag ok but if it be done with adjacency matrix then there should be multidiamentional array 0 0 replyShare Mamta Satywali commented Mar 29, 2018 reply Follow flag Exactly that was my point. We don't have matrix here(so we can't easily say its O(V2)).We have been provided with the queue as a data structure so we'll use it to implement prims. 0 0 replyShare Please log in or register to add a comment.