Question

Let GG be a weighted directed acyclic graph with mm edges and nn vertices. Given GG and a source vertex ss in GG, which one of the following options gives the worst case time complexity of the fastest algorithm to find the lengths of shortest paths from ss to all vertices that are reachable from ss in GG?

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2026 answer key

Solution

Use topological sorting followed by single-pass edge relaxation on a DAG.

Because GG is a Directed Acyclic Graph (DAG), we can topologically sort the vertices in Θ(m+n)\Theta(m + n) time and then relax the outgoing edges of each vertex in topological order in Θ(m+n)\Theta(m + n) total time. Thus single-source shortest paths on a DAG takes Θ(m+n)\Theta(m + n) time in the worst case.

Final answer

Option (A)

Common trap

Choosing Dijkstra's complexity Θ(m+nlog⁡n)\Theta(m + n \log n) or Bellman-Ford Θ(nm)\Theta(nm) when GG is a DAG.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2026 Computer Science and Information Technology - Session 2 (CS2)
Question
37 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.