public int extract() {
        if (size == 0) throw new ArrayIndexOutOfBoundsException("the array is already empty");
        int max = heap[0];
        heap[0] = heap[size-- - 1];
        siftDown(0);
        return max;
    }