Binary Tree Visualizer
Build and walk a binary search tree: insert, delete, search, traverse.
Binary Tree Visualizer
Insert numbers into a binary search tree and visualize the structure and operations
Tree Operations
Tree Traversal
Explore different ways to traverse the tree
Tree Statistics
Binary Search Tree
Visual representation of the binary search tree structure
Empty Tree
Insert numbers to build your binary search tree
Binary Search Tree Properties
Ordering Property
For any node, all values in the left subtree are smaller, and all values in the right subtree are larger.
Search Efficiency
Average case: O(log n) for search, insert, and delete operations. Worst case: O(n) when tree becomes skewed.
In-order Traversal
Visiting nodes in in-order sequence produces values in sorted order, making it useful for sorted data retrieval.
Binary tree vs BST
A binary tree: each node has at most two children. A BST adds the order rule—left subtree < node < right subtree—so search can discard half the remaining nodes each step.
Average insert/search/delete: O(log n). Sorted inserts can skew the tree into a line → O(n). AVL and red-black trees fix that with rotations.
Core operations
Insert
Walk left/right by comparison until you hit null; hang the new node there.
Search
Same walk; stop on equal or null.
Delete
Leaf: drop it. One child: promote the child. Two children: replace with inorder successor (min of right subtree), then delete that successor.
Traversals
- Inorder (L, node, R): sorted order on a BST
- Preorder (node, L, R): useful for copying structure
- Postorder (L, R, node): useful for deleting a tree
- Level-order: BFS by depth
Height is the longest root-to-leaf path length. Empty tree height conventions vary (often −1 or 0); a single root is height 0 or 1 depending on definition—pick one and stay consistent.
Related tools
Frequently Asked Questions
Binary tree vs BST?
Binary tree = shape constraint. BST = shape plus left < node < right.
When does a BST get slow?
When it skews—sorted inserts are the classic trap. Use a balanced variant for production maps/sets.
Duplicates?
Many textbooks forbid them. Real code may count duplicates in the node or push equals one side.
Delete with two children?
Replace with inorder successor or predecessor, then remove that replacement node (which has at most one child).
Related tools
Related tools
Related Number Tools
Add/Subtract Percentage
Add or subtract percentages from numbers
Age Calculator
Calculate age from birth date
Angle Converter
Convert between angle units
Area Converter
Convert between area units
Armstrong Number Checker
Check if a number is an Armstrong number
Average Calculator
Calculate average of numbers
Binary ↔ Decimal Converter
Convert between binary and decimal
BMI Calculator
Calculate your Body Mass Index (BMI) using metric or imperial units. Get instant health category classification and personalized weight range recommendations.
Box Plot Generator
Generate box plots from data
Combinations Calculator
Calculate combinations