Complete Binary Tree

In short: A complete binary tree is a binary tree in which every level is fully filled except possibly the last, and the last level's nodes are packed as far left as possible. This shape lets heaps be stored compactly in an array.

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.

Properties

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.

Frequently Asked Questions

What is a complete binary tree?

A binary tree where every level except possibly the last is completely filled, and all nodes in the last level are as far left as possible.

Why are complete binary trees useful?

Their predictable shape lets you store them in an array (a node at index i has children at 2i+1 and 2i+2), which is exactly how binary heaps are implemented.

What's the difference between a complete and a full binary tree?

In a complete tree every level but the last is full and the last is left-packed; in a full binary tree every node has either zero or two children.

Last updated: June 17, 2026

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

. . .