The proof follows the same reasoning as the proof of Proposition 6. First, one may remark that

because the number of subtrees of height

$h-1$ under a node

v of height

h can only decrease by the allowed deleting operations. Let

v be a node of height

h in

$\tau $ and

${\gamma}_{i}\left(v\right)$ the number of subtrees of height

i under

v. If a subtree of height

$h-i$ under

v that must be deleted is not self-nested, one can first modify it to get a self-nested tree and then remove it with the same overall cost. Thus, we can assume without loss of generality that all the subtrees under

v are self-nested.

${\Delta}_{h-1}\left(v\right)={\gamma}_{h-1}\left(v\right)-{\rho}_{\mathrm{NeST}\left(\tau \right)}(h,h-1)$ denotes the number of subtrees of height

$h-1$ that have to be removed from

v. Let

${\gamma}_{i}^{\left(j\right)}\left(v\right)$ the sequence of the modifications to obtain

${\rho}_{\mathrm{NeST}\left(\tau \right)}(h,h-1)$ subtrees of height

$h-1$ under

v, with

${\gamma}_{i}^{\left(0\right)}\left(v\right)={\gamma}_{i}\left(v\right)$. Instead of deleting a subtree of height

$h-1$, it is always less costly to decrease its height of one unit by deleting its root. However it is possible only if this internal node has only one child, i.e., if

${\rho}_{\tau}(h-1,h-2)=1$ and

${\rho}_{\tau}(h-1,i)=0$ for

$0\le i<h-2$. If this new tree of height

$h-2$ must be deleted in the sequel, it will be done with the same global cost as by directly deleting the subtree of height

$h-1$. Consequently,

From now on, the number of subtrees of height

$h-2$ under

v will thus not increase and we obtain

There are

${\Delta}_{h-2}\left(v\right)={\gamma}_{h-2}^{\left(1\right)}\left(v\right)-{\rho}_{\mathrm{NeST}\left(\tau \right)}(h,h-2)$ subtrees of height

$h-2$ to be deleted under

v. We can repeat the previous reasoning and delete the root of subtrees of height

$h-2$ if possible rather than delete the whole structure, and so on for any height. Thus, the sequence

${\gamma}_{i}^{\left(j\right)}$ is defined from

and we have

The tree returned by Algorithm 3 saturates the inequalities (

5) and (

6) for all the possible values of

h and

i. Decreasing of one unit the height profile at

$({h}_{1},{h}_{2})$ has a (strictly) positive cost. Thus, this tree is the (unique) NeST of

$\tau $. The time-complexity is given by the size of the height profile array. □