GateAI
Shortest Paths

GATE CSE 2026 Set 2 · Q37

MCQ2 marksEasy

Time

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?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) (m + n)

Shortest Paths

For a weighted Directed Acyclic Graph (DAG), single-source shortest paths can be computed efficiently by processing vertices in topologically sorted order [1]:

  1. Topologically sort the vertices of the DAG in Θ(n+m)\Theta(n + m) time using Depth First Search (DFS) or Kahn's algorithm [1].

  2. Initialize the distance to the source ss as 00 and to all other vertices as ∞\infty in Θ(n)\Theta(n) time [1].

  3. Iterate through the vertices in topological order and relax all outgoing edges from each vertex [1]. Since each edge and vertex is relaxed/visited once, the total time for edge relaxation across the entire graph is Θ(m)\Theta(m) [1].

Thus, the total worst-case running time is:

Θ(n+m)+Θ(n)+Θ(m)=Θ(m+n)\Theta(n + m) + \Theta(n) + \Theta(m) = \Theta(m + n)

Hence, (A) is the correct option [1].

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Shortest Paths previous year question is Q37 of the GATE CSE 2026 Set 2 paper. Find more GATE CSE PYQs on Shortest Paths in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 4 related Shortest Paths PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Shortest Paths in GATE CSE

Shortest Paths has 4 GATE CSE PYQs across 4 papers from 2012 to 2026. 3 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2026 Set 2.

How GATE tests Shortest Paths

More from GATE CSE 2026 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2026 Set 2 · Q37 · MCQ

Let G be a weighted directed acyclic graph with m edges and n vertices. Given G and a source vertex s in G, 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 that are reachable from s in G?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.