Priority Queues Medium
Binary Min-Heap
Push values into the source's one-based array representation of a min-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(n)
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady 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
Javasorting/BinaryHeap.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1