Binary Heaps

Priority Queue implementation using arrays. Supports Min Heap property.

Heap is Empty
Status: Empty Heap
Speed
1function insert(val):
2 arr.push(val)
3 bubbleUp(arr.length - 1)
4
5function bubbleUp(i):
6 while i > 0 && arr[i] < arr[parent(i)]:
7 swap(arr[i], arr[parent(i)])
8 i = parent(i)
9
10function extractMin():
11 root = arr[0]
12 arr[0] = arr.pop()
13 bubbleDown(0)
14 return root