DSAVisualiseData Structures & Algorithms Studio
Trees & Ordered Maps Hard

Array-Backed Binary Search Tree

Follow the source's binary search tree stored in four parallel ArrayLists, where child relationships are stable integer indices.

Trace input

Bounded JSON

Edit the lesson input, then build a deterministic source-linked trace.

This lesson validates its own input and operation limits.

Source scenarios

Complexity

BestO(1) for a root hit
AverageO(h) per put or get
WorstO(n) per operation in a skewed tree
SpaceO(n) across keys, values, and two child-index lists

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready to explore
Source behavior & common mistakes

Trace put and get operations, including search direction, key replacement, leaf-link reservation, and the four ordered append writes for a new node.

  • Array indices are node identities and remain stable as later entries append.
  • A new leaf's parent link is set to keys.size() before addNode appends the node.
  • addNode appends key, value, left NONE, and right NONE in that exact order.
  • put replaces the value and returns false when the key already exists.
  • get compares once for equality and again to choose the next child link.

Algorithm code

Java
ArrayBST.javaStep linked
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1
Comparisons 0