Binary tree
A structure where each element has at most 2 children, one on the left and one on the right, and all hang from a single one at the top, the root.
Example
A full binary tree of 3 levels has 1 + 2 + 4 = 7 elements; one of 20 levels, over 1 million.
Test yourself: Binary tree
Binary trees
In a binary tree, each node has at most ___ children.
Binary means 2: left and right. A node can have 0, 1 or 2 children, never 3.
Binary trees
What happens if every node in a binary tree has a single child, always on the right?
With 1,000 nodes in a single branch, the height is 999. A perfect tree with 1,023 nodes has height 9.
Binary trees
To remove P from 1 → P → 2, it's enough for 1 to point to ___.
1 change: 1 has 2 as its left child again. P is left out of the tree.
0/3
â–¶ Play