NAT · 2 marks · Graph Algorithms

GATE CS 2025 CS-2 — Q59

Consider the following algorithm someAlgo that takes an undirected graph GG as input.

someAlgo(GG)
1. Let vv be any vertex in GG. Run BFS on GG starting at vv. Let uu be a vertex in GG at maximum distance from vv as given by the BFS.
2. Run BFS on GG again with uu as the starting vertex. Let zz be the vertex at maximum distance from uu as given by the BFS.
3. Output the distance between uu and zz in GG.

The output of someAlgo(TT) for the tree shown in the given figure is ___________. (Answer in integer)
Question figure