Back to Portfolio

Search Tree Visualization

Compare the behaviors of different search tree data structures side by side

5
Value Distribution (1-100)
Click a position to change the starting value
Current Batch
Previous
Next Sequential

Naive BST

Simple binary tree with O(n) worst case. Left children are smaller, right children are larger.

Height: 0 Nodes: 0

Used in simple databases and file systems where balance is not critical.
Can get O(N) lookup complexity in worst case. Once a long linear chain forms, it will never self-correct without manual deletion.

AVL Tree

Self-balancing tree maintaining |height(left) - height(right)| ≤ 1 at every node.

Height: 0 Nodes: 0

Used in databases requiring strict lookup time guarantees and frequent searches.
Guarantees O(log N) operations with strict height balance.
Sometimes considered too strict — performs more rotations than necessary compared to RBT.

Red-Black Tree

Balanced using node colors with relaxed balance rules. Height ≤ 2log₂(n+1).

Height: 0 Nodes: 0

Used in system internals (Linux kernel, Java TreeMap) — often outperforms AVL in practice.
Faster insertions than AVL due to fewer rotations, while maintaining O(log N) guarantees.
More complex to implement than simpler balanced trees.

Size Balanced Tree

Maintains balance using subtree sizes. Size(left) and Size(right) bounded by each other's children.

Height: 0 Nodes: 0

Popular in competitive programming for order statistics and rank queries.
Efficiently supports finding k-th smallest element and node ranking operations.
Maintaining size metadata is computationally simpler than height tracking.

Treap

Randomized BST with heap property on priorities. Maintains balance probabilistically.

Height: 0 Nodes: 0

Good for dynamic sets with frequent insertions/deletions and no strict balance requirements.
Worst-case O(N) complexity exists, but probabilistically almost impossible (only with RNG malfunction).
Not considered as reliable as guaranteed balanced trees like AVL/RBT.

Splay Tree

Self-adjusting tree bringing accessed elements to root via rotations (splaying).

Height: 0 Nodes: 0

Excellent for caches and memory systems where recently accessed items are likely to be accessed again.
Self-optimizing: accessing existing nodes restructures the tree for better future access patterns.
Takes multiple operations per insertion and can be O(N) for individual operations. Can also stay a linear chain for really long time since self correction isn't guaranteed.

2-3-4 Tree

B-tree variant where nodes can have 2, 3, or 4 children. Always perfectly balanced.

Height: 0 Nodes: 0

Used in file systems and databases for efficient disk I/O operations.
Multi-way branching minimizes tree height, reducing disk reads in large datasets.
More complex node structure makes implementation and debugging harder.

Tree Comparison Metrics

Height Comparison

Balance Factor

Operation Count

Tree Properties

About Operation Counts

Measurement Methodology: We quantify atomic tree operations to analyze constant-factor performance differences among algorithms with equivalent asymptotic complexity. Each single rotation is counted as one unit operation; double rotations (e.g., LR, RL) count as two units. Metadata operations including Red-Black Tree recoloring are also included in the count as O(1) operations.
Note: This metric is experimental and subject to refinement as we evaluate alternative counting methodologies.

AVL Tree: Uses single rotations (1 spin) and double rotations like Left-Right or Right-Left (2 spins). Strictly balanced — typically 0-2 operations per insertion.

Red-Black Tree: Uses rotations sparingly by relying more on recoloring (not counted). On random input, RBT often needs fewer rotations than AVL. On sequential input, AVL wins.

Size Balanced Tree (SBT): Similar to AVL but balances based on subtree sizes. Competitive performance with slightly different rotation patterns.

Treap: Randomized tree using node priorities. Average case is good (similar to random BST), but can require rotations on every insertion to maintain heap property, leading to moderate operation counts.

Splay Tree: Aggressively rotates to move accessed nodes to the root using zig-zig and zig-zag patterns. Uses many spins per operation (can be 2-3x more than AVL) but self-optimizes for access patterns (amortized efficiency).

Why it matters: Lower structural change counts mean faster insertions. AVL excels on sequential data, RBT on random data. Splay prioritizes recent access over insertion cost.

Operation Log