code: private int choose_pivot(int p, int n) {
          int pl, pm, pn;// pointers
          int s;
  
          pm = p + (n >> 1); /* small arrays, middle element. */
          if (n > 7) {
              pl = p;
              pn = p + n - 1;
              if (n > 40) { /* big arrays, pseudomedian of 9. */
                  s = n >> 3;
                  pl = MED3(pl, pl + s, pl + s + s);
                  pm = MED3(pm - s, pm, pm + s);
                  pn = MED3(pn - s - s, pn - s, pn);
              }
              pm = MED3(pl, pm, pn); /* midsize arrays, median of 3. */
          }
          return KEY(pm);
      }
docs: Subroutine for {@link #sort_split(int, int)} , algorithm by Bentley & McIlroy.