Consider an n-vertex tree which has its
vertices labelled as 0, 1, 2, ..., n-1.
The Prufer code for this tree can be computed as follows:
Repeat n-2 times:
The sequence of n-2 numbers produced is the Prufer code for the labelled tree.
Given a sequence of n-2 integers in the range 0, 1, ..., n-1, the tree which corresponds to this Prufer code can be reconstructed by the following algorithm:
Set used[i] = false for i= 0, 1, ..., n-1.
Set count[i] to be the number of occurrences of i in the Prufer code sequence.
While the Prufer code is not empty do: