Heap
Last updated
Was this helpful?
Last updated
Was this helpful?
A heap is a binary tree where every element satisfies the heap property
It is created to efficiently support basic priority queue operations
In a binary heap the keys are stored in an array
This heap property depends on the sort heap:
Max-Heap: parent > children (root is the biggest element)
Min-Heap: parent < children (root is the smallest element)
For every element in array from 0 to floor(N/2)
Check heap condition, swap if needed
If swapped, repeat swap check on the child
Performance is O(n)
Start from root and check children
Swap if needed depending on the heap
Repeat for the subheap