A complete binary tree is a binary tree where nodes are filled in from left to right.
In a complete binary tree:
- Every level except the last one is full.
- The last level's nodes are as far left as possible.
Properties
The number of nodes on each horizontal "level" of the tree is twice as much as the level above it:
When every level in the tree is full, about half of the total number of nodes in the tree are in the last level (16 out of 31 total in the example above). A quarter of the nodes are in the second-to-last level, an eighth of the nodes are in the level above that, and so on.
Interview coming up?
Get the free 7-day email crash course. You'll learn how to think algorithmically, so you can break down tricky coding interview questions.
No prior computer science training necessary—we'll get you up to speed quickly, skipping all the overly academic stuff.
No spam. One-click unsubscribe whenever.
You're in! Head over to your email inbox right now to read day one!