Watch a min heap bubble a new value up, and sift the root down after extract min. Worked example on 2, 5, 4, 9, 7, 6, 8, with your own values, in O(log n).
About this algorithm
A min heap is a binary tree stored in an array where every parent is smaller than or equal to its children, so the smallest value always sits at index 0. You can read the minimum in O(1) and add or remove a value in O(log N), which is exactly what a priority queue needs when the item with the lowest number must come out first.
Use a min heap when you keep needing the smallest item of a collection that keeps changing: the closest unvisited node in Dijkstra's algorithm, the next event by time in a simulation, the earliest-ending meeting on the Meeting Rooms page, or the next value when merging k sorted lists. It also keeps the k largest values of a stream: hold a min heap of size k and drop its root whenever it grows past k. Pick a max heap when the largest value must come out first. A sorted array gives the minimum just as fast but pays O(N) for every insert.
Node i has its children at 2i + 1 and 2i + 2 and its parent at (i - 1) / 2, rounded down. The tree is always complete: every level is full except the last, which fills from the left. No pointers are needed.
Put the new value in the first free slot, at the end of the array. While it is smaller than its parent, swap the two. It stops when the parent is smaller or equal, or when it reaches the root.
Save the root; it is the answer. Move the last element of the array into index 0 and shrink the array by one.
While the moved value is larger than one of its children, swap it with the smaller child. Picking the smaller child makes the new parent smaller than both children.
The page loads the array [2, 5, 4, 9, 7, 6, 8]: 2 at the root, 5 and 4 under it, 9 and 7 under 5, 6 and 8 under 4. Play runs Extract-Min. It returns 2, moves the last value, 8, to the root, and sifts it down: against children 5 and 4 it swaps with 4, then against its one new child, 6, it swaps again. The heap is now [4, 5, 6, 9, 7, 8]. Press Reset and insert 1 instead. It lands at index 7, under 9. 1 is smaller than 9, so it swaps up to index 3; smaller than 5, up to index 1; smaller than 2, up to the root. The result is [1, 2, 4, 5, 7, 6, 8, 9], after 3 swaps, one per level climbed.
Python's heapq and Java's PriorityQueue are min heaps by default. C++'s std::priority_queue is a max heap unless you pass std::greater. A heap is not a sorted array: only the root is guaranteed, and reading the array from left to right does not give the values in order.
Time: peek reads index 0 in O(1); insert and extract-min make at most one swap per level, and a complete tree of N values has about log₂ N levels. Space: the array holds the N values and nothing else; each operation needs only a few extra variables.