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 16–20 of 22
To implement Dijkstra's shortest path algorithm on unweighted graphs so that it runs in linear time, then data structure to be used is
Answer: (A)
On an unweighted graph every edge has the same cost, so Dijkstra's algorithm becomes Breadth First Search (BFS). BFS keeps the vertices in a queue (FIFO). Vertices leave the queue in order of nondecreasing distance from the source, so the first time a vertex is reached is by a shortest path. Each vertex is queued once and each edge is checked once, so the time is , which is linear.
A heap (C) is needed only when edge weights differ, and it adds a factor. A stack (B) gives depth-first order, which does not give shortest paths. A B-tree (D) is a disk-based search structure and does not help here.
Answer: (A)
A heap (C) is needed only when edge weights differ, and it adds a factor. A stack (B) gives depth-first order, which does not give shortest paths. A B-tree (D) is a disk-based search structure and does not help here.
Answer: (A)
Let be a directed graph whose vertex set is the set of numbers from 1 to 100. There is an edge from a vertex to a vertex iff either or . The minimum number of edges in a path in G from vertex 1 to vertex 100 is
Answer: (B)
Searching from 1 forward has many branches, so search backward from 100. The predecessors of are , and also when 3 divides . Number the sets by distance from 100:
- 0: 100
- 1: 99
- 2: 98, 33
- 3: 97, 32, 11
- 4: 96, 31, 10
- 5: 95, 30, 9
- 6: 94, 29, 8, 3
- 7: contains 1 (from 3)
1 first appears at distance 7, so no path has fewer than 7 edges. The forward path is , with 7 edges.
Answer: (B)
- 0: 100
- 1: 99
- 2: 98, 33
- 3: 97, 32, 11
- 4: 96, 31, 10
- 5: 95, 30, 9
- 6: 94, 29, 8, 3
- 7: contains 1 (from 3)
1 first appears at distance 7, so no path has fewer than 7 edges. The forward path is , with 7 edges.
Answer: (B)
Let s and t be two vertices in a undirected graph G=(V, E) having distinct positive edge weights. Let [X, Y] be a partition of V such that sX and tY. Consider the edge e having the minimum weight amongst all those edges that have one vertex in X and one vertex in Y.
Let the weight of an edge e denote the congestion on that edge. The congestion on a path is defined to be the maximum of the congestions on the edges of the path. We wish to find the path from s to t having minimum congestion. Which one of the following paths is always such a path of minimum congestion?
Let the weight of an edge e denote the congestion on that edge. The congestion on a path is defined to be the maximum of the congestions on the edges of the path. We wish to find the path from s to t having minimum congestion. Which one of the following paths is always such a path of minimum congestion?
Answer: (A)
The congestion of a path is its largest edge weight, so we want a path whose largest edge is as small as possible.
Why the MST path works. Take the path from to in the minimum spanning tree and let be its heaviest edge, with weight . Remove from the tree. The tree splits into two parts, with in one and in the other. By the cut property, is the lightest edge crossing this cut (otherwise swapping it for a lighter crossing edge would give a lighter tree). Every path from to must cross the cut, so it uses an edge of weight at least . So no path has congestion below , and the MST path has exactly .
Other options. In the figure, the shortest weighted path is the direct edge with weight 6, and its congestion is 6. The MST has edges 2, 3 and 4, and its path has congestion . So option B can fail (the path has total weight 7, which is longer, but congestion is the only thing that counts here). An Euler walk uses every edge, so its congestion is the heaviest edge in the whole graph (6 here). A Hamiltonian path must visit every vertex, so it can be forced onto heavy edges, and it may not exist at all.
Answer: (A)
Let G(V,E) be an undirected graph with positive edge weights. Dijkstra's single source shortest path algorithm can be implemented using the binary heap data structure with time complexity:
Answer: (D)
Option : Uses a binary heap. There are decrease key operations, and each takes time. There are extract-min operations, and each takes .
Option : Uses a Fibonacci heap. There are decrease key operations, and each takes time. There are extract-min operations, and each takes .
Option : Uses an array. Finding the min-vertex in each iteration takes . This is done times.
A Binomial Heap works the same as a Binary heap here, because the main operations are decrease key and extract-min.
Correct Answer:
Option : Uses a Fibonacci heap. There are decrease key operations, and each takes time. There are extract-min operations, and each takes .
Option : Uses an array. Finding the min-vertex in each iteration takes . This is done times.
A Binomial Heap works the same as a Binary heap here, because the main operations are decrease key and extract-min.
Correct Answer:
Suppose we run Dijkstra's single source shortest-path algorithm on the following edge-weighted directed graph with vertex P as the source.
In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized?
In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized?
Answer: (B)
Dijkstra's algorithm finalises the unfinished vertex with the smallest tentative distance from the source , then relaxes its outgoing edges.
Start: . Edges from give .
1. Finalise .
2. Finalise (1): , .
3. Finalise (2): , .
4. Finalise (3): it has no outgoing edges.
5. Finalise (4): , and stays 3.
6. Finalise (7).
Order: .
Answer: (B)
Start: . Edges from give .
1. Finalise .
2. Finalise (1): , .
3. Finalise (2): , .
4. Finalise (3): it has no outgoing edges.
5. Finalise (4): , and stays 3.
6. Finalise (7).
Order: .
Answer: (B)
Keep practising