Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time of Depth First Search on G, when G is represented as an adjacency matrix?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2014 Set 1 · Q11
Time
Select one answerSingle correct
Solution
Official answer: C) (n2)
Graph TraversalsWhen a graph with vertices and edges is represented using an adjacency matrix:
DFS visits every vertex at most once.
To find all neighbors (adjacent vertices) of any vertex , DFS must scan the entire row corresponding to in the adjacency matrix, which takes time per vertex.
Since there are vertices, the total time required to inspect all adjacent vertices is:
Hence, the tightest bound on the running time of DFS using an adjacency matrix representation is , making (C) the correct option.
Try the question first, then check your work.
Examiner trap
Think about how long it takes to find all adjacent neighbors of a single vertex in an matrix.
This Graph Traversals previous year question is Q11 of the GATE CSE 2014 Set 1 paper. Find more GATE CSE PYQs on Graph Traversals in Algorithms, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Graph Traversals PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Graph Traversals has 16 GATE CSE PYQs across 12 papers from 2014 to 2026. 5 of them are 1-mark MCQs like this one, and GATE CSE 2014 Set 1 has 3.
How GATE tests Graph TraversalsIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.