Binary Tree
Recursive Definition
Base Case: an empty tree is a binary tree; Definition: A tree having a root node, and two binary subtrees (respectively left subtree and right subtree, which can be empty) is a binary tree.
Central node
A BT's node x is said to Central when the count of its subtree's leaves is equal to the sum of the nodes' keys belonging to the
.
Full, Complete, and Perfect binary trees
Depending on how nodes are arranged in a binary tree, it can be full, complete and perfect:
- Full binary tree: each node has exactly 0 or 2 children (but never 1).
- Complete binary tree: when all levels, except the last one, are full of nodes.
- Perfect binary tree: when all the levels (including the last one) are full of nodes.
Height
The height of binary tree is
K-ary Tree
It is the generalization of a Binary Tree.
A k-ary tree is a tree where the children of a node are labeled with distinct positive integers
- No labels larger than k are present.
- A binary tree is a K-ary tree with k = 2.
Complete K-ary Tree
It is a K-ary tree where
- All the leaves have the same depth
- All the internal nodes
have .
Let us call
It can be demonstrated that for a Complete K-ary Tree:
| Tree | Count of leaves | Count of internal nodes | Height |
|---|---|---|---|
| Complete K-Ary Tree with height |
Demonstration
By definition, a complete k-ary tree has exactly
| Level | Children |
|---|---|

The root has exactly
Demonstration by induction: for a complete k-ary tree
Base case:
Inductive Hypothesis: We assume that
Inductive Step: By inductive hypothesis a tree with

Since the tree is a complete k-ary tree,
- At step
, - At step
, as each internal node at level has exactly children.
Demonstration
Given the previous result we can think of the same tree with one more level, which means this last level only has leaves.
To compute count of internal nodes we can use the geometric series
Demonstrate
We know that
Then if the we have
Extra: for a non-empty 2-ary complete tree with n nodes
Demonstration that, for a non-empty 2-ary complete tree with n nodes, the count of leaves is exactly
Induction
- Base Case:
- Only the root is present, trivially true
- Inductive Hypothesis:
- We suppose that
is true at step - We assume that
, the property is true.
- We suppose that
- Inductive step: we need to demonstrate for any
- We exclude
by definition
- We exclude
For a non-empty complete binary tree
Since the two subtrees are complete and have less nodes than
- Trivially,
- Trivially,
- Trivially
and
Balanced Binary Tree
A tree is a balanced tree if its height is:
Complete Binary Tree is balanced
A Complete Binary Tree is a Balanced Binary Tree (but the opposite is not always true)
Performances
It is important to keep binary tree's height as close to
Binary Search Tree (BST)
Binary Search Trees or BST for short are a particular application of binary trees.
BST has at most two nodes (like all binary trees). However, the values are so that the left children value must be less than the parent, and the right children must be higher.
Duplicates: Some BST doesn’t allow duplicates while others add the same values as a right child. Other implementations might keep a count on a case of duplicity (we are going to do this one later).**