This page discusses the heap data structure. For the place where memory is dynamically allocated from, see dynamic memory allocation.

In computer science a **heap** is a specialized tree-based data structure. Its base datatype (used for node keys) must be an ordered set.

Let *A* and *B* be nodes of a heap, such that *B* is a child of *A*. The heap must then satisfy the following condition (*heap property*):

- key(
*A*) ≥ key(*B*)

Heaps are used in the sorting algorithm called heapsort.

## Variants

- Binary heap
- Binomial heap
- Fibonacci heap
- Soft heap