GATE / CS ARCHIVE

GATE CSE 2014 SET 1 / QUESTION 11

GATE CSE 2014 Set 1 Q11

Algorithms · Graph Algorithms · Full GATE CSE 2014 Set 1 paper

GATE 2014 Set 1, Q11 1 mark · MCQ
Report issue

Graph Algorithms

Question 11, GATE 2014: A graph has n vertices and m edges and is stored as an adjacency matrix. What is the tightest asymptotic upper bound for a complete depth-first search? A: Θ(n). B: Θ(n+m). C: Θ(n²). D: Θ(m²).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Method and setup. For adjacency lists, examining neighbors costs the degree of the current vertex. With a matrix, locating all neighbors requires inspecting n possible entries even for a low-degree vertex. A full DFS forest covers disconnected components too, so all n rows are scanned.

2. Work through the result and its assumptions. DFS scans an entire adjacency-matrix row for each visited vertex. A full traversal visits all n vertices, giving n rows of n entries and Θ(n²) time, C.

Original paper, page 10 · Answer key