GATE Overflow for GATE CSE - Recent questions tagged shortest-path
https://gateoverflow.in/tag/shortest-path
Powered by Question2AnswerTIFR CSE 2022 | Part B | Question: 13
https://gateoverflow.in/381996/tifr-cse-2022-part-b-question-13
<p>Consider a directed graph $G=(V, E)$, where each edge $e \in E$ has a positive edge weight $c_e$. Determine the appropriate choices for the blanks below so that the value of the following linear program is the length of the shortest directed path in $G$ from $s$ to $t$. (Assume that the graph has at least one path from $s$ to $t$.)</p>
<p>$\begin{align}<br>
\quad \underline{(\text{blank } 1)\text{imize}} \qquad X_{t} & \\ <br>
\quad \qquad {\text{s.t.}} \qquad X_{s}&\quad = \quad 0 \\ <br>
\quad \qquad X_{w}-X_{v}&\quad \underline{(\text{blank } 2)} & c_{e} \quad \text{(for each edge }e = (v, w) \in E).<br>
\end{align}$ </p>
<ol start="1" style="list-style-type:upper-alpha">
<li>$\text{blank }1: \max, \text{blank }2:\; \leq $</li>
<li>$\text{blank }1: \max, \text{blank }2:\; \geq$</li>
<li>$\text{blank }1: \min, \text{blank }2:\; \leq$</li>
<li>$\text{blank }1: \min, \text{blank }2:\; \geq$</li>
<li>$\text{blank }1: \min, \text{blank }2:\; =$</li>
</ol>Algorithmshttps://gateoverflow.in/381996/tifr-cse-2022-part-b-question-13Thu, 01 Sep 2022 17:42:48 +0000Made Easy Test Series
https://gateoverflow.in/369141/made-easy-test-series
Which of the following can be the best algorithm(s) for all pair of the shortest path problem?<br />
<br />
I. ‘V’ invocations of Dijkstra algorithm ⇒ Ο(VE logV).<br />
II. ‘V’ invocations of Bellman-Ford algorithm ⇒ Ο(V2 E).<br />
III. ‘1’ invocations of Floyd-Warshall algorithm ⇒ Ο(V3).Algorithmshttps://gateoverflow.in/369141/made-easy-test-seriesSat, 08 Jan 2022 08:08:44 +0000Nptel Assignment Question
https://gateoverflow.in/367128/nptel-assignment-question
<p>Consider the following strategy to convert a graph with negative edge weights to one that does not have negative edge weights. Let the maximum magnitude negative edge weight in the graph be -k. Then, for each edge in the graph with weight w, update the weight to w+k+1. Consider the following claim:</p>
<ul>
<li>To solve the shortest path problem in the original graph, we can run Dijkstra's algorithm on the modified graph and subtract the added weights to get the original distances.</li>
</ul>
<p>Which of the following is not correct.</p>
<ol style="list-style-type:upper-alpha" type="A">
<li>The claim is not true in general.</li>
<li>The claim is true for all graphs.</li>
<li>The claim is true for connected acyclic graphs.</li>
<li>The claim is not true in general for connected graphs with cycles</li>
</ol>Algorithmshttps://gateoverflow.in/367128/nptel-assignment-questionWed, 08 Dec 2021 11:50:20 +0000NPTEL Assignment Question
https://gateoverflow.in/367127/nptel-assignment-question
<p>Consider the following strategy to solve the single source shortest path problem with edge weights from source s.</p>
<p>1. Replace each edge with weight w by w edges of weight 1 connected by new intermediate nodes</p>
<p>2. Run BFS(s) on the modified graph to find the shortest path to each of the original vertices in the graph.</p>
<p> </p>
<p>Which of the following statements is correct?</p>
<ol style="list-style-type:upper-alpha" type="A">
<li>This strategy will solve the problem correctly but is not as efficient as Dijkstra's algorithm.</li>
<li>This strategy will solve the problem correctly and is as efficient as Dijkstra's algorithm.s st</li>
<li>This strategy will not solve the problem correctly.</li>
<li>This strategy will only work if the graph is acyclic.</li>
</ol>Algorithmshttps://gateoverflow.in/367127/nptel-assignment-questionWed, 08 Dec 2021 11:48:17 +0000NPTEL Assignment Question
https://gateoverflow.in/367049/nptel-assignment-question
<p>Let G be a weighted connected undirected graph with distinct positive edge weights.</p>
<p>If every edge weight is increased by the same value, then</p>
<p> </p>
<p>which of the following statements is/are TRUE?</p>
<p> </p>
<p>P: Minimum spanning tree of G does not change</p>
<p>Q: Shortest path between any pair of vertices does not change</p>
<p> </p>
<ol style="list-style-type:upper-alpha" type="A">
<li>P only</li>
<li>Q only</li>
<li>Neither P nor Q</li>
<li>Both P and Q</li>
</ol>Algorithmshttps://gateoverflow.in/367049/nptel-assignment-questionTue, 07 Dec 2021 17:34:41 +0000NPTEL Assignment Question
https://gateoverflow.in/367002/nptel-assignment-question
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=14564794211551727693"></p>
<p> </p>Algorithmshttps://gateoverflow.in/367002/nptel-assignment-questionTue, 07 Dec 2021 13:05:07 +0000CMI2018-A-4
https://gateoverflow.in/320489/cmi2018-a-4
<p>Let $G=(V, E)$ be an undirected simple graph, and $s$ be a designated vertex in $G.$ For each $v\in V,$ let $d(v)$ be the length of a shortest path between $s$ and $v.$ For an edge $(u,v)$ in $G,$ what can not be the value of $d(u)-d(v)?$</p>
<ol start="1" style="list-style-type:upper-alpha">
<li>$2$</li>
<li>$-1$</li>
<li>$0$</li>
<li>$1$</li>
</ol>Graph Theoryhttps://gateoverflow.in/320489/cmi2018-a-4Fri, 13 Sep 2019 14:34:32 +0000Made Easy Test Series:Algorithm- Minimum Weight Path
https://gateoverflow.in/311759/made-easy-test-series-algorithm-minimum-weight-path
<p>Consider the following statement:</p>
<p>$A)$ If all edge weight of a graph are positive then any subset of edges that connect all vertices and has minimum total weight is a tree.</p>
<p>$B)$ Let $p=<V_{0},V_{1},V_{2},........V_{k} >$ be the shortest path from vertex $V_{0}$ to $V_{k}$ for all $i,j$ such that $0\leq i\leq j\leq k$ let $p_{ij}$ be subpath of. $p$ from vertex $V_{i}$ to $V_{j}$. Then $p_{ij}$ be the shortest path from $V_{i}$ to $V_{j}$</p>
<p>Which statement is correct?</p>
<hr>
<p>My question is , is tree always needed for minimum weight graph??</p>
<p>and what about B)?? Is it just saying each minimum path between $2$ vertices makes total shortest path?? </p>Algorithmshttps://gateoverflow.in/311759/made-easy-test-series-algorithm-minimum-weight-pathFri, 10 May 2019 09:04:22 +0000Virtual Gate Test Series: Algorithms - Graphs
https://gateoverflow.in/293729/virtual-gate-test-series-algorithms-graphs
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=17934044773399957330"></p>Algorithmshttps://gateoverflow.in/293729/virtual-gate-test-series-algorithms-graphsSun, 13 Jan 2019 07:43:01 +0000GATE Overflow | Mock GATE | Test 1 | Question: 47
https://gateoverflow.in/285432/gate-overflow-mock-gate-test-1-question-47
<p>Which of the following statements is/are correct with respect to Djikstra Algorithm?<br>
(P) It always works perfectly for graphs with negative weight edges.<br>
(Q) It does not work perfectly for graphs with negative weight cycles.<br>
(R) It may or may not work for graphs with negative weight edges.<br>
(S) It may not terminate if the graph has negative weight cycle<br>
(T) It always terminates for graphs with negative weight edges.<br>
(U) Time complexity of Djikstra algorithm becomes $O(V*E)$ if AVL tree is used instead of priority queues.<br>
<br>
</p>
<ol style="list-style-type:upper-alpha">
<li>Only P, Q, S and T are correct</li>
<li>Only P, Q, S, T and U are correct</li>
<li>Only Q, R, T are correct</li>
<li>Only Q, R, S, T and U are correct</li>
</ol>Algorithmshttps://gateoverflow.in/285432/gate-overflow-mock-gate-test-1-question-47Thu, 27 Dec 2018 17:24:40 +0000self doubt multistaGE GRAPH
https://gateoverflow.in/268215/self-doubt-multistage-graph
<p><a href="https://gateoverflow.in/86958/find-shortest-path" rel="nofollow">https://gateoverflow.in/86958/find-shortest-path</a></p>
<p>IN THIS QUESTION WHEN WE DO FINDING FROM END A SITUATION CAME WHERE WE HAVE TWO PATH FROM 8 OF LENGTH 3 EACH SO WHERE TO MOVE NOW AND I AM FINDING MINIMUM LENGTH 14 BUT ANSWER SAYS 15.</p>Algorithmshttps://gateoverflow.in/268215/self-doubt-multistage-graphWed, 21 Nov 2018 05:53:08 +0000Shortest Path
https://gateoverflow.in/267341/shortest-path
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=3943399480616220154"></p>Algorithmshttps://gateoverflow.in/267341/shortest-pathMon, 19 Nov 2018 06:55:11 +0000shortest path
https://gateoverflow.in/261858/shortest-path
Can shortest path contains positive weight cycle???Please explain with examples.Algorithmshttps://gateoverflow.in/261858/shortest-pathTue, 06 Nov 2018 01:55:54 +0000Bellmann Ford Algorithm
https://gateoverflow.in/254891/bellmann-ford-algorithm
Consider following with respect to directed graph where there can be positive,negative edge weights but no negative edge cycle.<br />
<br />
S1 : The Bellmann Ford algorithm will compute correctly the shortest path from source vertex S to every other Vertex.<br />
<br />
S2 : The Floyd Warshall algorithm will compute correctly the shortest path between every pair of Verices.<br />
<br />
Which of Following statements are Correct ?<br />
<br />
A. Only S1<br />
<br />
B. Only S2<br />
<br />
C. Both<br />
<br />
D. NoneAlgorithmshttps://gateoverflow.in/254891/bellmann-ford-algorithmSat, 20 Oct 2018 10:42:50 +0000How Bellman ford is dynamic programming?
https://gateoverflow.in/230530/how-bellman-ford-is-dynamic-programming
<pre>
What is the reason behind it? How do we find an optimal substructure and overlapping sub problems in this ? In which line of code memoization is done?
BELLMAN-FORD(G,w,s)
Code
1. INITIALIZE-SINGLE-SOURCE(G,s)
2. for i = 1 to |G.V|-1
3. for each edge (u,v) ∈ G.E
4. RELAX(u,v,w)
5. for each edge (u,v) ∈ G.E
6. if v.d > u.d + w(u,v)
7. return FALSE
8. return TRUE
INITIALIZE-SINGLE-SOURCE(G,s)
1. for each vertex v ∈ G.V
2. v.d = ∞
3. v.pi = NIL
4. s.d = 0
RELAX(u,v,w)
1. if v.d > u.d + w(u,v)
2. v.d = u.d + w(u,v)
3. v.pi = u</pre>Algorithmshttps://gateoverflow.in/230530/how-bellman-ford-is-dynamic-programmingFri, 03 Aug 2018 05:16:29 +0000shortest path algo
https://gateoverflow.in/229633/shortest-path-algo
TRUE / FALSE Explain Please..<br />
<br />
An undirected graph is said to be Hamiltonian if it has a cycle containing all the vertices. Any DFS tree on a Hamiltonian graph must have depth V − 1.Algorithmshttps://gateoverflow.in/229633/shortest-path-algoMon, 30 Jul 2018 20:14:23 +0000Space Complexity of Dijkastra's algorithm
https://gateoverflow.in/223992/space-complexity-of-dijkastras-algorithm
<p>I read that the space complexity of Dijasktra is $O(V^2)$ . (<a rel="nofollow" href="http://igraph.wikidot.com/algorithm-space-time-complexity">http://igraph.wikidot.com/algorithm-space-time-complexity</a>)<br>
<br>
But how ????<br>
</p>Algorithmshttps://gateoverflow.in/223992/space-complexity-of-dijkastras-algorithmThu, 05 Jul 2018 18:22:37 +0000Regarding the complexity of Bellman-Ford ?
https://gateoverflow.in/219069/regarding-the-complexity-of-bellman-ford
<p>In the adjacency list implementation of <strong>Bellman Ford algorithm </strong> every edge is visited at most one time and total of <strong>|E|</strong> are present in the adjacency list. So,how can the complexity be <strong>O(VE) </strong>why can't it be O(E) .Though it has two loops on whole it will run for |E| times. ??</p>Algorithmshttps://gateoverflow.in/219069/regarding-the-complexity-of-bellman-fordFri, 01 Jun 2018 07:21:28 +0000#Algorithm Bellman Ford uses which algorithm design technique
https://gateoverflow.in/217026/%23algorithm-bellman-ford-which-algorithm-design-technique
Is it Dynamic programming?Algorithmshttps://gateoverflow.in/217026/%23algorithm-bellman-ford-which-algorithm-design-techniqueThu, 17 May 2018 16:05:56 +0000# Self doubt
https://gateoverflow.in/214246/%23-self-doubt
To get in shape, you have decided to start running to work. You want a route that goes entirely uphill and then entirely downhill so that you can work up a sweat going uphill and then get a nice breeze at the end of your run as you run faster downhill. Your run will start at home and end at work and you have a map detailing the roads with l road segments(any existing road between two intersections) and m intersections. Each road segment has a positive length, and each intersection has a distinct elevation. Assuming that every road segment is either uphill or downhill, give an efficient algorithm to find out shortest route that meets above specification??Algorithmshttps://gateoverflow.in/214246/%23-self-doubtWed, 25 Apr 2018 17:45:10 +0000Equality of shortest path tree for given node as a root and
https://gateoverflow.in/208996/equality-of-shortest-path-tree-for-given-node-as-a-root-and
<p>I have a small doubt.</p>
<p>Chapter 25 All pairs shortest path of CLRS says following:</p>
<blockquote>
<p>To solve the all-pairs shortest-paths problem on an input adjacency matrix, we need to compute not only the shortest-path weights but also a predecessor matrix $\Pi=(\pi_{ij})$, where $\pi_{ij}$ is $\text{NIL}$ if either $i=j$ or there is no path from $i$ to $j$, and otherwise $\pi_{ij}$ is the predecessor of $j$ on some shortest path from $i$. The subgraph induced by the $i$ th row of the $\Pi$ matrix should be a <strong>shortest-paths tree with root $i$</strong>. For each vertex $i\in V$, we define the <strong>predecessor subgraph</strong> <strong>of $G$ for $i$ </strong>as $G_{\pi,i}=(V_{\pi,i},E_{\pi,i})$, where</p>
<p>$V_{\pi,i}=\{j\in V:\pi_{ij}\neq \text{NIL}\}\cup \{i\}$</p>
<p>and </p>
<p>$E_{\pi,i}=\{(\pi_{i,j},j):j\in V_{\pi,i}-\{i\}\}$</p>
</blockquote>
<p>My doubt is, isnt both things (shortest-paths tree with root $i$ and predecessor subgraph of $G$ for $i$) the same?</p>Programminghttps://gateoverflow.in/208996/equality-of-shortest-path-tree-for-given-node-as-a-root-andSat, 24 Mar 2018 06:51:24 +0000Negative edge weights in Dijkstra
https://gateoverflow.in/202260/negative-edge-weights-in-dijkstra
<p>All text books and online resources say </p>
<blockquote>
<p>Dijkstra's algorithm need all non negative edge weights</p>
</blockquote>
<p>However I feel a bit different, especially after coming across problem asking to build shortest path tree from node aa in following graph:</p>
<p><a href="https://i.stack.imgur.com/ZPN6w.png" rel="nofollow"><img alt="enter image description here" src="https://i.stack.imgur.com/ZPN6w.png"></a></p>
<p>My shortest path tree after running Dijkstra came like this:</p>
<p><a href="https://i.stack.imgur.com/KI0or.png" rel="nofollow"><img alt="enter image description here" src="https://i.stack.imgur.com/KI0or.png"></a></p>
<p>Then why texts say that Dijkstra need all non negative edge weights? I feel that it should be no -ve edge weight cycle reachable from source node. Am I correct with this? or am I missing something here?</p>Algorithmshttps://gateoverflow.in/202260/negative-edge-weights-in-dijkstraThu, 01 Feb 2018 06:26:38 +0000Dijkstra Algorithm
https://gateoverflow.in/199530/dijkstra-algorithm
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=2547610579144661080"></p>
<p>I think answer should be Option(B).</p>
<p>Path:<s,y><y,x><x,t> = 7-3-2=2</p>Algorithmshttps://gateoverflow.in/199530/dijkstra-algorithmThu, 25 Jan 2018 04:44:14 +0000algorithm
https://gateoverflow.in/187913/algorithm
<p style="text-align:center"><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=6126438122821802574"></p>
Algorithmshttps://gateoverflow.in/187913/algorithmSun, 31 Dec 2017 06:51:19 +0000madeeasy
https://gateoverflow.in/187825/madeeasy
<p>Consider the following statements with respect to a directed graph <em>G</em> in which edges can have positive or negative edge length but that has no negative cycles:</p>
<ul>
<li><strong>S1 :</strong> The Bellman-Ford algorithm correctly computes shortest path lengths from a given origin ‘<em>s</em>’ to every other vertex ‘<em>v</em> ’.</li>
<li><strong>S2 :</strong> The Floyd-Warshall algorithm correctly computes shortest path lengths between every pair of vertices.</li>
</ul>
<p>Which of the following is correct?</p>Algorithmshttps://gateoverflow.in/187825/madeeasySun, 31 Dec 2017 03:16:11 +0000shortest path
https://gateoverflow.in/180822/shortest-path
Read the following statements below<br />
For all the below questions consider the graph as simple and has positive weight edges.<br />
<br />
(i) Let the cost of the shortest path between two nodes is S.If the weight of every edge in the graph is doubled then weight of the shortest path between the two nodes changes to 2*S.<br />
<br />
(ii) Let the cost of the shortest path between two nodes is S . If the weight of every edge in the graph is doubled then, the weight of the shortest path between the two nodes increases by a factor of 2*k, where k is the minimum number of edges used to reach the destination among all such shortest paths.<br />
<br />
(iii) We can use Kruskal’s algorithm to find Minimum spanning tree of a directed graph .<br />
<br />
How many of the above statements are true.Algorithmshttps://gateoverflow.in/180822/shortest-pathWed, 13 Dec 2017 13:02:52 +0000Shortest path - bellman ford and floyd warshall
https://gateoverflow.in/179546/shortest-path-bellman-ford-and-floyd-warshall
<p>Consider the following statements with respect to a directed graph <em>G</em> in which edges can have positive or negative edge length but that has no negative cycles:<br>
<strong>S1 :</strong> The Bellman-Ford algorithm correctly computes shortest path lengths from a given origin ‘<em>s</em>’ to every other vertex ‘<em>v</em> ’.<br>
<strong>S2 :</strong> The Floyd-Warshall algorithm correctly computes shortest path lengths between every pair of vertices.<br>
Which of them is correct?</p>Algorithmshttps://gateoverflow.in/179546/shortest-path-bellman-ford-and-floyd-warshallSun, 10 Dec 2017 10:23:59 +0000TIFR CSE 2018 | Part B | Question: 9
https://gateoverflow.in/179293/tifr-cse-2018-part-b-question-9
<p>Let $G=(V,E)$ be a DIRECTED graph, where each edge $\large e$ has a positive weight $\large\omega(e),$ and all vertices can be reached from vertex $\large s.$ For each vertex $\large v,$ let $\large \phi(v)$ be the length of the shortest path from $\large s$ to $\large v.$ Let $G'=(V,E)$ be a new weighted graph with the same vertices and edges, but with the edge weight of every edge $\large e=(u\to v)$ changed to $\large \omega'(e)=\omega(e)+\phi(v)-\phi(u).$ Let $P$ be a path from $\large s$ to a vertex $\large v,$ and let $\large \omega(P)=\sum_{e\in P} \omega_{e},$ and $\large \omega'(P)=\sum_{e\in P} \omega'_{e}.$</p>
<p>Which of the following options is NOT NECESSARILY TRUE ?</p>
<ol style="list-style-type:upper-alpha">
<li>If $P$ is a shortest path in $G,$ then $P$ is a shortest path in $G'.$</li>
<li>If $P$ is a shortest path in $F',$ then P is a shortest path in $G.$</li>
<li>If $P$ is a shortest path in $G,$ then $\omega'(P)=2\times \omega(P).$</li>
<li>If $P$ is NOT a shortest path in $G,$ then $\omega'(P)<2\times \omega(P).$</li>
<li>All of the above options are necessarily TRUE.</li>
</ol>Algorithmshttps://gateoverflow.in/179293/tifr-cse-2018-part-b-question-9Sun, 10 Dec 2017 01:38:43 +0000Virtual gate
https://gateoverflow.in/176296/virtual-gate
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=3461392251793871006"></p>Algorithmshttps://gateoverflow.in/176296/virtual-gateSat, 02 Dec 2017 08:14:39 +0000