139 views
2 votes
2 votes

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$? (Mark all the correct options)

  1. $\Theta(m+n)$ if $G$ is represented using adjacency matrix
  2. $\Theta(m+n)$ if $G$ is represented using adjacency list
  3. $\Theta(n^2)$ if $G$ is represented using adjacency matrix
  4. $\Theta(n^2)$ if $G$ is represented using adjacency list

1 Answer

Best answer
2 votes
2 votes
In a graph with $n$ vertices and $m$ edges, DFS has the best case time complexity of $\Theta(m+n)$ when the graph is represented in Adjacency List format. With Adjacency Matrix, the time complexity will become $\Theta(n^2).$ So, options B and C are correct.
selected by
Answer:

Related questions

3 votes
3 votes
1 answer
3
gatecse asked Sep 7, 2020
170 views
Given any two vertices in an undirected finite graph, which of the two graph traversal algorithms BFS and DFS can be used to find if there is path between them?Only B...