code: protected int partition(int attIdx, int[] index, int l, int r) {
      
      double pivot = m_Instances.instance(index[(l + r) / 2]).value(attIdx);
      int help;
  
      while (l < r) {
        while ((m_Instances.instance(index[l]).value(attIdx) < pivot) && (l < r)) {
          l++;
        }
        while ((m_Instances.instance(index[r]).value(attIdx) > pivot) && (l < r)) {
          r--;
        }
        if (l < r) {
          help = index[l];
          index[l] = index[r];
          index[r] = help;
          l++;
          r--;
        }
      }
      if ((l == r) && (m_Instances.instance(index[r]).value(attIdx) > pivot)) {
        r--;
      } 
  
      return r;
    }
docs: Partitions the instances around a pivot. Used by quicksort and
  kthSmallestValue.
  
  @param attIdx The attribution/dimension based on which the
  instances should be partitioned.
  @param index The master index array containing indices of the
  instances.
  @param l The begining index of the portion of master index
  array that should be partitioned.
  @param r The end index of the portion of master index array
  that should be partitioned.
  @return the index of the middle element