Binary Search Tree Visualizer

Explore BST insertion, search, deletion, and traversal with animated comparisons, responsive controls, and live tree statistics.

Current status: Start with a value, or load the demo tree to explore the BST rule.
Ordered tree playground

Binary Search Tree Visualizer

Every comparison chooses a branch: values smaller than a node go left; values larger go right. Watch the route before the tree changes.

Tree controls

Compare, branch, and connect

nodes: 0

Build

Find

Traverse

Tree stage

The active node marks the current comparison

active branch

Your tree is waiting.

Insert a number to grow from the root, or load the demo to start exploring immediately.

Traversal output

Visited values

waiting
Run a traversal to reveal its visit order.

Under the hood

Operation sketch

Choose an operation, then inspect the small Java sketch that drives the comparison or pointer update.

Why does the BST rule matter?

A Binary Search Tree keeps each left subtree smaller and each right subtree larger than its parent. Each comparison rules out half of the remaining choices-when the tree stays reasonably balanced.

Search / insert

O(h)

Inorder output

sorted

Worst-case height

O(n)

Concept guide

Review the mental model, tradeoffs, and practical use cases after you experiment.

Binary Search Tree Complete Info Card

OrderedHierarchical

A Binary Search Tree (BST) is an ordered tree structure maintaining the invariant where left child values are smaller and right child values are larger than their parent. Enables efficient search operations through value comparisons at each node.

BST Characteristics

Search Complexity (Avg)

Balanced tree structure

O(log n)

Search Complexity (Worst)

Linear tree (skewed)

O(n)

Insert/Delete (Avg)

Height-balanced operations

O(log n)

Space Complexity

Node-based storage

O(n)

Order Property

Left < Root < Right

Yes

Self-Balancing

AVL/Red-Black variants

Optional

Core Operations

1

Insert: Find position using BST property

2

Delete: Handle leaf/one-child/two-children cases

3

Search: Traverse left/right based on values

4

Traversal: In-order returns sorted sequence

5

Balance: Rotations (for balanced variants)

BST Variants & Properties

VariantAdvantagesTrade-offs
AVL TreeStrict balanceRotation overhead
Red-Black TreeEfficient balanceComplex rules
Splay TreeSelf-optimizingUnpredictable performance
TreapRandomized balancePriority management
Threaded BSTEfficient traversalExtra pointer storage

Optimal Use Cases

  • Dynamic datasets requiring frequent lookups
  • Implementation of ordered map/set
  • Database indexing structures

When to Avoid

  • Static datasets (use sorted arrays)
  • Memory-constrained environments
  • When hash tables would suffice
Pro Tip: Use self-balancing BST variants for dynamic datasets. For read-heavy workloads, consider using a sorted array with binary search for better cache performance.
Ordered StructureLogarithmic SearchDynamic Data