Consider the following algorithm someAlgo that takes an undirected graph 𝐺 as…
GATE · 2025 · CS · Set 2 · Computer Science & IT
Consider the following algorithm someAlgo that takes an undirected graph 𝐺 as input.
someAlgo(𝐺)
1. Let 𝑣 be any vertex in 𝐺. Run BFS on 𝐺 starting at 𝑣. Let 𝑢 be a vertex in 𝐺 at maximum distance from 𝑣 as given by the BFS.
2. Run BFS on 𝐺 again with 𝑢 as the starting vertex. Let 𝑧 be the vertex at maximum distance from 𝑢 as given by the BFS.
3. Output the distance between 𝑢 and 𝑧 in 𝐺.
The output of someAlgo(𝑇) for the tree shown in the given figure is ___________. (Answer in integer)

Attempted by 113 students.
Sign up free to check your answer
Sign up freeLoading lesson…