From a Sequence to a Labeled Tree
A Prüfer sequence records information about a labeled tree in a compact list. Decoding reverses the direction of the task: given the list and its label set, construct the tree’s edges. The key is to keep track of two things at once: the labels still available as vertices, and the entries still present in the sequence. At each step, the least available label that does not occur in the remaining sequence becomes a leaf. Join it to the first entry of that sequence, then remove the leaf label and that first entry.
Throughout, labels come from a finite ordered set \(L\) of \(n\geq 1\) distinct labels. In the usual convention \(L=\{1,2,\dots,n\}\), so “least” refers to the usual order on integers. A sequence for this procedure has length \(n-2\), with every entry in \(L\), when \(n\geq2\). Repetitions are allowed. The sequence of length zero is used when \(n=1\) or \(n=2\), with the two cases producing different trees.
Here “absent” means that the label does not occur anywhere in the remaining sequence. The edge list is built as the procedure runs; active labels are the vertices not yet selected as leaves. The sequence entry used as the other endpoint is always its first entry, not an arbitrary occurrence or the last entry.
The Decoding Procedure
Set the active-label set to \(L\), and set the remaining sequence to the given sequence.
Among active labels that do not occur in the remaining sequence, choose the least one, say \(x\).
If the first sequence entry is \(y\), add \(xy\), remove \(x\) from the active labels, and delete that first entry.
When exactly two active labels remain, add the edge between them. If \(n=1\), there is no edge to add.
The updates must be synchronized: each step removes one active label and one sequence entry. If there are \(r\) active labels before a step, there are \(r-2\) entries in the remaining sequence. This length relationship explains both why an absent label is available and why the procedure stops with two labels and an empty sequence.
Worked Example: A Sequence on Six Labels
Decode the sequence \((4,4,2,5)\) on \(L=\{1,2,3,4,5,6\}\). Its length is \(4=6-2\), as required. In the table, the action column records the edge added at that step.
| Active labels | Remaining sequence | Action |
|---|---|---|
| \(\{1,2,3,4,5,6\}\) | \((4,4,2,5)\) | Absent labels are \(1,3,6\); choose \(1\), add \(14\). |
| \(\{2,3,4,5,6\}\) | \((4,2,5)\) | Absent labels are \(3,6\); choose \(3\), add \(34\). |
| \(\{2,4,5,6\}\) | \((2,5)\) | Absent labels are \(4,6\); choose \(4\), add \(42\). |
| \(\{2,5,6\}\) | \((5)\) | Absent labels are \(2,6\); choose \(2\), add \(25\). |
| \(\{5,6\}\) | \(()\) | Join the final two labels; add \(56\). |
The decoded graph is \(G=(V,E)\), where \(V=\{1,2,3,4,5,6\}\) and \(E=\{14,34,24,25,56\}\). For a direct check of the edge count, the degrees are \(1,2,1,3,2,1\), respectively, so their sum is \(10\) and the handshake count gives \(|E|=10/2=5\), matching the five listed edges. The graph is connected: \(1,3,2,5,6\) are joined through vertex \(4\) and the edge \(25\), as shown by the edge list. Its shape is a tree with vertex \(4\) joined to \(1,3,2\), and the path \(2,5,6\) continuing from \(2\).
Check: each step added one edge, including the final edge, giving \(4+1=5\) edges. The degree sum independently gives \(1+2+1+3+2+1=10\), hence \(10/2=5\) edges.
Why the Procedure Always Works
Proof. First consider \(n=1\). The procedure returns one vertex and no edges, which is connected and has no cycle, so it is a tree. Now suppose \(n\geq2\). Before any iterative step, there are \(n\) active labels and \(n-2\) sequence entries. Whenever a step is performed, one active label and one sequence entry are removed. Therefore, if there are \(r\) active labels, the remaining sequence has length \(r-2\).
Suppose \(r>2\). The sequence is nonempty, so its first entry exists. Every remaining sequence entry is an active label: this holds initially because all entries lie in \(L\), and the chosen label \(x\) is absent from the remaining sequence, so removing \(x\) cannot remove a label that occurs in it. There are at most \(r-2\) distinct labels appearing in a sequence of length \(r-2\). Thus at least \(r-(r-2)=2\) active labels are absent from it. A least such label \(x\) exists because the active set is finite and ordered. If \(y\) is the first entry, then \(y\) is active and \(y\neq x\), since \(x\) is absent. So the edge \(xy\) can be added without a loop. Each step reduces \(r\) by one, and after \(n-2\) steps exactly two active labels remain; the sequence then has length zero, so the final edge is well-defined.
It remains to show that the output is a tree. At the end, the last two active labels form a tree consisting of one edge. Now read the earlier steps in reverse order. At each reversed step, restore the label \(x\) that was removed and its edge \(xy\). When that edge was originally added, \(y\) was active; hence \(y\) was either one of the final two labels or a label removed at a later step. In reverse order, all such later-removed labels have already been restored. Therefore \(y\) is already in the graph when \(x\) is restored. Adding a new vertex with exactly one edge to an existing tree preserves connectedness and creates no cycle: any route from the new vertex must use its only incident edge, so a cycle through it cannot occur. Repeating this argument restores every label and preserves the tree property. No edge is a loop, and each added edge has a newly restored endpoint, so no edge is repeated. The resulting graph is simple and is a tree on \(L\). \(\square\)
Worked Example: Repeated Entries
Decode \((2,2,2)\) on \(L=\{1,2,3,4,5\}\). The repeated entries are allowed; absence is tested by whether a label occurs at least once in the remaining sequence.
| Active labels | Remaining sequence | Action |
|---|---|---|
| \(\{1,2,3,4,5\}\) | \((2,2,2)\) | Absent labels are \(1,3,4,5\); choose \(1\), add \(12\). |
| \(\{2,3,4,5\}\) | \((2,2)\) | Absent labels are \(3,4,5\); choose \(3\), add \(32\). |
| \(\{2,4,5\}\) | \((2)\) | Absent labels are \(4,5\); choose \(4\), add \(42\). |
| \(\{2,5\}\) | \(()\) | Join the final two labels; add \(25\). |
The result has \(V=\{1,2,3,4,5\}\) and \(E=\{12,23,24,25\}\). This is the star centered at \(2\). The degrees are \(1,4,1,1,1\), so their sum is \(8\) and the degree count gives \(8/2=4\) edges, exactly the number in the edge set. Each of the four other vertices is joined directly to \(2\), so the graph is connected; with these four edges and no additional edges, it is precisely the star described.
Check: the number of listed edges is \(1+1+1+1=4\), and the degree sum independently confirms \(4=(1+4+1+1+1)/2\).
Worked Example: Labels That Are Not Consecutive
The ordering need not be written using consecutive integers. Decode \((8,11,8)\) on the ordered label set \(L=\{2,5,8,11,14\}\). The least-label rule uses the usual numerical order on this set.
| Active labels | Remaining sequence | Action |
|---|---|---|
| \(\{2,5,8,11,14\}\) | \((8,11,8)\) | Absent labels are \(2,5,14\); choose \(2\), add \(28\). |
| \(\{5,8,11,14\}\) | \((11,8)\) | Absent labels are \(5,14\); choose \(5\), add \(5\,11\). |
| \(\{8,11,14\}\) | \((8)\) | Absent labels are \(11,14\); choose \(11\), add \(11\,8\). |
| \(\{8,14\}\) | \(()\) | Join the final two labels; add \(8\,14\). |
The resulting graph has \(V=\{2,5,8,11,14\}\) and \(E=\{28,5\,11,11\,8,8\,14\}\). The edges form the path \(2,8,11,5\), together with the edge \(8\,14\). The degrees of \(2,5,8,11,14\) are \(1,1,3,2,1\); their sum is \(8\), so the degree count gives \(8/2=4\) edges, agreeing with the four listed edges. Every vertex is connected to the path or to vertex \(8\), so the output is connected.
Check: the edge list has four entries, and \(1+1+3+2+1=8\) gives \(8/2=4\) edges independently.
Small Cases and Common Mistakes
Worked Example: One or Two Labels
For \(L=\{7\}\), the sequence is empty because \(n-2=-1\) is not a usable length; the one-vertex case is defined separately and returns \(V=\{7\}\), \(E=\varnothing\). Its degree sum is \(0\), consistent with having no edges. For \(L=\{3,9\}\), the sequence has length \(2-2=0\). There are already exactly two active labels, so the procedure adds \(39\), giving \(V=\{3,9\}\), \(E=\{39\}\). Each vertex has degree \(1\), and the degree sum \(1+1=2\) confirms one edge.
Common mistake: use the original sequence to test absence. The test must use the sequence that remains after earlier entries have been deleted. For \((4,4,2,5)\), after the first step the active labels are \(\{2,3,4,5,6\}\) and the remaining sequence is \((4,2,5)\). Label \(3\) is the least active label absent from that current sequence, so the next edge is \(34\). After that step, the active labels are \(\{2,4,5,6\}\) and the sequence is \((2,5)\); now \(4\) is the least absent label, so the edge is \(42\). Using a stale absence list can instead select \(6\), which is absent but not the least currently absent label. The correction is to recompute absence at every step.
Common mistake: remove the wrong sequence entry. After selecting a leaf label, delete the first entry of the remaining sequence, because that is the label joined to the leaf. Do not delete an entry that happens to equal the leaf label: the leaf was selected precisely because it does not occur in the remaining sequence. For instance, the first step for \((4,4,2,5)\) adds \(14\) and leaves \((4,2,5)\), not \((4,2,5)\) after deleting a \(1\) (there was no \(1\) in the sequence to delete); the deleted entry is the first \(4\).
The decoder is useful because it makes a tree concrete: it turns a short list into an explicit vertex and edge set by a finite sequence of local decisions. Keeping the active labels and remaining sequence visible prevents most errors. The main checks are simple: the sequence length decreases by one at each leaf step, the active-label count decreases at the same time, and the final two active labels must be joined.
Check Your Understanding
For each question, state the active labels and remaining sequence at every decoding step.
- Decode \((3,1,3)\) on \(L=\{1,2,3,4,5\}\). Give the final edge set.
- Decode \((6,6)\) on \(L=\{2,4,6,8\}\). Which labels are selected as leaves, and what are the final two labels?
- Explain why, with \(r>2\) active labels, a remaining sequence of length \(r-2\) guarantees at least two active labels absent from it.
- Why can the first entry of the remaining sequence not equal the least active label absent from that sequence?
- In the proof that the output is a tree, explain why restoring a removed label in reverse order attaches it to a vertex already present.