Data Structures & AlgorithmsHardICPC regional · GATE CS

A tree on vertices 1 to 9 has the edges 3–5, 7–8, 1–6, 9–6, 4–3, 2–4, 6–7, 5–9. Compute its Prüfer code: repeat 7 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. 7 6 4 3 5 9 6
  2. B. 1 2 4 3 5 8 7
  3. C. 6 7 9 5 3 4 6
  4. D. 6 4 3 5 9 7 6

Correct answer: D. 6 4 3 5 9 7 6

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