DSAVisualiseData Structures & Algorithms Studio
Priority Queues Hard

Min-Max Heap

Insert keys into an array-backed heap whose levels alternate between minimum and maximum order.

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) swim
AverageO(log n) insert
WorstO(log n) insert
SpaceO(n)

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready to explore
Source behavior & common mistakes

Preserve alternating min/max levels while swimming each inserted key, then retrieve the minimum and maximum using the source methods.

  • Using min-heap rules at every level instead of alternating min and max levels.
  • Checking a grandparent before the source's parent comparison, or ignoring its `else if` priority.
  • Swapping on equality; the source comparisons are strict, and max returns child 3 on a tie.

Algorithm code

Java
MinMaxHeap.java (pinned repository source)Step linked
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1