# Nearest Embedded and Embedding Self-Nested Trees

## Abstract

**:**

## 1. Introduction

`Python`library

`treex`[9].

## 2. Preliminaries

#### 2.1. Unordered Rooted Trees

#### 2.2. DAG Compression

#### 2.3. Self-Nested Trees

**Proposition**

**1**

**.**A tree τ is self-nested if and only if its reduction $\mathcal{R}\left(\tau \right)$ is a linear DAG.

## 3. Height Profile of the Tree Structure

#### 3.1. Definition and Complexity

**Proposition**

**2.**

**Proof.**

#### 3.2. Relation with Self-Nested Trees

**Proposition**

**3.**

**Proof.**

**Lemma**

**1.**

Algorithm 1: Construction of a self-nested tree from its height profile. |

**Proposition**

**4.**

**Proof.**

## 4. Approximation Algorithms

#### 4.1. Definitions

#### 4.1.1. Editing Operations

#### 4.1.2. Constrained Editing Operations

**Lemma**

**2.**

**Proof.**

#### 4.1.3. Preserving the Height of the Pre-Existing Nodes

**Lemma**

**3.**

**Proof.**

**Lemma**

**4.**

**Proof.**

**Lemma**

**5.**

**Proof.**

**Lemma**

**6.**

**Proof.**

#### 4.1.4. NEST and NeST

- Internal nodes (AI): adding w as a child of v making w the parent of the child c of v can be done only if $\mathcal{H}\left(\tau \right[c\left]\right)+1<\mathcal{H}\left(\tau \right[v\left]\right)$.
- Subtrees (AS): adding t as a child of v can be done only if $\mathcal{H}\left(t\right)+1\le \mathcal{H}\left(\tau \right[v\left]\right)$.

- Internal nodes (DI): deleting $v\in {\mathcal{C}}_{\tau}\left(u\right)$ (making the unique child w of v a child of u) can be done only if there exists ${v}^{\prime}\in {\mathcal{C}}_{\tau}\left(u\right)$, $v\ne {v}^{\prime}$, such that $\mathcal{H}\left(\tau \left[{v}^{\prime}\right]\right)\ge \mathcal{H}\left(\tau \left[v\right]\right)$.
- Subtrees (DS): deleting the subtree $\tau \left[w\right]$, $w\in {\mathcal{C}}_{\tau}\left(v\right)$, of $\tau $ can be done if there exists ${w}^{\prime}\in {\mathcal{C}}_{\tau}\left(v\right)$, ${w}^{\prime}\ne w$, such that $\mathcal{H}\left(\tau \left[{w}^{\prime}\right]\right)+1=\mathcal{H}\left(\tau \left[v\right]\right)$.

**Proposition**

**5.**

**Proof.**

#### 4.2. NEST Algorithm

Algorithm 2: Construction of the nearest embedding self-nested tree. |

**Proposition**

**6.**

**Proof.**

#### 4.3. NeST Algorithm

Algorithm 3: Construction of the nearest embedded self-nested tree. |

**Proposition**

**7.**

**Proof.**

## 5. Numerical Illustration

#### 5.1. Random Trees

#### 5.2. Structural Analysis of a Rice Panicle

## 6. Summary and Concluding Remarks

`Python`library

`treex`[9].

## Funding

## Acknowledgments

## Conflicts of Interest

## References

