Data Structures & AlgorithmsVery hardICPC regional · GATE CS

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

Correct answer: B. 4 7 7 3 5 6 8 7 3 10

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