Binary Search Tree Visualizer

Paste an insertion-order array, build the binary search tree, then visualize search paths and traversal orders directly in the browser.

Nodes
7
Height
3
Leaves
4
Range
20 to 80

Insertion-order input

Values are inserted from left to right using BST rules. Duplicate values are ignored.

Single-value operations

Traversal

BST diagram

Sample insertion-order array loaded. Edit the array or use the secondary operations.

Path Match
Binary search tree diagramCurrent binary search tree built from the values 50, 30, 70, 20, 40, 60, 80.20304050607080

In-order result

Run a traversal to see the visit order. In-order traversal of a BST returns values in sorted order.

Current insertion order

50 -> 30 -> 70 -> 20 -> 40 -> 60 -> 80

Changing insertion order can create a different BST shape even when the values are the same.

What is a Binary Search Tree Visualizer?

A binary search tree visualizer is an interactive way to see how a BST stores values. Every node can have a left child and a right child. Values smaller than a node go to the left, and values greater than a node go to the right.

This tool lets you build a binary search tree from an insertion-order array, insert or delete individual values, search for a value, and compare common traversal orders.

If you need to preserve an exact tree shape from level-order input such as [1, null, 2, 3], use the Binary Tree Visualizer instead.

For the full cluster, browse the Data Structure Visualizers hub.

How to use this BST visualizer

  • Paste an insertion-order array such as [50, 30, 70, 20, 40, 60, 80].
  • Click Build to create the binary search tree from left to right.
  • Use Insert, Search, or Delete for single-value operations after the tree is built.
  • Run in-order, pre-order, post-order, or level-order traversal.
  • Use the highlighted nodes to follow the search path or traversal result.

The insertion order matters. The values 50, 30, 70 and 30, 50, 70 contain the same numbers, but they do not create the same tree shape.

Binary search tree traversal orders

In-order traversal visits the left subtree, then the node, then the right subtree. For a binary search tree, this returns the values in sorted order.

Pre-order traversal visits the node first, then the left subtree, then the right subtree. It is useful when you want to serialize or copy the shape of a tree.

Post-order traversal visits the left subtree, then the right subtree, then the node. It is common when deleting or freeing tree nodes.

Level-order traversal visits nodes breadth first, starting at the root and moving level by level.

Why BST visualization helps

Binary search trees are easier to understand when you can see the route taken by each operation. A search begins at the root and moves left or right after each comparison. The same pattern is used when inserting a new value.

If you are learning data structures, compare this tool with the existing guides on linked list implementation in C++, queue implementation in C++, and the Stack and Queue Visualizer. Trees, linked lists, stacks, and queues are often learned together because they all focus on how data is organized and accessed.

To see how balancing changes the tree shape, open the AVL Tree Visualizer. To compare a BST with a color-balanced search tree, use the Red Black Tree Visualizer. To compare a search tree with a priority queue, use the Heap Visualizer.

Frequently Asked Questions

What is a binary search tree?
A binary search tree is a tree data structure where each node's left subtree contains smaller values and each node's right subtree contains greater values.
Does this tool allow duplicate values?
No. This visualizer ignores duplicate values so the search, insert, delete, and traversal results stay clear and predictable.
Why does in-order traversal return sorted values?
In-order traversal visits the left side first, then the current node, then the right side. Because smaller BST values are placed on the left and larger values are placed on the right, this produces sorted output.
Can I use this for coding interview practice?
Yes. The tool is useful for checking search paths, traversal output, and how insertion order changes the shape of a binary search tree.

Related tools