Complete Binary Tree

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.
A binary tree where every level except the last is completely filled and each node has either 0 or 2 children.


The number of nodes on each horizontal "level" of the tree is twice as much as the level above it:

A binary tree with 5 rows of nodes. The root node is on top, and every node has 2 children in the row below. Each row is labelled with the number of nodes in the row, which doubles from the top down: 1, 2, 4, 8, 16.

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.

What's next?

If you're ready to start applying these concepts to some problems, check out our mock coding interview questions.

They mimic a real interview by offering hints when you're stuck or you're missing an optimization.

Try some questions now

. . .