Data Structures & AlgorithmsEasyAccenture · Cognizant pattern

An undirected graph with V vertices and E edges is stored as adjacency lists. How many entries do all the lists hold in total?

  1. A. E
  2. B. 2E
  3. C. V + E
  4. D. V²

Correct answer: B. 2E

Each undirected edge u–v appears twice: v in u's list and u in v's list, so the total is 2E (the sum of degrees). The structure's overall space is O(V + E), but that counts the list headers too; V² is the adjacency-matrix size.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic