Secondary functions

Sift up procedure — $O(\log{n})$

void recursiveSiftUp(i) {
	if (i == 0) { // if reached the root, stop
		return;
	}
	if (array[i] < array[parentOf(i)]) {
		swap(array[i], array[parentOf(i)]); 
	}
	recursiveSiftUp(parentOf(i)); // recursive call
}
void siftUp(i) {
	while (i != root && array[i] < array[parentOf(i)]) {
		swap(array[i], array[parentOf(i)]);
		i = parentOf(i); 
	}
}

Sift down procedure — $O(\log{n})$

void siftDown(i) {
	while (hasLeftChild(i) && leftChild(i) < array[i] || hasRightChild(i) && rightChild(i) < array[i]) {
		minChild = min(leftChild(i), rightChild(i)); 
		swap(array[i], minChild); 
		i = minChild; 
	}
}