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.8k 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 Mamta Satywali commented Mar 27, 2018 reply Follow flag The question stated that we are using the array as a queue, we cant modify it to be used as an array. However, yes we can use this "queue" data structure to keep set of all visited vertices while all vertices are not visited.That saves us O(n) space. But still, we need to use either Adjacency Matrix or Min-heap to find the min edge from all visited vertices. Could you pls explain why have you chosen Adjacency matrix over min-Heap? 0 0 replyShare abhishekmehta4u commented Mar 27, 2018 reply Follow flag bcz we are using array as queue. 0 0 replyShare Mamta Satywali commented Mar 27, 2018 reply Follow flag That's my point. That array has been used to implement a queue, Its Queue, which is available to us, how can we modify it? 0 0 replyShare Sukannya commented Mar 27, 2018 reply Follow flag @abhishek, why adjacency matrix? I mean the representation of graph is not mentioned in the question, they have mentioned the queue datastructure to implement Prims algo, so are you modifying the queue to adjacency matrix? 0 0 replyShare abhishekmehta4u commented Mar 27, 2018 reply Follow flag I think implementation of array using queue we need to adjency matrix. 0 0 replyShare srestha commented Mar 29, 2018 reply Follow flag what is meaning of array using queue? is it like each array forming a column of matrix and multiple columns are formed by multiple arrays? why is it require, can u explain in detail? 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 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.