Data Structures & AlgorithmsModerateICPC regional · GATE CS

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

Correct answer: C. 4 6 1 1 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