Data Structures & AlgorithmsVery hardICPC regional · GATE CS
A tree on vertices 1 to 12 has the edges 2–9, 7–12, 1–7, 5–9, 11–8, 9–10, 12–2, 3–9, 6–7, 4–2, 8–9. 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.
- A. 7 9 2 9 7 12 9 8 9 2
- B. 8 9 9 7 9 2 9 2 12 7
- C. 1 3 4 5 6 7 10 11 8 9
- D. 2 9 8 9 12 7 9 2 9 7
Correct answer: A. 7 9 2 9 7 12 9 8 9 2
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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A tree on vertices 1 to 12 has the edges 2–7, 12–2, 9–8, 3–12, 7–1, 11–10, 4–1, 10–6, 5–9, 6–5, 1–6. Compute its Prüfer code: repeat 10…
- 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…
- 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…
- A binary tree has these nodes: node 1 (value -5): left 30, right 56; node 10 (value -1): left none, right none; node 20 (value 5): left…
- A binary tree has these nodes: node 3 (value -9): left 93, right 63; node 8 (value 5): left none, right 99; node 47 (value 2): left none…
- A binary tree has these nodes: node 19 (value -8): left 62, right 73; node 44 (value 3): left 56, right none; node 56 (value 7): left…