NOTE

Heap / Priority Queue

Binary heap representation and priority-queue operations such as push, peek, pop, and heapify.

Data Structures & AlgorithmsCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

A binary heap is a complete binary tree usually stored compactly in an array. A min-heap maintains each parent <= children; a max-heap reverses the relation.

Peek is O(1); insertion and removing the root are O(log n); building a heap bottom-up is O(n).

Heaps are ideal for priority queues and top-k/selection tasks. They do not maintain a fully sorted sequence, so arbitrary ordered iteration is not free.

Loading helpful count