Question
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 ?
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 is a Directed Acyclic Graph (DAG), we can topologically sort the vertices in time and then relax the outgoing edges of each vertex in topological order in total time. Thus single-source shortest paths on a DAG takes time in the worst case.
Option (A)
Choosing Dijkstra's complexity or Bellman-Ford when 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.