DSAVisualiseData Structures & Algorithms Studio
Priority Queues Hard

Ternary Max-Heap

Insert, inspect, and remove values from a zero-based ternary max heap.

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)
AverageO(log₃ n)
WorstO(log₃ n)
SpaceO(capacity)

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready 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

Java
sorting/TernaryHeap.javaStep linked
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1