Tree – definition and properties
A tree is made of a set of nodes. Each node is a data structure that contains a key value, a set of children nodes, and a link to a parent node. There is only one node that has no parent: the root of the tree. A tree structure represents data in a hierarchical form, where the root node is on top of the tree and the child nodes are below it.
The tree has some constraints: a node cannot be referenced more than once, and no nodes point to the root, so a tree never contains a cycle:
Basic tree data structure
Let's see some important terms when talking about tree data structures:
- Root: The node that is on the top of the tree and is the only node in the tree that has no parent.
- Node: A data structure that has a value key, and can contain a set of children and a reference to a parent node. If there is no reference to a parent node, the node is the root of the tree. If the node has no children, it is called a leaf.
- Edge: Represents the connection between...