WHAT is a heap?

Tree-based data structure which is essentially an almost complete tree that statifies the heap property.

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.

Min heap

The P is less than or equal to the key C.

When to use a heap?

  • Priority queue.
  • Heapsort.