Data Structures & AlgorithmsHardICPC regional · GATE CS
A tree on vertices 1 to 8 has the edges 2–6, 3–2, 4–7, 8–7, 5–1, 7–1, 1–2. Compute its Prüfer code: repeat 6 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 2 1 7 1 2
- B. 3 4 5 6 2 1
- C. 2 7 1 2 1 7
- D. 7 1 2 1 7 2
Correct answer: C. 2 7 1 2 1 7
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 9 has the edges 9–1, 7–1, 4–3, 1–2, 8–1, 5–2, 6–7, 3–9. Compute its Prüfer code: repeat 7 times, delete the…
- A tree on vertices 1 to 10 has the edges 4–2, 7–1, 3–9, 2–9, 1–2, 8–4, 5–2, 6–8, 9–10. Compute its Prüfer code: repeat 8 times, delete the…
- A tree on vertices 1 to 9 has the edges 7–3, 6–5, 1–4, 4–5, 3–5, 8–6, 2–9, 9–4. Compute its Prüfer code: repeat 7 times, delete the…
- A tree on vertices 1 to 9 has the edges 8–7, 5–7, 3–1, 9–3, 2–8, 4–1, 6–1, 7–1. Compute its Prüfer code: repeat 7 times, delete the…
- A tree on vertices 1 to 9 has the edges 2–9, 8–3, 1–3, 5–7, 4–9, 9–1, 6–2, 7–2. Compute its Prüfer code: repeat 7 times, delete the…
- A tree on vertices 1 to 8 has the edges 2–3, 3–4, 6–2, 8–2, 7–2, 5–4, 1–7. Compute its Prüfer code: repeat 6 times, delete the…