Introduction
Explore the basics of binary trees by understanding their structure, types of nodes, and key properties such as height and node relationships. This lesson lays the foundation for using binary trees effectively in competitive programming challenges.
We'll cover the following...
We'll cover the following...
Vocabulary
A binary tree is a hierarchical data structure.
- The topmost node is called the root.
- Each node can have up to two children, hence the name Binary tree.
- The two children of a node are the left and right children.
- The node above a node is called its parent. Root has no parent.
- Nodes with no children are called leaves or external nodes.
- Non-Leaf nodes are called internal nodes.
- The number of levels is the height of the tree.
- Siblings: Nodes with the same parent.
- Descendant: Node reachable by traversing children (Nodes in the Subtree).
- Ancestor: Nodes reachable by traversing parents (Nodes on the path from the node to root).
Node structure
Each node needs two pointers along with a value. The structure would look something like this.
Properties
- The maximum possible nodes at level