GATE 2026 CS (CS2) – Question 37
Let $G$ be a weighted directed acyclic graph with $m$ edges and $n$ vertices. Given $G$ and a source vertex $s$, which one of the following options gives the worst-case time complexity of the fastest algorithm to find the lengths of shortest paths from $s$ to all vertices reachable from $s$?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (A) $\Theta(m+n)$
Explanation
In a weighted DAG, shortest paths from a source can be found by processing the vertices in topological order and relaxing each outgoing edge once. Computing a topological order and relaxing all edges together take $\Theta(m+n)$ time. Therefore, option (A) is correct.