Data Structures & AlgorithmsEasyTCS NQT · Infosys pattern

What is the space needed by the adjacency-matrix representation of a graph with V vertices and E edges?

  1. A. O(V²)
  2. B. O(E log V)
  3. C. O(E)
  4. D. O(V + E)

Correct answer: A. O(V²)

The matrix has a V × V entry for every possible pair, whatever the number of edges, so O(V²). O(V + E) is the adjacency-list figure.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic