Shortest paths with a bounded edge budget
Graph Algorithms

Answer & solution
Official answer: A
Givens and goal
In an undirected integer-weighted graph, dk(u) is the minimum weight of an s-to-u path with at most k edges, or infinity if none exists. S1 says dk+1(u)≤dk(u). S2 says that if edge (u,v) lies on a shortest s-to-v path, then dk(u)≤dk(v) for every k. Classify S1 and S2.
Approach
Compare nested feasible path sets for S1 and use an explicit small edge-budget counterexample for S2.
Step-by-step solution
1. Every path using at most k edges also uses at most k+1 edges. The feasible set for dk(u) is therefore contained in the feasible set for dk+1(u).
2. Minimizing over a larger set cannot increase the minimum. Hence dk+1(u)≤dk(u), including the situation where an unavailable path of value infinity becomes available. S1 is true without assuming positive weights.
3. For S2, consider four vertices s,a,u,v with edges s—a of weight 1, a—u of weight 1, u—v of weight 1, and s—v of weight 10. The shortest s-to-v path is s—a—u—v, of total weight 3, and it includes (u,v).
4. Impose budget k=1. There is no one-edge s-to-u path, so d₁(u)=∞. But the direct edge s—v is permitted, giving d₁(v)=10. The asserted inequality ∞≤10 is false.
5. Thus only S1 holds, option A. Being a prefix of an unrestricted shortest path does not imply being reachable under the same smaller edge budget. The counterexample uses strictly positive integer weights, so the failure does not depend on negative cycles or an ambiguity about repeated vertices.

![Question 50, GATE 2026: DFS assigns each vertex discovery time d and finish time f. The directed input graph is acyclic. For an edge u→v, which time orders are impossible? A d[u]<d[v]<f[v]<f[u]; B d[v]<d[u]<f[u]<f[v]; C d[v]<f[v]<d[u]<f[u]; D d[u]<d[v]<f[u]<f[v].](../../../assets/questions/CS-2026-S1-Q50-1.webp)






























![Question 41, GATE 2016: An undirected simple graph with n vertices and m edges uses adjacency lists. Entries [v] in u’s list and [u] in v’s list are twins. With unrestricted auxiliary memory, find the best time to set all twin pointers. A Θ(n²); B Θ(n+m); C Θ(m²); D Θ(n⁴).](../../../assets/questions/CS-2016-S2-Q51-1.webp)
















![Question 50, GATE 2010: A complete undirected graph has vertices 0,1,2,3,4 and symmetric weight matrix W, with rows/columns in that order: [[0,1,8,1,4],[1,0,12,4,9],[8,12,0,7,3],[1,4,7,0,2],[4,9,3,2,0]]. What is the minimum weight of a spanning tree in which vertex 0 is a leaf?
Options: (A) 7; (B) 8; (C) 9; (D) 10.](../../../assets/questions/CS-2010-Q60-1.webp)
![Question 50, GATE 2010: A complete undirected graph has vertices 0,1,2,3,4 and symmetric weight matrix W, with rows/columns in that order: [[0,1,8,1,4],[1,0,12,4,9],[8,12,0,7,3],[1,4,7,0,2],[4,9,3,2,0]]. What is the minimum weight of a spanning tree in which vertex 0 is a leaf?
Options: (A) 7; (B) 8; (C) 9; (D) 10.](../../../assets/questions/CS-2010-Q60-2.webp)
![Question 51, GATE 2010: A complete undirected graph has vertices 0,1,2,3,4 and symmetric weight matrix W, with rows/columns in that order: [[0,1,8,1,4],[1,0,12,4,9],[8,12,0,7,3],[1,4,7,0,2],[4,9,3,2,0]]. What is the minimum weight of a path from vertex 1 to vertex 2 containing at most three edges?
Options: (A) 7; (B) 8; (C) 9; (D) 10.](../../../assets/questions/CS-2010-Q61-1.webp)
![Question 51, GATE 2010: A complete undirected graph has vertices 0,1,2,3,4 and symmetric weight matrix W, with rows/columns in that order: [[0,1,8,1,4],[1,0,12,4,9],[8,12,0,7,3],[1,4,7,0,2],[4,9,3,2,0]]. What is the minimum weight of a path from vertex 1 to vertex 2 containing at most three edges?
Options: (A) 7; (B) 8; (C) 9; (D) 10.](../../../assets/questions/CS-2010-Q61-2.webp)










![Question 47, GATE 2006: An undirected graph has vertices a,b,c,d,e,f and weighted edges ab:1, ac:6, bc:3, bd:4, bf:2, cd:2, ce:4, cf:7, de:3, df:1, ef:5. Which sequence cannot be the edges added, in order, by Kruskal’s minimum-spanning-tree algorithm? GFG A prints af, an edge absent from the graph; GateForum A instead prints df. Both readings are retained.
Options:
(A) ab, af, bf, dc, de [GFG]; ab, df, bf, dc, de [GateForum]
(B) ab, df, dc, bf, de
(C) df, ab, dc, bf, de
(D) df, ab, bf, de, dc](../../../assets/questions/CS-2006-Q47-1.webp)
![Question 47, GATE 2006: An undirected graph has vertices a,b,c,d,e,f and weighted edges ab:1, ac:6, bc:3, bd:4, bf:2, cd:2, ce:4, cf:7, de:3, df:1, ef:5. Which sequence cannot be the edges added, in order, by Kruskal’s minimum-spanning-tree algorithm? GFG A prints af, an edge absent from the graph; GateForum A instead prints df. Both readings are retained.
Options:
(A) ab, af, bf, dc, de [GFG]; ab, df, bf, dc, de [GateForum]
(B) ab, df, dc, bf, de
(C) df, ab, dc, bf, de
(D) df, ab, bf, de, dc](../../../assets/questions/CS-2006-Q47-2.webp)












![Question 70, GATE 2003: G is a directed n-vertex graph. A path may repeat vertices; a simple path has no repeated vertex. Initialize A[j,k]=1 when edge (j,k) exists, otherwise 0. Run in-place:
for i=1,...,n:
for j=1,...,n:
for k=1,...,n:
A[j,k]=max(A[j,k], A[j,i]+A[i,k])
Which is necessarily true at termination?
A. A[j,k]≤n
B. If A[j,j]≥n−1, G has a Hamiltonian cycle
C. Whenever a path j→k exists, A[j,k] is its longest-path length
D. Whenever a path j→k exists, every simple j→k path has at most A[j,k] edges](../../../assets/questions/CS-2003-Q70-1.webp)
![Question 70, GATE 2003: G is a directed n-vertex graph. A path may repeat vertices; a simple path has no repeated vertex. Initialize A[j,k]=1 when edge (j,k) exists, otherwise 0. Run in-place:
for i=1,...,n:
for j=1,...,n:
for k=1,...,n:
A[j,k]=max(A[j,k], A[j,i]+A[i,k])
Which is necessarily true at termination?
A. A[j,k]≤n
B. If A[j,j]≥n−1, G has a Hamiltonian cycle
C. Whenever a path j→k exists, A[j,k] is its longest-path length
D. Whenever a path j→k exists, every simple j→k path has at most A[j,k] edges](../../../assets/questions/CS-2003-Q70-2.webp)
![Question 12(a), GATE 2002: Complete a template computing all-pairs shortest-path lengths in a directed graph G. Its n×n adjacency matrix A has A[i,j]=1 for an edge i→j and 0 otherwise. Initialization loops over i=1..n and j=1..n and executes:
if A[i,j]=0 then P[i,j]=____ else P[i,j]=____;
The algorithm then has nested loops, in this exact order: for i=1..n, for j=1..n, for k=1..n, executing:
P[____,____] = min{____,____};
Copy and complete the initialization line so that the algorithm is correct.](../../../assets/questions/CS-2002-Q70-1.webp)
![Question 12(a), GATE 2002: Complete a template computing all-pairs shortest-path lengths in a directed graph G. Its n×n adjacency matrix A has A[i,j]=1 for an edge i→j and 0 otherwise. Initialization loops over i=1..n and j=1..n and executes:
if A[i,j]=0 then P[i,j]=____ else P[i,j]=____;
The algorithm then has nested loops, in this exact order: for i=1..n, for j=1..n, for k=1..n, executing:
P[____,____] = min{____,____};
Copy and complete the initialization line so that the algorithm is correct.](../../../assets/questions/CS-2002-Q70-2.webp)
![Question 12(b), GATE 2002: Complete a template computing all-pairs shortest-path lengths in a directed graph G. Its n×n adjacency matrix A has A[i,j]=1 for an edge i→j and 0 otherwise. Initialization loops over i=1..n and j=1..n and executes:
if A[i,j]=0 then P[i,j]=____ else P[i,j]=____;
The algorithm then has nested loops, in this exact order: for i=1..n, for j=1..n, for k=1..n, executing:
P[____,____] = min{____,____};
Copy and complete the line in the algorithm’s triple loop so that the algorithm is correct.](../../../assets/questions/CS-2002-Q71-1.webp)
![Question 12(b), GATE 2002: Complete a template computing all-pairs shortest-path lengths in a directed graph G. Its n×n adjacency matrix A has A[i,j]=1 for an edge i→j and 0 otherwise. Initialization loops over i=1..n and j=1..n and executes:
if A[i,j]=0 then P[i,j]=____ else P[i,j]=____;
The algorithm then has nested loops, in this exact order: for i=1..n, for j=1..n, for k=1..n, executing:
P[____,____] = min{____,____};
Copy and complete the line in the algorithm’s triple loop so that the algorithm is correct.](../../../assets/questions/CS-2002-Q71-2.webp)
![Question 12(c), GATE 2002: Complete a template computing all-pairs shortest-path lengths in a directed graph G. Its n×n adjacency matrix A has A[i,j]=1 for an edge i→j and 0 otherwise. Initialization loops over i=1..n and j=1..n and executes:
if A[i,j]=0 then P[i,j]=____ else P[i,j]=____;
The algorithm then has nested loops, in this exact order: for i=1..n, for j=1..n, for k=1..n, executing:
P[____,____] = min{____,____};
Complete the running-time expression O(____).](../../../assets/questions/CS-2002-Q72-1.webp)
![Question 12(c), GATE 2002: Complete a template computing all-pairs shortest-path lengths in a directed graph G. Its n×n adjacency matrix A has A[i,j]=1 for an edge i→j and 0 otherwise. Initialization loops over i=1..n and j=1..n and executes:
if A[i,j]=0 then P[i,j]=____ else P[i,j]=____;
The algorithm then has nested loops, in this exact order: for i=1..n, for j=1..n, for k=1..n, executing:
P[____,____] = min{____,____};
Complete the running-time expression O(____).](../../../assets/questions/CS-2002-Q72-2.webp)












































