private void siftDown(int i) {
    int left = i * 2;
    int right = i * 2 + 1;
    int smallest = i;
    if (left > 0 && left <= size && lessThan(left, smallest)) {
      smallest = left;
    }
    if (right > 0 && right <= size && lessThan(right, smallest)) {
      smallest = right;
    }
    if (smallest != i) {
      swap(i, smallest);
      siftDown(smallest);
    }
  }