Skip to content
Related Articles

Related Articles

Improve Article

GATE | GATE-CS-2014-(Set-1) | Question 20

  • Last Updated : 28 Jun, 2021
Geek Week

Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time on Depth First Search of G? Assume that the graph is represented using adjacency matrix.
(A) O(n)
(B) O(m+n)
(C) O(n2)
(D) O(mn)


Answer: (C)

Explanation: Depth First Search of a graph takes O(m+n) time when the graph is represented using adjacency list.

In adjacency matrix representation, graph is represented as an “n x n” matrix. To do DFS, for every vertex, we traverse the row corresponding to that vertex to find all adjacent vertices (In adjacency list representation we traverse only the adjacent vertices of the vertex). Therefore time complexity becomes O(n2)

Quiz of this Question

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :