A binary tree is the most important kind of tree in computing. Each node has at most two children, called left and right, which makes it ideal for yes/no decisions, comparisons and two-operand expressions.
Definition
Two consequences of this definition:
A binary tree may be empty, unlike a general tree.
Left and right are different: a root with only a left child and a root with only a right child are two different binary trees.
Special binary trees
Name
Meaning
Example (nodes)
Strictly binary (full, in many books)
Every node has 0 or 2 children
Expression trees
Perfect (called “full” in the study material)
All levels completely filled: 2h−1 nodes for height h
1, 3, 7, 15, … nodes
Complete
All levels full except possibly the last, which is filled from the left
Used by heaps (Unit 9)
Skewed
Every node has only a left (or only a right) child
Behaves like a linked list
Properties
For a binary tree with n nodes and height h (number of levels):
It has exactly n−1 edges.
Level ℓ has at most 2ℓ−1 nodes.
It has at most 2h−1 nodes.
Its height satisfies ⌈log2(n+1)⌉≤h≤n: at least the height of a perfect tree with n nodes, at most n for a skewed tree.
If n0 is the number of leaves and n2 the number of nodes with two children, then n0=n2+1.
It has exactly n+1NULL links.
Proof. Let n1 be the number of nodes with one child. Counting nodes: n=n0+n1+n2. Counting edges by children: n−1=n1+2n2. Subtracting the second equation from the first gives 1=n0−n2. ∎
Key takeaways
Binary tree: empty, or root + left binary subtree + right binary subtree; left and right are distinct.
Perfect: 2h−1 nodes; complete: last level filled from the left; strict: 0 or 2 children.
⌈log2(n+1)⌉≤h≤n; at most 2ℓ−1 nodes on level ℓ.
n0=n2+1; a binary tree with n nodes has n+1 NULL links.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Prove that a non-empty binary tree with n0 leaves and n2 nodes of degree 2 satisfies n0=n2+1.
Show worked answer
Let n1 be the number of nodes of degree 1 and n the total. Every node has degree 0, 1 or 2, so n=n0+n1+n2 (1). Every node except the root has exactly one parent edge, so the number of edges is n−1; counting edges from the parents’ side, a degree-1 node contributes 1 edge and a degree-2 node 2 edges, so n−1=n1+2n2 (2). Subtracting (2) from (1): 1=n0−n2, i.e. n0=n2+1.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-208/trees/binary-trees-and-their-properties/ to read this page.