Binary Search Tree Simulator

Build and explore a binary search tree interactively. Insert new values, remove existing nodes, search for a value, and visualize how the tree changes. Explore in-order, pre-order, and post-order traversal sequences.

Build Your Binary Search Tree

Use a safe integer between -1,000,000 and 1,000,000.

Enter an integer and choose Insert Node to begin.

Tree Visualization

Each node is positioned according to its left and right child relationships.
0 nodes
Your tree is empty. Insert a node to start.
Normal node Search path Found node Traversal highlight
Total nodes
0
Tree height
0
Minimum value
—
Maximum value
—

Tree Traversal Visualizer

Select a traversal method to see the order in which nodes are visited. The sequence is displayed from left to right.

Choose a traversal method to inspect the current tree.
Traversal sequence
No traversal generated yet.
Traversal progress will appear here.

Search Path and Operation Details

When you search for a value, the simulator highlights the nodes visited while following the binary search tree rules.

Step Current node Comparison Next action
No search performed yet.

How a Binary Search Tree Works

A binary search tree (BST) is a binary tree in which each node follows an ordering rule. Values smaller than a node are placed in its left subtree, while values larger than the node are placed in its right subtree.

Left subtree values < Node value
Right subtree values > Node value

For example, inserting 50, 30, 70, 20, 40, 60, and 80 produces this structure:

50 / \ 30 70 / \ / \ 20 40 60 80

BST Operations

Three Common Traversal Methods

Traversal Visit order Example result
In-order Left → Root → Right 20, 30, 40, 50, 60, 70, 80
Pre-order Root → Left → Right 50, 30, 20, 40, 70, 60, 80
Post-order Left → Right → Root 20, 40, 30, 60, 80, 70, 50

Time Complexity

The performance of a binary search tree depends on its shape. A balanced tree can provide efficient operations, while a highly skewed tree can behave similarly to a linked list.

Operation Average case Worst case
SearchO(log n)O(n)
InsertionO(log n)O(n)
DeletionO(log n)O(n)
TraversalO(n)O(n)

This simulator implements a standard, unbalanced BST. It does not automatically rebalance the tree.

Frequently Asked Questions

What is a binary search tree?

A binary search tree is a data structure in which each node has at most two children. Values smaller than a node are stored to its left, and larger values are stored to its right.

How do I insert a node into the BST?

Enter an integer and click Insert Node. The simulator compares the value with existing nodes and places it in the correct empty position.

How does BST deletion work?

A node with no children can be removed directly. A node with one child is replaced by that child. A node with two children is replaced by its in-order successor, the smallest value in its right subtree.

Why does in-order traversal produce sorted values?

In-order traversal visits the left subtree, then the current node, then the right subtree. Because of the BST ordering rule, the resulting sequence is sorted in ascending order.

Does this simulator allow duplicate values?

No. Duplicate values are rejected so that each value appears only once in the tree.

Is this an AVL tree or a Red-Black tree?

No. It is a standard binary search tree. It does not automatically rotate or rebalance nodes after insertions or deletions.

What is the difference between pre-order and post-order traversal?

Pre-order visits the root before its children. Post-order visits both subtrees before visiting the root.

Related Binary and Computer Science Tools

Binary Search Simulator

Visualize binary search iterations and midpoint comparisons.

Binary String Validator

Validate binary strings and inspect their format.

Number Base Converter

Convert numbers between binary, decimal, hexadecimal, and octal.

Binary to Decimal Converter

Convert binary values into decimal numbers.

Decimal to Binary Converter

Convert decimal integers into binary representation.

Truth Table Generator

Generate truth tables for Boolean expressions.

Logic Gate Simulator

Explore digital logic gates and their outputs.