StreakPeaked· Practice

ExamsGATETechnical

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?

  1. Θ(n)
  2. Θ(n + m)
  3. Θ(n²)
  4. Θ(m²)

Correct answer: Θ(n²)

Solution

When a graph is represented as an adjacency matrix, checking for the existence of edges requires examining each entry in the n x n matrix. This results in a time complexity of Θ(n²) for Depth First Search, as every vertex and its potential connections must be considered.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →