Complete Binary Tree Visualizer
All levels are completely filled except possibly the last, which fills from left to right. Insert, delete and search with step-by-step animation.
How to use the Complete Binary Tree Visualizer on KickSolve
Three quick steps, no account needed.
Why choose KickSolve
Built for learning, speed and privacy.
What you can do with the Complete Binary Tree Visualizer
Everything this tool offers.
About the Complete Binary Tree Visualizer on KickSolve
What it does and how to get the best results.
What is a complete binary tree?
A complete binary tree has every level completely filled except possibly the last, and the last level is filled from left to right with no gaps. Because of this shape it can be stored in a plain array.
Key properties
- All levels are full except maybe the last
- The last level is filled from the left
- Array storage: children of index i are 2i + 1 and 2i + 2
- A tree with n nodes has floor(log2 n) + 1 levels
Operations and time complexity
Insert at the next slot is O(1). Search and traversal are O(n). Height stays O(log n), so heap style operations are O(log n).
Real-world uses
- Binary heaps and priority queues
- Heap sort
- Array based tree storage
- Scheduling structures
Comparing tree shapes? Try the Binary Tree, Full Binary Tree, Perfect Binary Tree or Balanced Binary Tree visualizer.
Worked example: building a small complete binary tree
The same steps the visualizer animates for any input.
Insert 1, 2, 3, 4, 5: each goes into the next free slot. Array: [1, 2, 3, 4, 5] (indexes 0 to 4) Children of index 1 (value 2) are indexes 3 and 4 (values 4 and 5). Delete 2: the last node (5) moves into index 1. Array: [1, 5, 3, 4] The tree is still complete. Before the delete: Preorder: 1 2 4 5 3 Inorder: 4 2 5 1 3 Postorder: 4 5 2 3 1 Level order: 1 2 3 4 5
Level order always matches the array order in a complete tree.
Complete Binary Tree traversals compared
When each node is visited relative to its children.
| Traversal | Order | Typical use |
|---|---|---|
| Preorder | Root, left, right | Copying a tree, prefix expressions |
| Inorder | Left, root, right | Sorted output from a binary search tree |
| Postorder | Left, right, root | Deleting a tree, postfix expressions |
| Level order | Level by level, left to right | Shortest path, printing by depth |
Types of binary trees
The shapes the property badges check for.
| Type | Rule |
|---|---|
| Full | Every node has 0 or exactly 2 children |
| Complete | All levels filled except the last, which fills from the left |
| Perfect | All internal nodes have 2 children and all leaves share one level |
| Balanced | Left and right heights differ by at most 1 at every node |
| Binary search tree | Left values are smaller and right values are larger |
Nodes per complete binary tree height
The fewest and most nodes a complete binary tree of each height can hold.
| Height | Minimum nodes | Maximum nodes |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 2 | 3 |
| 3 | 4 | 7 |
| 4 | 8 | 15 |
| 5 | 16 | 31 |
| 6 | 32 | 63 |
| 7 | 64 | 127 |
| 8 | 128 | 255 |
| 9 | 256 | 511 |
| 10 | 512 | 1023 |
Complete Binary Tree FAQ
Quick answers.
What is a complete binary tree?
A binary tree where all levels are full except possibly the last, which is filled from left to right with no gaps.
Why are complete binary trees stored in arrays?
There are no gaps, so a node's children and parent can be found with simple index arithmetic. No pointers are needed.
How do I find the children and parent of a node in the array?
With a 0-based index i, the children are at 2i + 1 and 2i + 2, and the parent is at floor((i - 1) / 2). The small number above each node in the visualizer is its index.
Is a heap a complete binary tree?
Yes. A binary heap is a complete binary tree that also follows the heap order rule, so it fits neatly in an array.
Is every complete binary tree full?
No. A complete tree can have one node with a single left child at the end of the last level. A full tree allows no node with exactly one child.
What is the difference between a complete and a perfect binary tree?
In a perfect tree every level is completely filled. In a complete tree the last level may be partly filled, as long as it fills from the left.
How tall is a complete binary tree with n nodes?
It has floor(log2 n) + 1 levels, so the height always grows logarithmically.
How do I add and delete nodes in the visualizer?
Insert always places the value in the next free slot in level order, so the tree stays complete. To delete, type the value or click a node. The last node moves into the gap to keep the shape.
What is the time complexity of complete binary tree operations?
Insert at the next slot is O(1). Search and traversal are O(n). Height stays O(log n), so heap style operations are O(log n).
Can I undo a change?
Yes. Press Undo to step back through your last 40 changes. Clear and Random can also be undone.
Is the visualizer free and private?
Yes. It is free with no signup, and everything runs in your browser. Nothing you type is sent to a server.
More free tools from KickSolve
Other tree visualizers.