Data Structures & AlgorithmsVery hardICPC regional · GATE CS

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

Correct answer: C. 8 6 4 9 5 7 5 8 7 4

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