Heap

Info

A heap is a type of binary tree where all elements must satisfy the heap property

Warning

Not to be confused with "the heap" or freestore in C/C++. It's different.

Info

The heap property states that the child nodes must be less than their parent

Figure

Operations

See Big O

General Implementation

A heap is usually implemented with an array (dynamic). The left child is always at index 2 * i + 1, and the right child is always at index 2 * i + 2, and the parent is always at index (i - 1) / 2

Example

The heap above would look like:
[420, 69, 100, 32, 53, 30, 1, 9, 12, 31]