Data Structures & AlgorithmsModerateICPC regional · GATE CS

A tree on vertices 1 to 6 has the edges 6–2, 4–6, 2–3, 3–5, 1–2. Compute its Prüfer code: repeat 4 times, delete the smallest-labelled leaf and write down the label of its neighbour. Give the code as the written numbers in order.

  1. A. 3 6 2 2
  2. B. 2 6 3 2
  3. C. 1 4 5 3
  4. D. 2 3 6 2

Correct answer: B. 2 6 3 2

Each step removes the smallest current leaf and records its unique neighbour; the trap answers come from removing the largest leaf, recording the leaf instead, or reversing the list.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic