GATE Overflow - Recent questions tagged prims-algorithm
https://gateoverflow.in/tag/prims-algorithm
Powered by Question2AnswerCormen 23.2-3
https://gateoverflow.in/236791/cormen-23-2-3
For a sparse graph $G=(V,E)$ where $|E|=\Theta (V)$ is the implementation of Prim’s algorithm with a Fibonacci heap asymptotically faster than the binary-heap implementation? What about for a dense graph, where $|E|=\Theta (V)^{2}$? How must the sizes $|E|$ and $|V|$ be related for the Fibonacci-heap implementation to be asymptotically faster than the binary-heap implementation?<br />
<br />
__________________________________________________________________________<br />
<br />
Plz tell me difference between Sparse and Dense graph here? How Dense graph implemented and how it make difference for this questionAlgorithmshttps://gateoverflow.in/236791/cormen-23-2-3Fri, 24 Aug 2018 11:37:09 +0000CLRS INTRODUCTION TO ALGORITHMS 3rd Edition, CHAPTER 23 QUESTION 23.2.7
https://gateoverflow.in/234860/clrs-introduction-algorithms-3rd-edition-chapter-question
<blockquote>
<p>suppose that a graph G has MST already computed. How quickly can we update the MST if we add a new vertex and incident edges to it.</p>
</blockquote>
<p>I know for the best case scenario when a single edge is incident from the newly added vertex. but for the worst case, when the newly added vertex has an edge incident to the every other vertex in the MST, then i'm getting confused as how should we proceed?</p>
<p>there are two solutions i've got online, which i'm attaching here for reference.</p>
<blockquote>
<p>solution 1:</p>
<p>If there is only one edge, just add this edge.</p>
<p>If there are k(k > 1) edges, then we need to remmove k-1 edges. We can find cycles by Union-Find and remove the weightest edge in an union. This algorithm need (k-1) passes.</p>
</blockquote>
<blockquote>
<p>solution 2:</p>
<p>We first add all the edges to the new vertex. Then, we preform a DFS rooted at that vertex. As we go down, we keep track of the largest weight edge seen so far since each vertex above us in the DFS. We know from exercise 23.3-6 that in a directed graph, we don’t need to consider cross or forward edges. Every cycle that we detect will then be formed by a back edge. So, we just remove the edge of greatest weight seen since we were at the vertex that the back edge is going to. Then, we’ll keep going until we’ve removed one less than the degree of the vertex we added many edges. This will end up being linear time since we can reuse part of the DFS that we had already computed before detecting each cycle.</p>
</blockquote>
<p> </p>Algorithmshttps://gateoverflow.in/234860/clrs-introduction-algorithms-3rd-edition-chapter-questionSun, 19 Aug 2018 07:58:53 +0000cormen 2nd edition excercise 23-2-5
https://gateoverflow.in/227441/cormen-2nd-edition-excercise-23-2-5
Suppose that all edge weights in a graph are integers in the range from 1 to |V|. How fast can you make Prim's algorithm run? What if the edge weights are integers in the range from 1 to W for some constant W?<br />
<br />
Answer given :-<br />
<br />
The running time of Prims algorithm is composed of :<br />
<br />
• O(V) initialization.<br />
<br />
• O(V · time for EXTRACT-MIN).<br />
<br />
• O(E · time for DECREASE-KEY).<br />
<br />
If the edges are in the range 1, . . . , |V| the Van Emde Boas priority queue can speed up EXTRACT- MIN and DECREASE-KEY to O(lg lg V) thus yielding a total running time of O(V lg lg V +E lg lg V) = O(E lg lg V ). If the edges are in the range from 1 to W we can implement the queue as an array [1...W+1] where the ith slot holds a doubly linked list of the edges with weight i. The (W+1)st slot contains ∞. EXTRACT-MIN now runs in O(W) = O(1) time since we can simply scan for the first nonempty slot and return the first element of that list. DECREASE-KEY runs in O(1) time as well since it can be implemented by moving an element from one slot to another.<br />
<br />
Doubt 1 : Incase of range 1, . . . , |V| , how EXTRACT- MIN and DECREASE-KEY speed up to O(lg lg V).<br />
<br />
Doubt 2 : why doubly linked list is used for range 1.... |W| ??Algorithmshttps://gateoverflow.in/227441/cormen-2nd-edition-excercise-23-2-5Sat, 21 Jul 2018 02:00:15 +0000TEST SERIES
https://gateoverflow.in/191525/test-series
<p>Consider the following graph and Assume node ‘P’ as the starting vertex for Prim’s algorithm. Which of the following can be the correct order of edges to which they are added to construct Minimum Spanning Tree (MST)?
<br>
<img alt="image:n104.PNG" height="192" src="http://gatexcel.co.in/cache/n104.PNG" width="459"></p>
<ol>
<li> P-Q, Q-R, R-W, R-S, V-X, V-U, W-V, S-T</li>
<li> P-Q, Q-R, R-W, W-V, V-X, V-U, R-S, S-T</li>
<li> P-Q, P-X, X-V, V-U, U-R, R-S, R-W, S-T</li>
<li> P-Q, P-X, X-V, V-U, U-R, R-W, R-S, S-T</li>
</ol>
<p>PLEASE EXPLAIN.</p>Algorithmshttps://gateoverflow.in/191525/test-seriesMon, 08 Jan 2018 08:14:23 +0000How many MST is possible?
https://gateoverflow.in/188665/how-many-mst-is-possible
<p>Given graph using Prim’s or Kruskal’s algorithm, find out that how many distinct minimum cost spanning trees are possible___?</p>
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=13571922630184828519"></p>
<p>My answer was 1 and given is 2 ,what I am missing ?</p>
<p> <img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=9904486936216050373"> </p>
<p>Edit:I had confirmed with it and answer is only one tree possible.</p>Algorithmshttps://gateoverflow.in/188665/how-many-mst-is-possibleTue, 02 Jan 2018 02:26:39 +0000Regarding prims algo
https://gateoverflow.in/173559/regarding-prims-algo
Hello,<br />
<br />
I have doubt regarding prims algorithm<br />
<br />
1)should we choose the lowest cost edge and then implement algo further?<br />
<br />
2)Or we choose any vertex and then lowest cost edge of that vertex?DShttps://gateoverflow.in/173559/regarding-prims-algoFri, 24 Nov 2017 06:01:49 +0000Prims algorithm
https://gateoverflow.in/170983/prims-algorithm
<p>Consider the following graph and Assume node ‘P’ as the starting vertex for Prim’s algorithm. Which of the following can be the correct order of edges in which they are added to construct Minimum Spanning Tree (MST)?</p>
<p><img alt="image:n104.PNG" src="http://gatexcel.co.in/cache/n104.PNG"></p>
<ol>
<li>P-Q, P-X, X-V, V-U, U-R, R-S, R-W, S-T</li>
<li> P-Q, P-X, X-V, V-U, U-R, R-W, R-S, S-T</li>
<li> P-Q, Q-R, R-W, W-V, V-X, V-U, R-S, S-T</li>
<li> P-Q, Q-R, R-W, R-S, V-X, V-U, W-V, S-T</li>
</ol>Algorithmshttps://gateoverflow.in/170983/prims-algorithmThu, 16 Nov 2017 22:27:35 +0000MST Kruskal
https://gateoverflow.in/165248/mst-kruskal
<p style="text-align:center"><img alt="" height="91" src="https://gateoverflow.in/?qa=blob&qa_blobid=17677029584590517476" width="752"></p>
<p>First statement is False because complexity will be O(E<sup>2</sup>).</p>
<p><strong>I think the second statement is true? But not sure</strong></p>Algorithmshttps://gateoverflow.in/165248/mst-kruskalThu, 02 Nov 2017 08:54:32 +0000Prim's algorithm for MST
https://gateoverflow.in/164219/prims-algorithm-for-mst
Assuming that the graph can contain repeated edge weights, we have a single tree at any instance when applying Prim's algorithm.<br />
<br />
Justify this statement.Algorithmshttps://gateoverflow.in/164219/prims-algorithm-for-mstMon, 30 Oct 2017 09:16:45 +0000Analysis Of Prims Algorithm Time Complexity
https://gateoverflow.in/154329/analysis-of-prims-algorithm-time-complexity
<p>Explain </p>
<ul>
<li>Prims Algorithm</li>
<li>Analysis Of Time Complexity</li>
<li>How does $\mathcal{O}(VlogV + ElogV)=\mathcal{O}(ElogV)$</li>
</ul>Algorithmshttps://gateoverflow.in/154329/analysis-of-prims-algorithm-time-complexityFri, 22 Sep 2017 14:25:18 +0000Self Doubt (Graphs)
https://gateoverflow.in/151515/self-doubt-graphs
<p>How to understand this: For a connected graph, V = O(E))</p>
<p>SOURCE <a rel="nofollow" href="http://www.geeksforgeeks.org/greedy-algorithms-set-5-prims-mst-for-adjacency-list-representation/">http://www.geeksforgeeks.org/greedy-algorithms-set-5-prims-mst-for-adjacency-list-representation/</a></p>
<p>prims algorithm time complexity for adjacency list representation. Also same is given in CLRS but no reason </p>Algorithmshttps://gateoverflow.in/151515/self-doubt-graphsMon, 11 Sep 2017 23:56:23 +0000prims algo from cormen
https://gateoverflow.in/141767/prims-algo-from-cormen
<p style="text-align:center"><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=17871055485514426163"></p>
<p>Here the graph that I was trying to find MST using algo in cormen.(If you need algo to ask, I supposed you have it)</p>
<p>Algorithms uses min queue in process, my dobut is when it came to choice b/w vertex 'c' and 'd' as at that time both will have 8 has key value, if we choose min as 'd' we get wrong answer, so prism deal with this case?</p>
<p>
<br>
If you need algo I will given you, or just please refer chapter 23 cormen prim's algorithm.</p>Algorithmshttps://gateoverflow.in/141767/prims-algo-from-cormenFri, 04 Aug 2017 22:53:09 +0000Difference between Kruskal's and Prim's algorithm ?
https://gateoverflow.in/110577/difference-between-kruskals-and-prims-algorithm
<blockquote>
<p>It may be the case that "Kruskal's Algorithm may not maintain connectivity while Prim's algorithm always does that" ?</p>
</blockquote>
<hr>
<p>Any example which favours this ?</p>Algorithmshttps://gateoverflow.in/110577/difference-between-kruskals-and-prims-algorithmTue, 24 Jan 2017 15:59:09 +0000Prim's Algorithm
https://gateoverflow.in/110365/prims-algorithm
<p><em><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=87839012549417469"></em></p>
<p><em>I am getting B and C both. Answer is given as C. Where am I wrong?</em></p>Algorithmshttps://gateoverflow.in/110365/prims-algorithmTue, 24 Jan 2017 08:55:38 +0000Virtual Gate Test Series: Algorithms - Minimum Spanning Tree
https://gateoverflow.in/103805/virtual-gate-test-series-algorithms-minimum-spanning-tree
<p><img alt="" height="419" src="https://gateoverflow.in/?qa=blob&qa_blobid=340028041458131516" width="844"></p>
<p>I think all options are wrong</p>Algorithmshttps://gateoverflow.in/103805/virtual-gate-test-series-algorithms-minimum-spanning-treeWed, 11 Jan 2017 02:46:05 +0000Targate
https://gateoverflow.in/100870/targate
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=18138104159124353877"></p>
<p>Here it is mentioned as a queue and not a priority queue ,what would be the answer ?</p>Algorithmshttps://gateoverflow.in/100870/targateThu, 05 Jan 2017 05:27:04 +0000Virtual Gate Test Series: Algorithms - Prim's Algorithm
https://gateoverflow.in/98214/virtual-gate-test-series-algorithms-prims-algorithm
<p><img alt="" height="420" src="https://gateoverflow.in/?qa=blob&qa_blobid=2155884445957342397" width="933"></p>
<p>both B and C correct order of prims algo?</p>Algorithmshttps://gateoverflow.in/98214/virtual-gate-test-series-algorithms-prims-algorithmThu, 29 Dec 2016 18:47:03 +0000Analysis Of Prims Algorithm
https://gateoverflow.in/93929/analysis-of-prims-algorithm
I have seen many varients of complexities using diferent data structures in implementing Prims Agorithm. Can you pls post standard algorithm and tells me in details how to derive the complexities. Please also mention the variations possibles when data structure changes and How will effect the complexity taking Best case and Worst case senarios .Algorithmshttps://gateoverflow.in/93929/analysis-of-prims-algorithmSun, 18 Dec 2016 07:21:43 +0000#algorithm
https://gateoverflow.in/76931/%23algorithm
Can Prim's and Kruskal's algorithm yield different minimum spanning trees? Explain why or why not.Algorithmshttps://gateoverflow.in/76931/%23algorithmWed, 26 Oct 2016 09:32:51 +0000Is array implementation better or the min heap in case of Prims algorithm
https://gateoverflow.in/20172/array-implementation-better-the-heap-case-prims-algorithm
For prim's algorithm array implementation takes $O(V^2)$ while min heap implementation takes $O((E+V)\log V)$ time. For dense graph $E = O(V^2).$<br />
<br />
So is array implementation considered better or the min heap one???<br />
<br />
Does the min heap implementation run better for graph with less edges??Algorithmshttps://gateoverflow.in/20172/array-implementation-better-the-heap-case-prims-algorithmSun, 18 Oct 2015 15:52:00 +0000Cormen Edition 3 Exercise 23.2 Question 6 (Page No. 637)
https://gateoverflow.in/19753/cormen-edition-3-exercise-23-2-question-6-page-no-637
Suppose that edge weights are uniformly distributed over half open interval $[0,1)$. Which algorithm kruskal's or prim's can make you run faster?Algorithmshttps://gateoverflow.in/19753/cormen-edition-3-exercise-23-2-question-6-page-no-637Thu, 15 Oct 2015 04:14:44 +0000