Trees & Ordered Maps Hard
BST Node Deletion (Array-Backed)
Follow the source's array-linked search tree as deletion marks nodes without moving their stable indices.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
Source scenarios
Complexity
BestO(1) for a root hit
AverageO(h) per put, get, or delete
WorstO(n) per operation in a skewed tree
SpaceO(k) for k distinct keys ever inserted
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady to explore
Source behavior & common mistakes
Trace insertion, lookup, and soft deletion. A deleted key stays in its array slot and a later put of the same key revives that slot.
- delete marks deleted[i] but leaves the key, value, links, and stable array index in place.
- Deleting a missing key or an already deleted key returns false.
- Putting a tombstoned key replaces its value, clears the flag, and returns true at the old index.
- Putting a different key never reuses a tombstoned slot; its new node appends at keys.size().
- getNodeIndex searches tombstones as ordinary keys so a matching put can revive them.
Algorithm code
JavaArrayBSTDelete.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 · Writes 0