Develop an algorithm for reconstructing a tree from a given
Develop an algorithm for reconstructing a tree from a given Prüfer Code: a1,a2, ... , an-2
Solution
Algorithm: Pr¨ufer’s code
Input: A tree T with vertex set S N where |S| 2.
Output: A sequence f(T) = (a1 , a2, . . . , a|S|2 ) S |S|2
let T1 = T
for each i = 1 to |S| 2 do
let v be the leaf of Ti with smallest label
set ai to be the unique neighbour of v in T
construct Ti+1 from Ti by removing the vertex v and the edge {v, ai}
end for
