Tree (data structure)
Appearance
![](https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/Tree_%28computer_science%29.svg/220px-Tree_%28computer_science%29.svg.png)
In computer science, a tree is a graph data structure composed of items that have child items. Trees have an item called a root. No item has the root as a child. Trees may not have cycles. Items may contain a reference to their parent. An item is a leaf if it has no children. The height of an item is the length of the longest downward path to a leaf from that item. The height of the root is the height of the tree. The depth of an item is the length of the path to the tree's root, tree roots can be infinite.
Example
[change | change source]- The item labeled 2 in green text is the root.
- The item labeled 4 is a leaf and its depth is 3.
- The height of the tree is 3.