Priority Queues Hard
Ternary Max-Heap
Insert, inspect, and remove values from a zero-based ternary max heap.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
Source scenarios
Complexity
BestO(1)
AverageO(log₃ n)
WorstO(log₃ n)
SpaceO(capacity)
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady to explore
Source behavior & common mistakes
Track the source's three-child indexing, strict swim and child-selection comparisons, fixed backing array, and delete-time sink operations.
- The source stores the root at index zero; children are at 3i+1, 3i+2, and 3i+3.
- Swim swaps only when the child is strictly greater; equal children are not exchanged.
- largestChild scans in ascending index order and uses strict >, so ties keep the earliest child.
- The source allocates a fixed array and never resizes; a failed insert leaves size incremented.
Algorithm code
Javasorting/TernaryHeap.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1