Trees

Graphs
yFiles
About the yFiles tree structure.

Some layout algorithms require your graph to be a tree and we explain in some details in this page the various concepts related to trees.

In a somewhat mathematical lingo one would define a tree a connected graph without undirected cyclic edge paths. That is, a tree is a special type of graph with the following characteristics: - It is connected, meaning there is a path between any two nodes. - It has no cycles (also known as loops), which means there are no closed paths where you can start at one node and return to it by following edges. - It is acyclic, ensuring that there are no repeated edges or loops. - It has a unique root node from which all other nodes descend. - Each node (except the root) has exactly one parent node. - Nodes can have zero or more child nodes.

Visually, you can think of a tree as something like this (check this playground):

but as soon as you add anywhere an edge this breaks the tree structure:

(check the playground )

In a tree, one speaks of a Leaf Node (or External Node) if the node has the following properties:

Sometimes one also refers to a leaf node if the graph is not a tree. In this case, it means a node with a single edge pointing towards it.

An ancestor or parent Node is defined as any node on the path from the root to a leaf node is called an ancestor of that leaf node.

The height of a Tree:

A tree level or depth is defined as follows:

In summary, levels in a tree graph help organize nodes based on their distance from the root, providing a clear hierarchy

A forest is in essence a collection of trees:


Trees are everywhere and the predictable (topological) structure of nodes in a tree make them ideal in all sorts of situations:

Hierarchical Structure:

Efficient Searching:

Sorting and Traversal:

Binary Trees:

Balanced Trees:

Decision Trees:

Spanning Trees:

Expression Trees:

Parse Trees:

Tree Traversal Algorithms:

Tree Height and Depth:

Tree Pruning: