LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

Is a heap sorted? What does the heap-order property not tell you?

No. The heap-order property only orders each parent against its children; it says nothing about siblings, cousins or left versus right. Only the root position is guaranteed (the minimum).

Consider the heap with root 2, children 5 and 6, and 9 and 7 below the 5. Several things a learner might expect are false:

  • Left is not smaller than right. 5 and 6 happen to be in order, but the heap would be just as valid with 6 on the left and 5 on the right. This is the key difference from a binary search tree, where smaller keys always go left and larger keys right.
  • Depth is not rank. Make the 6 a 10 and the heap is still valid, yet now 9 and 7 on depth 2 are both smaller than 10 on depth 1: a deeper node can be smaller than a shallower one in another branch. Even reading level by level (2, 5, 6, 9, 7) is not sorted.
  • No traversal yields sorted order. An inorder traversal of this heap gives 9, 5, 7, 2, 6.
  • Searching for an arbitrary key is slow. Because there is no left/right rule, looking for, say, key 7 may require visiting every node: $O(n)$.

That is the bargain: a heap maintains just enough order to find the minimum instantly and to repair itself in $O(\log n)$ after a change, and no more. Full sortedness would make updates expensive, which is exactly the problem of the sorted list.

From Quiz: ADS / Priority Queues and Heaps | Updated: Nov 26, 2026