DSAVisualiseData Structures & Algorithms Studio
Priority Queues Medium

Binary Min-Heap

Push values into the source's one-based array representation of a min-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(n)

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready to explore
Source behavior & common mistakes

Restore heap order after each insertion while preserving the backing array, parent comparisons, and capacity growth from BinaryHeap.java.

  • The root is stored at index 1, so index 0 remains in the Java backing array.
  • The source swaps only when a child is strictly smaller than its parent; equal values do not swap.
  • The source increments size before checking whether the backing array must double.

Algorithm code

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

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1