Quick Sort
Sortingmedium#5Partition around pivot, recursively sort left and right
Ready
Step 1 of 0
Speed
Input Data
Comma-separated numbers (0-999). Min 2 values.
Algorithm Code
1function quickSort(arr, low, high) {2 if (low >= high) return;3 const pi = partition(arr, low, high);4 quickSort(arr, low, pi - 1);5 quickSort(arr, pi + 1, high);6}7function partition(arr, low, high) {8 const pivot = arr[high];9 let i = low - 1;10 for (let j = low; j < high; j++) {11 if (arr[j] < pivot) {12 i++;13 [arr[i], arr[j]] = [arr[j], arr[i]];14 }15 }16 [arr[i+1], arr[high]] = [arr[high], arr[i+1]];17 return i + 1;18}
Best
O(n log n)
Average
O(n log n)
Worst
O(n²)
Space
O(log n)
About Quick Sort
Quick Sort picks a 'pivot' element and partitions the array around it — elements smaller go left, larger go right. It recursively sorts the partitions. Average O(n log n) and in-place, making it the most widely used sorting algorithm in practice.
Time Complexity: Best: O(n log n), Average: O(n log n), Worst: O(n²). Space: O(log n).