Workspace Heap
0d
Problem-solving patterns

Priority Heap

Keep the next highest-priority item at the root.

Recognition signal

A stream needs repeated minimum, maximum or top-k updates.

Method

Push new candidates and repair the parent-child order along one path.

Worked example

Keeping the top two of [4, 8, 7] replaces the retained minimum 4 with 7.

Common mistake

A valid heap array is only partially ordered.