- Bille, P.; Gørtz, I.L.; Landau, G.M.; Weimann, O. Tree compression with top trees. Inf. Comput.
**2015**, 243, 166–177. [Google Scholar] [CrossRef] [Green Version] - Bousquet-Mélou, M.; Lohrey, M.; Maneth, S.; Noeth, E. XML Compression via Directed Acyclic Graphs. Theory Comput. Syst.
**2014**, 57, 1322–1371. [Google Scholar] [CrossRef] [Green Version] - Buneman, P.; Grohe, M.; Koch, C. Path Queries on Compressed XML. In Proceedings of the 29th International Conference on Very Large Data Bases, VLDB’03, Berlin, Germany, 9–12 September 2003; Volume 29, pp. 141–152. [Google Scholar]
- Frick, M.; Grohe, M.; Koch, C. Query evaluation on compressed trees. In Proceedings of the 18th Annual IEEE Symposium of Logic in Computer Science, Ottawa, ON, Canada, 22–25 June 2003; pp. 188–197. [Google Scholar]
- Godin, C.; Ferraro, P. Quantifying the degree of self-nestedness of trees. Application to the structural analysis of plants. IEEE Trans. Comput. Biol. Bioinform.
**2010**, 7, 688–703. [Google Scholar] [CrossRef] [PubMed] - Busatto, G.; Lohrey, M.; Maneth, S. Efficient Memory Representation of XML Document Trees. Inf. Syst.
**2008**, 33, 456–474. [Google Scholar] [CrossRef] - Lohrey, M.; Maneth, S. The Complexity of Tree Automata and XPath on Grammar-compressed Trees. Theor. Comput. Sci.
**2006**, 363, 196–210. [Google Scholar] [CrossRef] - Greenlaw, R. Subtree Isomorphism is in DLOG for Nested Trees. Int. J. Found. Comput. Sci.
**1996**, 7, 161–167. [Google Scholar] [CrossRef] - Azaïs, R.; Cerutti, G.; Gemmerlé, D.; Ingels, F. treex: A Python package for manipulating rooted trees. J. Open Source Softw.
**2019**, 4, 1351. [Google Scholar] [CrossRef] - Aho, A.V.; Hopcroft, J.E.; Ullman, J.D. The Design and Analysis of Computer Algorithms, 1st ed.; Addison-Wesley Longman Publishing Co., Inc.: Boston, MA, USA, 1974. [Google Scholar]
- Zhang, K. A constrained edit distance between unordered labeled trees. Algorithmica
**1996**, 15, 205–222. [Google Scholar] [CrossRef]

**Figure 1.**Trees and their DAG (Directed Acyclic Graph) reduction. In the tree, roots of isomorphic subtrees are colored identically. In the DAG, vertices are equivalence classes colored according to the class of isomorphic subtrees that they represent.

**Figure 2.**A tree $\tau $ (

**middle**) with 30 nodes and its approximations $\mathrm{NeST}\left(\tau \right)$ (

**left**) with 24 nodes and $\mathrm{NEST}\left(\tau \right)$ (

**right**) with 37 nodes.

**Figure 5.**The tree $\theta $ is obtained from $\tau $ by inserting an internal node. The associated mapping does not satisfy the conditions imposed by Zhang [11] because the LCA (Least Common Ancestor) of ${v}_{1}$ and ${v}_{2}$ is a proper ancestor of ${v}_{3}$ whereas the LCA of ${w}_{1}$ and ${w}_{2}$ is not a proper ancestor of ${w}_{3}$.

**Figure 6.**Adding a node as new child of w making all the current children of w children of this new node (

**top**) provides the same topology as adding a new node between v and its child w (

**bottom**).

**Figure 9.**Number of nodes of the NEST (

**left**) and of the NeST (

**right**) estimated from 3000 random trees: average (full lines) and first and third quartiles (dashed lines).

**Figure 10.**Average running time required to compute the NEST (dashed line) or the NeST (full line) estimated from 3000 simulated trees.

**Figure 11.**The rice panicle is composed of a main axis and lateral systems ${V}_{i}$, each made of one or several inflorescences ${P}_{j}$.

**Figure 12.**Degree of self-nestedness measured by ${\delta}_{\mathrm{NEST}}\vee 0$ (dashed lines) and ${\delta}_{\mathrm{NeST}}$ (full lines) of the different substructures appearing in the rice panicle.

**Figure 13.**Progress of Algorithm 2 to compute the NEST of the left tree from its height profile. Only the second line must be edited to get the correct output. Editions of the height profile are associated with addition of vertices in red. The output tree is self-nested and has been constructed by adding a minimal number of nodes to the initial tree.

**Figure 14.**Progress of Algorithm 3 to compute the NeST of the left tree from its height profile. Only the second line must be edited to get the correct output. Editions of the height profile are associated with deletion of vertices in dashed lines. The output tree is self-nested and has been constructed by removing a minimal number of nodes from the initial tree.

© 2019 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Azaïs, R.
Nearest Embedded and Embedding Self-Nested Trees. *Algorithms* **2019**, *12*, 180.
https://doi.org/10.3390/a12090180

**AMA Style**

Azaïs R.
Nearest Embedded and Embedding Self-Nested Trees. *Algorithms*. 2019; 12(9):180.
https://doi.org/10.3390/a12090180

**Chicago/Turabian Style**

Azaïs, Romain.
2019. "Nearest Embedded and Embedding Self-Nested Trees" *Algorithms* 12, no. 9: 180.
https://doi.org/10.3390/a12090180