GATE Assistant

Past questions › Computer Science and Information Technology › GATE 2025 set2

GATE 2025 set2 · CS · NAT · 2 marks · Algorithms › Graph Algorithms

GATE 2025 set2 Computer Science and Information Technology question: Consider the following algorithm someAlgo that takes an undirected graph G as input.…

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

someAlgo(G)

  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(T) for the tree shown in the given figure is ___________. (Answer in integer)

figure

Show answer

Official answer: 6

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion