A tree is a connected, undirected graph with no cycles. Unlike a general graph, a tree has no loops — there is exactly one path between any two vertices.
A rooted tree is a tree in which one vertex is designated the root. This creates a hierarchy:
- The root has no parent
- Every other node has exactly one parent
- Nodes with no children are called leaves
A binary tree is a rooted tree in which every node has at most two children, referred to as the left child and right child.
A tree does not have to have a root — but a rooted tree does. A binary tree is always rooted.
The most practically important application of a binary tree is the binary search tree (BST). A BST is a binary tree with an ordering property that makes efficient searching possible:
BST ordering property: for every node, all values in its left subtree are less than the node's value, and all values in its right subtree are greater than the node's value.
This property holds at every node in the tree, not just at the root.