KickSolve • Free • Private

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.

Array index on every nodeAll four traversalsLive property checks

How to use the Complete Binary Tree Visualizer on KickSolve

Three quick steps, no account needed.

Type a valueEnter a number or short word in the Value box and press Insert. It always goes into the next free slot in level order, so the tree stays complete.
Press Insert, Delete or SearchWatch the animation. Orange is a new node, red is being deleted and green is found. To delete, type the value or click a node first. The last node moves into the gap.
Run a traversalUse the traversal buttons to see preorder, inorder, postorder and level order output. The small number above each node is its array index, and Complete should stay green.

Why choose KickSolve

Built for learning, speed and privacy.

Private by designEverything runs in your browser. Nothing you type is ever sent anywhere.
Animated, step by stepWatch every visit and placement as it happens, at a speed you choose.
Array index viewSee the array index on every node and how a complete tree maps to a plain array.
Undo and experimentStep back through your last 40 changes, or generate a random tree to explore.

What you can do with the Complete Binary Tree Visualizer

Everything this tool offers.

InsertAdd a value in the next free slot in level order. The tree always stays complete.
DeleteRemove a node. The last node moves into its slot to keep the shape.
SearchScan the tree and highlight the first node that matches.
Array indexThe small number above every node is its position in the array. Children of i sit at 2i + 1 and 2i + 2.
PreorderRoot, then left, then right.
InorderLeft, root, right.
PostorderLeft, right, then root.
Level orderBreadth first. For a complete tree this is the same as array order.
Property checksBadges show whether the tree is full, complete, perfect, balanced and ordered.
Copy and downloadCopy the tree as an image or save it as a PNG for notes and slides.
Click to selectClick any node to pick it for delete.
Random and UndoGenerate a random complete tree, or step back through your changes.

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.

TraversalOrderTypical use
PreorderRoot, left, rightCopying a tree, prefix expressions
InorderLeft, root, rightSorted output from a binary search tree
PostorderLeft, right, rootDeleting a tree, postfix expressions
Level orderLevel by level, left to rightShortest path, printing by depth

Types of binary trees

The shapes the property badges check for.

TypeRule
FullEvery node has 0 or exactly 2 children
CompleteAll levels filled except the last, which fills from the left
PerfectAll internal nodes have 2 children and all leaves share one level
BalancedLeft and right heights differ by at most 1 at every node
Binary search treeLeft 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.

HeightMinimum nodesMaximum nodes
111
223
347
4815
51631
63263
764127
8128255
9256511
105121023

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.