Data Structures & AlgorithmsVery hardICPC regional · GATE CS

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

Correct answer: C. 6 3 5 10 9 12 11 1 4 3

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