# HackerRank: My QuickSort algorithm is too slow

Can someone please explain to me why this QuickSort algorithm has bad performance?

I followed a tutorial from Derek Banas so I thought it would optimal.

public static void quickSort(int[] arr, int left, int right){

if(left>=right) return;

int pivot = arr[right];

int index = partition(arr, left, right, pivot);

quickSort(arr, left, index-1);

quickSort(arr, index+1, right);

}

private static int partition(int[] arr, int left, int right, int pivot){

int leftPointer = left-1;

int rightPointer = right;

while(true){

while(arr[++leftPointer]

while(arr[--rightPointer]>pivot && rightPointer>leftPointer);

if(leftPointer>=rightPointer) break;

else{

//swap values

int temp = arr[leftPointer];

arr[leftPointer] = arr[rightPointer];

arr[rightPointer] = temp;

}

}

int tempP = arr[leftPointer];

arr[leftPointer] = arr[right];

arr[right] = tempP;

return leftPointer;

}...

By: StackOverFlow - Tuesday, 6 November

# Related Posts

- Older News
- Stackoverflow error in Quick Sort algorithm StackOverFlow (2 days ago) - So, my professor just gave us a homework to analyze the runtime of seven different sorting algorithms. Problem is: the Quick Sort algorithm he provided us is giving Stack Overflow...
- Need help modifying Quicksort algorithum StackOverFlow (2 days ago) - I need to write four versions of a Quicksort algorithm. I found a copy of a general quicksort algorithm online that I've been trying to modify to satisfy the requirements....
- Quicksort gets faster with duplicate keys (without three way partitioning). What is going on? StackOverFlow (2 days ago) - I am a little confused. I've been trying to test quicksort and everything seems to be working fine, except, when I have many duplicate array elements, I am a getting...