Tree Components
- Identify the various components of a rooted tree structure.
In the tree structure below, each circle that contains a value is called a node.
The first node from where the tree originates is called the root node.
The tree creates a hierarchical structure where except for the root node, every other node has a parent and zero or more children.
The nodes with no children are called leaves.
Exercise Given the tree structure above, complete the table below:
Answer | |
---|---|
The root is | |
The leaves are | |
The parent of node with value $21$ is | |
The children of node with value $5$ are |
Solution
Answer | |
---|---|
The root is | $9$ |
The leaves are | $4, 8, 14, 20, 25$ |
The parent of node with value $21$ is | $17$ |
The children of node with value $5$ are | $2, 7$ |
The nodes which belong to the same "parent" are called siblings!
The parent-child relationship between nodes can be extended to ancestors and descendants.
For example,
- The nodes $21$, $17$, and $9$ are ancestors of $25$.
- The nodes $2$, $7$, $4$, and $8$ are descendants of $5$.
The root is an ancestor of every node in a tree, and every node is a descendant of the root.
Resources
- Wikipedia's entry on Tree (data structure), Terminology.