Technology Fundamentals

Heap

Definition

In computer science, a heap is a specialized tree-based data structure which is an almost complete tree that satisfies the heap property. In a max heap, for any given node C, if P is a parent node of C, then the key (the value) of P is greater than or equal to the key of C. In a min heap, the key of P is less than or equal to the key of C.

Why It Matters

Heaps are very efficient for finding the minimum or maximum element in a dataset, making them ideal for implementing priority queues. They are also a key part of the "heapsort" sorting algorithm.

Contextual Example

An operating system scheduler might use a min-heap to manage tasks. Each task has a priority, and the scheduler always picks the task with the highest priority (the minimum value) from the heap to run next.

Common Misunderstandings

  • This data structure "heap" is not to be confused with the "heap" which is a region of memory used for dynamic memory allocation.
  • A heap is not a sorted structure, but it has a partial order.

Related Terms

Last Updated: December 17, 2025