Binary Tree Visualizer
A tree in which each node can have at most 2 children (left and right). Insert, delete, edit and search with step-by-step animation.
How to use the 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 Binary Tree Visualizer
Everything this tool offers.
About the Binary Tree Visualizer on KickSolve
What it does and how to get the best results.
What is a binary tree?
A binary tree is a tree data structure in which every node has at most two children, called the left child and the right child. It is the base for binary search trees, heaps and expression trees.
Key properties
- Each node has 0, 1 or 2 children
- Children are named left and right
- Height can range from log n to n
- Supports preorder, inorder, postorder and level order traversal
Operations and time complexity
Traversal and search take O(n) because a plain binary tree has no ordering. Insert at the first free slot and delete using the deepest node are O(n) to locate.
Real-world uses
- Expression parsing
- Binary search trees and heaps
- Decision trees
- Huffman coding
Comparing tree shapes? Try the Full Binary Tree, Complete Binary Tree, Perfect Binary Tree or Balanced Binary Tree visualizer.
Worked example: building a small binary tree
The same steps the visualizer animates for any input.
Insert 1: it becomes the root. Insert 2: first free slot in level order, so it is the left child of 1. Insert 3: next free slot, so it is the right child of 1. Insert 4: the root is full, so it is the left child of 2. Preorder: 1 2 4 3 Inorder: 4 2 1 3 Postorder: 4 2 3 1 Level order: 1 2 3 4
The same tree gives four different orders depending on when the root is visited.
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 binary tree height
The fewest and most nodes a binary tree of each height can hold.
| Height | Minimum nodes | Maximum nodes |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 2 | 3 |
| 3 | 3 | 7 |
| 4 | 4 | 15 |
| 5 | 5 | 31 |
| 6 | 6 | 63 |
| 7 | 7 | 127 |
| 8 | 8 | 255 |
| 9 | 9 | 511 |
| 10 | 10 | 1023 |
Binary Tree FAQ
Quick answers.
What is a binary tree?
A tree where each node has at most two children, a left and a right child.
What are the binary tree traversals?
Preorder (root, left, right), inorder (left, root, right), postorder (left, right, root) and level order (breadth first).
Is every binary tree a binary search tree?
No. A binary search tree also keeps smaller values on the left and larger values on the right. A plain binary tree has no ordering rule.
What is the difference between a binary tree and a binary search tree?
A binary tree only limits each node to two children. A binary search tree adds an ordering rule, so search, insert and delete can run in O(log n) when the tree is balanced.
What is the height of a binary tree?
The height is the number of levels from the root down to the deepest leaf. With n nodes it can range from about log2(n) for a compact tree up to n for a tree that is a straight line.
How many nodes can a binary tree have at most?
A binary tree of height h has at most 2^h - 1 nodes. Height 3 allows 7 nodes and height 4 allows 15.
What is the difference between full, complete and perfect binary trees?
In a full tree every node has 0 or 2 children. A complete tree is filled level by level from the left. A perfect tree has every level completely filled. The property badges in the visualizer check all three.
What is the time complexity of binary tree operations?
Search and traversal take O(n) in a plain binary tree because there is no ordering to follow. Insert at a known parent is O(1) and finding that parent is O(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.