GATE / CS ARCHIVE

GATE CSE 2025 SET 2 / QUESTION 59

GATE CSE 2025 Set 2 Q59

Algorithms · Graph Algorithms · Full GATE CSE 2025 Set 2 paper

GATE 2025 Set 2, Q59 2 marks · NAT
Report issue

Graph Algorithms

Question 59, GATE 2025: An algorithm runs BFS from any vertex v, picks a farthest vertex u, runs BFS from u, then reports its maximum distance d(u,z). Apply it to the unweighted tree described by these edges (labels added solely to reproduce the source figure): c–l,c–r,c–a,c–b; l–d,l–e,l–g; e–f; g–h,g–i; r–j,r–k; k–m. There are no other edges. Find the reported distance in edges.
Figure orientation: c is the central branching vertex, l its upper-left junction, r its upper-right junction; a,b are the two lower leaves. The left arms end at d,f,h,i and the right arms at j,m.
Tap to enlarge
Answer & solution

Official answer: 6

Step through it (12 steps)

The two-BFS method returns a diameter of an unweighted tree: a farthest vertex from any starting point is a diameter endpoint, and a BFS from that endpoint measures the full diameter. This exact guarantee uses the unique paths of a tree; it should not be assumed for every arbitrary graph.

Compute the diameter directly from the supplied edge list. From central vertex c, the farthest left-side leaves f,h,i are each three edges away: c–l–e–f or c–l–g–h/i. The farthest right-side leaf m is also three edges away: c–r–k–m. Joining a deepest left leaf to m therefore produces a path of length 3+3=6, for example f–e–l–c–r–k–m.

No longer path exists. A path crossing c uses at most two of its branch depths, whose two largest are 3 and 3. A path contained entirely in the left branch has at most 4 edges between f and h/i; a path within the right branch has at most 3 between j and m. The short lower branches of c cannot improve the maximum. Thus the diameter and algorithm's output are 6. The complete 14-vertex, 13-edge tree was reconstructed from the source figure.

Original paper, page 44 · Answer key