KickSolve • Free • Private

Perfect Binary Tree Visualizer

All internal nodes have exactly 2 children, and all leaf nodes are at the same level. Insert, delete and search with step-by-step animation.

Dashed empty slotsAdd level in one clickLive property checks

How to use the Perfect 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 goes into the next free slot in level order. Dashed circles show the empty slots still left on the last level.
Fill the level or press Add levelThe tree is perfect only when no dashed circle is left. Press Add level to fill the last level in one click, or add a whole new level when the tree is already perfect.
Run a traversalUse the traversal buttons to see preorder, inorder, postorder and level order output, and check that Perfect turns green in the property badges.

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.
Empty slots made visibleDashed circles show exactly which slots are missing before the tree becomes perfect.
Undo and experimentStep back through your last 40 changes, or generate a random tree to explore.

What you can do with the Perfect Binary Tree Visualizer

Everything this tool offers.

InsertAdd a value in the next free slot in level order.
DeleteRemove a node. The last node moves into its slot to keep the shape.
SearchScan the tree and highlight the first node that matches.
Add levelFill the last level in one click, or add a new level when the tree is already perfect.
Empty slots and indexDashed circles are empty slots on the last level. The number above each node is its array index.
PreorderRoot, then left, then right.
InorderLeft, root, right.
PostorderLeft, right, then root.
Level orderBreadth first, one level at a time.
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.
Random and UndoGenerate a random perfect tree, or step back through your changes.

About the Perfect Binary Tree Visualizer on KickSolve

What it does and how to get the best results.

What is a perfect binary tree?

A perfect binary tree is a binary tree in which every internal node has exactly two children and all leaves sit on the same level. Every level is completely full.

Key properties

  • All leaves are at the same depth
  • Every internal node has 2 children
  • A tree of height h has 2^h - 1 nodes
  • Level k contains 2^(k-1) nodes

Operations and time complexity

Height is exactly log2(n + 1). Traversal and search take O(n) here, while a root to leaf path is only O(log n) long.

Real-world uses

  • Tournament brackets
  • Ideal balanced structures
  • Analysing the best case tree height
  • Segment tree layouts

Comparing tree shapes? Try the Binary Tree, Full Binary Tree, Complete Binary Tree or Balanced Binary Tree visualizer.

Worked example: building a small perfect binary tree

The same steps the visualizer animates for any input.

Insert 1: it becomes the root.
Insert 2 and 3: level 2 is full.
Insert 4: level 3 starts. Dashed circles show 3 empty slots, so the tree is not perfect yet.
Insert 5, 6 and 7: level 3 is full, no dashed circle is left.
The tree is perfect: 7 nodes = 2^3 - 1, with 4 leaves.

Preorder:    1 2 4 5 3 6 7
Inorder:     4 2 5 1 6 3 7
Postorder:   4 5 2 6 7 3 1
Level order: 1 2 3 4 5 6 7

Press Add level after inserting 4 to fill the missing slots in one click.

Perfect 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 perfect binary tree height

A perfect tree of each height has exactly this many nodes.

HeightNodesLeavesInternal nodes
1110
2321
3743
41587
5311615
6633231
71276463
8255128127
9511256255
101023512511

Perfect Binary Tree FAQ

Quick answers.

What is a perfect binary tree?

A binary tree where every internal node has exactly two children and all leaves are on the same level. Every level is completely full.

How many nodes are in a perfect binary tree of height h?

2^h - 1 nodes, counting height in levels. Height 3 has 7 nodes and height 4 has 15.

How many leaves does a perfect binary tree have?

A perfect tree of height h has 2^(h-1) leaves and 2^(h-1) - 1 internal nodes, so more than half of the nodes are leaves.

What is the height of a perfect binary tree with n nodes?

The height is log2(n + 1) levels. A perfect tree with 15 nodes has 4 levels.

Is a perfect binary tree full and complete?

Yes. A perfect tree is both full and complete. The reverse is not true: a full or complete tree is not always perfect.

What do the dashed circles mean?

They are empty slots on the last level. The tree is perfect only when every slot is filled and no dashed circle is left.

What does Add level do?

It fills the last level with new values until the tree is perfect. If the tree is already perfect, it adds a whole new level, which doubles the leaves.

How do I add and delete nodes in the visualizer?

Insert places the value in the next free slot in level order. To delete, type the value or click a node. The last node moves into the gap, so the tree may stop being perfect until you refill it.

What is the time complexity of perfect binary tree operations?

Search and traversal take O(n) in this unordered tree. A path from the root to any leaf is only log2(n + 1) steps, so an ordered perfect tree can be searched in O(log n).

Can I undo a change?

Yes. Press Undo to step back through your last 40 changes. Clear, Random and Add level 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.