private void maxHeapify(int a[], int i, int heapSize) {
        int left = left(i, a, heapSize);
        int right = right(i, a, heapSize);
        int largest = i;

        if (left == -1 && right == -1) {
            return;
        }

        if (left != -1 && a[left] > a[largest]) {
            largest = left;
        }

        if (right != -1 && a[right] > a[largest]) {
            largest = right;
        }

        if (largest == i) {
            return;
        }

        // swap a[i] and a[largest]
        int temp = a[i];
        a[i] = a[largest];
        a[largest] = temp;

        maxHeapify(a, largest, heapSize);
    }