GATE CS 2025, set 2 · Question 59 · Algorithms · Numerical answer (NAT) · 2 marks · no negative marks

Consider the following algorithm someAlgo that takes an undirected graph G as input.
someAlgo(G) 1. Let v be any vertex in G. Run BFS on G starting at v. Let u be a vertex in G at maximum distance from v as given by the BFS. 2. Run BFS on G again with u as the starting vertex. Let z be the vertex at maximum distance from u as given by the BFS. 3. Output the distance between u and z in G.
The output of someAlgo(T) for the tree shown in the given figure is ______. (Answer in integer)

An unlabeled tree T with 14 vertices and 13 edges. Call the vertices A to N. Hub vertex E has neighbours B (a leaf), C, F and H. C has two further leaf neighbours, A and D. F has one further leaf neighbour, G. H has neighbours E, I (a leaf), J (a leaf) and K. K has neighbours H, L (a leaf) and M. M is connected to N (a leaf). Edges: A-C, C-D, C-E, B-E, E-F, F-G, E-H, H-I, H-J, H-K, K-L, K-M, M-N. The longest paths are G-F-E-H-K-M-N and A-C-E-H-K-M-N, each with 6 edges.
Answer

Answer 6

Answer from the official GATE CS 2025 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes