Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

A tree on vertices 0 to 11 has the edges 1-0, 2-0, 3-0, 4-2, 5-2, 6-3, 7-0, 8-3, 9-3, 10-0, 11-6. What is its diameter, meaning the largest number of edges on any path between two vertices?

  1. A. 3
  2. B. 8
  3. C. 5
  4. D. 6

Correct answer: C. 5

The diameter is found by two BFS passes: from any vertex to a farthest vertex, then from that vertex. It is an edge count; the eccentricity of one fixed vertex, or the vertex count of the path, is a different number.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic