I've heard of this implementation of quick sort (in pseudocode):

    TAIL-RECURSIVE-QUICKSORT(A, p, r)
      while p < r
         q = PARTITION(A, p, r)
         if q < (p + (r-p)/2)
            TAIL-RECURSIVE-QUICKSORT(A, p, q-1)
            p = q+1
         else
            TAIL-RECURSIVE-QUICKSORT(A, q+1, p)
            r = q-1

Here it is partially implemented.

    private static void quickSort(int[] arr, int lo, int hi){
      if(lo >= hi) return;
    
      int p = partition(arr, lo, hi);
    
      // modified to choose small partition first
    
      if((p - lo )<=(hi-p)){
        System.out.println(String.format("Sorting left first %d %d %d",lo,p,hi)) ;
        quickSort(arr, lo, p);
        quickSort(arr, p+1, hi);
      }else {
        System.out.println(String.format("Sorting right first %d %d %d",lo,p,hi));
        quickSort(arr, p+1, hi);
        quickSort(arr, lo, p);
      }
    }

Can it be made any faster?


  [1]: http://mypathtothe4.blogspot.ca/2013/02/lesson-2-variations-on-quicksort-tail.html
  [2]: http://stackoverflow.com/questions/25438121/recursing-small-side-of-quicksort-first