Convert-Prüfer-to-Tree(a)
1 n ← length[a]
2 T ← a graph with n + 2 isolated nodes, numbered 1 ton + 2
3 degree ← an array of integers
4 for each node i in Tdo
5 degree[i] ← 1
6 for each value i in ado
7 degree[i] ← degree[i] + 1
次に、次数 が であり、かつ最小となるような を見つけて、木に辺 を追加する操作を繰り返す。
8 for each value i in ado
9 for each node j in Tdo
10 ifdegree[j] = 1 then
11 Insert edge[i, j] into T
12 degree[i] ← degree[i] - 1
13 degree[j] ← degree[j] - 1
14 break
15 u ← v ← 0
16 for each node i in T
17 ifdegree[i] = 1 then
18 ifu = 0 then
19 u ← i
20 else
21 v ← i
22 break
23 Insert edge[u, v] into T
24 degree[u] ← degree[u] - 1
25 degree[v] ← degree[v] - 1
26 returnT