Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
A tree on vertices 0 to 9 has the edges 1-0, 2-0, 3-1, 4-1, 5-4, 6-5, 7-6, 8-0, 9-7. What is its diameter, meaning the largest number of edges on any path between two vertices?
- A. 7
- B. 4
- C. 3
- D. 8
Correct answer: A. 7
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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A tree on vertices 0 to 9 has the edges 1-0, 2-0, 3-0, 4-0, 5-4, 6-2, 7-4, 8-5, 9-2. What is its diameter, meaning the largest number of…
- A tree on vertices 0 to 9 has the edges 1-0, 2-1, 3-0, 4-2, 5-4, 6-2, 7-5, 8-5, 9-1. What is its diameter, meaning the largest number of…
- A tree on vertices 0 to 9 has the edges 1-0, 2-0, 3-2, 4-0, 5-1, 6-1, 7-2, 8-5, 9-8. What is its diameter, meaning the largest number of…
- A tree on vertices 0 to 8 has the edges 1-0, 2-0, 3-2, 4-0, 5-1, 6-1, 7-6, 8-5. What is its diameter, meaning the largest number of edges…
- A tree on vertices 0 to 11 has the edges 1-0, 2-0, 3-0, 4-0, 5-3, 6-4, 7-0, 8-7, 9-8, 10-5, 11-10. What is its diameter, meaning the…
- A tree on vertices 0 to 9 has the edges 1-0, 2-0, 3-1, 4-2, 5-2, 6-4, 7-0, 8-2, 9-8. What is its diameter, meaning the largest number of…