Shortest Path · Algorithms
22 questions · asked in 17 of 27 years (2000–2026)
MCQ 21 · NAT 11-mark 12 · 2-mark 10
2000Questions per year2026
Questions 1–5 of 22
Let be an undirected, edge-weighted graph with integer weights. The weight of a path is the sum of the weights of the edges in that path. The length of a path is the number of edges in that path.
Let be a vertex in . For every and for every , let denote the weight of a shortest path (in terms of weight) from to of length at most . If there is no path from to of length at most , then .
Consider the statements:
S1: For every and .
S2: For every , if is part of a shortest path (in terms of weight) from to , then for every .
Which one of the following options is correct?
Let be a vertex in . For every and for every , let denote the weight of a shortest path (in terms of weight) from to of length at most . If there is no path from to of length at most , then .
Consider the statements:
S1: For every and .
S2: For every , if is part of a shortest path (in terms of weight) from to , then for every .
Which one of the following options is correct?
Answer: (A)
is the least weight among paths from to with at most edges.
S1 is true. Every path with at most edges also has at most edges. So is a minimum over a larger set of paths, and it cannot be bigger than .
S2 is false. The condition only says lies on some shortest path to ; it does not say that path is short in edges. Counterexample: edges , , with weight 0, and an edge with weight 5. The path has weight 0, so it is a shortest path to and it uses the edge . For : (direct edge), but is 2 edges from , so . Then fails.
Only S1 is true.
Answer: (A)
S1 is true. Every path with at most edges also has at most edges. So is a minimum over a larger set of paths, and it cannot be bigger than .
S2 is false. The condition only says lies on some shortest path to ; it does not say that path is short in edges. Counterexample: edges , , with weight 0, and an edge with weight 5. The path has weight 0, so it is a shortest path to and it uses the edge . For : (direct edge), but is 2 edges from , so . Then fails.
Only S1 is true.
Answer: (A)
Let be a weighted directed acyclic graph with edges and vertices. Given and a source vertex in , which one of the following options gives the worst case time complexity of the fastest algorithm to find the lengths of shortest paths from to all vertices that are reachable from in
Answer: (A)
For a directed acyclic graph (DAG) the fastest method has two steps.
(1) Find a topological order of the vertices: .
(2) Take the vertices in that order and relax each outgoing edge of each vertex once: in total.
This is correct because in topological order every edge into a vertex has been relaxed before that vertex is processed, so its distance is already final. So no priority queue and no repeated passes are needed, and negative edge weights cause no trouble.
Option (B) is Dijkstra's bound with a priority queue, which is never faster than . Option (C) is the Bellman-Ford bound. Option (D) is the all-pairs Floyd-Warshall bound.
Answer: (A)
(1) Find a topological order of the vertices: .
(2) Take the vertices in that order and relax each outgoing edge of each vertex once: in total.
This is correct because in topological order every edge into a vertex has been relaxed before that vertex is processed, so its distance is already final. So no priority queue and no repeated passes are needed, and negative edge weights cause no trouble.
Option (B) is Dijkstra's bound with a priority queue, which is never faster than . Option (C) is the Bellman-Ford bound. Option (D) is the all-pairs Floyd-Warshall bound.
Answer: (A)
Let be an undirected and unweighted graph with 100 vertices. Let denote the number of edges in a shortest path between vertices and in . Let the maximum value of , such that , be 30. Let be any breadth-first-search tree of . Which ONE of the given options is CORRECT for every such graph ?
Answer: (C)
Let be the root of the BFS tree . BFS puts each vertex at a level equal to its distance from , so the height is .
Lower bound. Some pair has . For any root , , so .
Why the other options fail. The height can also be larger. Take a path of 31 vertices (length 30) and attach the other 69 vertices to its middle vertex. The diameter is still 30. BFS from the middle vertex has height 15, so (B) and (D) are not true for every such graph. BFS from an end of the path has height 30, so (A) is not true for every such graph.
Answer: (C)
Lower bound. Some pair has . For any root , , so .
Why the other options fail. The height can also be larger. Take a path of 31 vertices (length 30) and attach the other 69 vertices to its middle vertex. The diameter is still 30. BFS from the middle vertex has height 15, so (B) and (D) are not true for every such graph. BFS from an end of the path has height 30, so (A) is not true for every such graph.
Answer: (C)
Let be an edge-weighted undirected graph with positive edge weights. Suppose a positive constant is added to the weight of every edge.
Which ONE of the following statements is TRUE about the minimum spanning trees (MSTs) and shortest paths (SPs) in before and after the edge weight update?
Which ONE of the following statements is TRUE about the minimum spanning trees (MSTs) and shortest paths (SPs) in before and after the edge weight update?
Answer: (C)
If we add the same positive constant to every edge, the total weight of any spanning tree goes up by exactly . This is because every spanning tree has exactly edges, the same number. The shift is the same for all trees, so it does not change which spanning tree has the minimum total weight. So every MST remains an MST.
Shortest paths are different. A path can have a different number of edges depending on the route. A path with fewer edges gets a smaller total addition of than a path with more edges. This can change which path is the shortest after the update. So SPs need not remain SPs.
Answer: Every MST remains an MST, and SPs need not remain SPs.
Shortest paths are different. A path can have a different number of edges depending on the route. A path with fewer edges gets a smaller total addition of than a path with more edges. This can change which path is the shortest after the update. So SPs need not remain SPs.
Answer: Every MST remains an MST, and SPs need not remain SPs.
Let be an undirected unweighted connected graph. The diameter of is defined as:
Let be the adjacency matrix of .
Define graph on the same set of vertices with adjacency matrix , where
Which one of the following statements is true?
Let be the adjacency matrix of .
Define graph on the same set of vertices with adjacency matrix , where
Which one of the following statements is true?
Answer: (A)
means there is a walk of length 2 from to . So in two vertices are adjacent when their distance in is 1 or 2.
Upper bound. Take a shortest path of length in and jump two edges at a time. This reaches the end in edges of .
Lower bound. Each edge of spans at most 2 edges of , so edges of cover a distance of at most in .
So the distance in is exactly , and .
So option (A) is true. Options (B), (C) and (D) each need to be larger than , which does not happen.
Answer: (A)
Upper bound. Take a shortest path of length in and jump two edges at a time. This reaches the end in edges of .
Lower bound. Each edge of spans at most 2 edges of , so edges of cover a distance of at most in .
So the distance in is exactly , and .
So option (A) is true. Options (B), (C) and (D) each need to be larger than , which does not happen.
Answer: (A)
Keep practising