GATE Computer ScienceVery hardGATE CS

An undirected graph on vertices 0 to 7 has the edges 0-1, 0-2, 0-3, 1-2, 1-4, 2-3, 2-5, 3-4, 3-5, 4-5, 4-6, 5-6, 5-7, 6-7. Let A be its adjacency matrix. How many triangles does the graph contain?

  1. A. 12
  2. B. 8
  3. C. 6
  4. D. 36

Correct answer: C. 6

The diagonal entries of A³ count closed walks of length 3, and each triangle gives 6 of them (3 start vertices × 2 directions). Here trace(A³) = 36, so there are 36/6 = 6 triangles: 012, 023, 235, 345, 456 and 567.

More Programming and Data Structures (GATE) questions

Exams that ask this topic