Introduction to Trees
What is a Tree?
A tree is a non-linear hierarchical data structure consisting of nodes, with a single node as the root and zero or more child nodes. Each node (except the root) has exactly one parent.
- Root node: The topmost node.
- Leaf node: A node with no children.
- Internal node: A node with at least one child.
- Height: Number of edges on the longest path from root to a leaf.
- Depth: Number of edges from root to the node.
1
2
4
5
3
6
7
A simple binary tree visualization
Real-life analogy: Family tree, organization chart, file system directories.