The first entry of a min-heap is the smallest key, but reading the rest of its array from left to right does not produce a sorted sequence. The data structure preserves enough order to select the next minimum efficiently, without maintaining every pairwise relationship that a sorted array would impose.

That distinction matters when an abstract robot-event queue is inspected as a list. A display can look unsorted while representing a valid heap. Conversely, an operation can preserve the heap invariant while retaining the wrong set of records for the intended selection rule.

The examples below use invented finite integer priorities. Smaller numbers mean earlier selection. No robot scheduler, Python heap routine, or performance benchmark was executed.

Check the local invariant

Use zero-based array positions. A node at position i has children at 2i+1 and 2i+2 when those positions exist. A min-heap requires each parent key to be no greater than either child key. Its array also represents a complete binary tree: levels are filled in order, with the last level filled from the left.

Consider H = [2,5,3,9,8,7,4]. The root two is no greater than five or three. Five is no greater than its children nine and eight. Three is no greater than seven and four. The complete shape and every parent-child comparison are valid.

Nevertheless, the array is not sorted: five precedes three, nine precedes eight, and seven precedes four. Siblings do not need a specified relative order. Neither do nodes lying in separate subtrees.

Python's official heapq documentation states its zero-based min-heap invariant and the semantics of its combined operations. Carnegie Mellon's notes distinguish complete-tree shape from heap order and explain upward and downward repair. The arrays and traces here are independently constructed.

Why the root still certifies the minimum

Every existing node has a chain of parents leading back to the root. Repeatedly applying the local inequality shows root <= parent <= descendant along that path. Transitivity therefore makes the root no greater than any key anywhere in the heap.

This argument does not order two descendants whose paths branch apart. Local comparisons provide a global minimum certificate without providing a global sorted traversal.

A heap is also not a binary search tree. Its left subtree does not mean values below the root while its right subtree means values above it. Both subtrees of this min-heap contain keys at least as large as the root.

Insertion repairs one upward path

Append priority one to H. The new entry occupies position seven, preserving the complete shape. Its parent at position three contains nine, so the inequality fails. Swap one with nine.

One is now at position three, whose parent at position one contains five. Swap again. Its new parent is the root two, requiring a third swap. The resulting array is [1,2,3,5,8,7,4,9].

Only one ancestor path needed repair. Other branches already satisfied their comparisons, and each displaced parent moves down into a location where the existing order remains compatible. The newly added minimum reaches the root without sorting the entire array.

The longest such path has the height of the complete tree, which grows logarithmically with its size. This is a structural operation-count argument, not a measured runtime claim for a particular implementation or workload.

Removing the root repairs downward

Return to the original seven-entry H and remove its root two. To retain complete shape, move the last entry four to the root and shorten the array. The temporary array is [4,5,3,9,8,7].

Compare the root's children five and three. The smaller child is three; exchanging it with four gives [3,5,4,9,8,7]. Four's remaining child seven is no smaller than four, so repair stops.

Choosing the smaller child matters. Swapping the temporary root with five instead would leave a root five above child three and fail the invariant. A downward repair needs to preserve both child comparisons, not merely improve one of them.

Repeated minimum removals would emit keys in nondecreasing order while modifying the collection. Merely iterating through its current backing array performs a different operation and does not provide that ordered output.

Push-pop and replacement retain different sets

Take a separate heap with keys [4,7,6] and a new candidate two. A push-then-pop-min operation considers the union of the old keys and the candidate, returns its smallest key two, and retains the original set {4,6,7}.

A pop-min-then-push replacement first removes the old minimum four, then inserts two. It returns four and retains {2,6,7}. Both resulting collections can be valid heaps of size three, but they are different selections.

These correspond to Python's heappushpop and heapreplace semantics, respectively. For a candidate nine, both remove four and retain {6,7,9}. Their agreement for that candidate does not make them interchangeable for candidates below the current root.

If the declared objective is retaining the three largest keys seen so far, a min-heap can expose the smallest retained key as a threshold. A candidate below that threshold should not displace an existing retained key. The push-pop set rule expresses that objective directly; unconditional replacement does not.

Specify what the ordering means

Equal priorities need a separate policy if record identity or arrival order matters. The parent-child numeric invariant alone does not establish first-in-first-out behavior among ties. Similarly, changing a stored key without repairing affected comparisons can invalidate the heap even though the array still has the right length.

The mathematical examples assume an ordinary consistent order on finite integer keys. They do not silently extend that premise to values with unordered comparison behavior.

A useful queue record therefore names its comparison key, direction of priority, tie policy, mutation rules and retained-set objective. Heap validity certifies local order and minimum selection. It does not certify that the chosen operation implements every scheduling or data-selection rule one might intend.

Sources checked October 24, 2026:

Python: heapq, Heap Queue Algorithm: https://docs.python.org/3/library/heapq.html

Carnegie Mellon: Priority Queues and Heaps: https://web2.qatar.cmu.edu/cs/15121/notes/heaps/

Concept illustration: A small desktop robot beside a laptop showing a generic workflow provides robotics context for this analytical model. The image does not depict the article's numerical example, a verified experiment, a product specification, or deployment evidence.