Tree (graph theory)
Wednesday, May 4th, 2011A tree is in the graph theory , a special graph , with a single hierarchy can be modeled. Depending on whether the edges of the tree significant direction have one, can be graph-theoretical trees divide in undirected trees and rooted trees , and rooted trees in Out-Trees , where the edges from the root go in, and In-Trees , where edges in the direction of root showing.
In the computer science trees are often used as data structure used. In this case, but they are otherwise represented as a general graph. By removing an edge tree falls into two sub-trees and thus forms a so-called forest .
Special trees
There are a variety of terms to specify the trees closer. There are, for example
- empty trees (they do not contain nodes and edges),
- Binary trees ,
- Binomial trees ,
- balanced trees and
- complete binary trees .
Equivalent characterizations of trees
A graph G = (V, E) with | V | = n nodes and | E | = m edges can be defined as a tree equivalent to statements by the following:
- Between two nodes of G there is exactly one path.
- G is connected and it is m = n-1 . (There is always an edge is less than node.)
- G contains no cycle and we have m = n-1 .
- G is (minimally) coherent and (maximum) acyclic.
Trees as a data structure
Rooted trees, especially out-Trees are often used as a data structure. In case of restricted procedure can be implemented so that each node has a fixed set of variables or an array of references to his children contains. Often have the node and a reference to its parent node ( back pointer ). A tree of unlimited order can be implemented by dynamic arrays instead of lists used. In programming languages ​​without dynamic lists process has also proven, in which a general tree by a binary tree is implemented:
The red line marks the realized common tree while the arrows represent the actual data structures. The basic principle is that each is a pointer to the leftmost son shows, the other to the right brother refers. Here, nodes may be a direct access to individual-specific son no longer possible, since one of siblings who have to work ahead. But this implementation is very memory efficient.
Drawing trees
The graphical output of a tree is a nontrivial problem. The general rule is that every planar tree, ie, drawn without overlapping the edges. Depending on the application, there are more requests to the kind of output:
- all edges are straight lines
- all nodes have integer coordinates
- the smallest possible footprint with possible aesthetic result
- all edges from father to child is strictly monotonic decreasing
There are several algorithms whose results look quite different. They usually only solve some but not all wishes to the output. Known algorithms are the HV-trees (horizontal-vertical) and the algorithm of Walker .
Number of trees
There are n n – 2 different labeled trees with n nodes. This statement is a set of Cayley known.