Data Structures & AlgorithmsVery hardICPC regional · GATE CS

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

Correct answer: D. 2 3 2 12 3 3 9 12 5 12

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