What is Quick Sort?
Pick a pivot, move smaller values left and larger values right, then sort both sides.
Type a tool name, format or task
Pick a pivot, move smaller values left and larger values right, then sort both sides. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Pick a pivot, move smaller values left and larger values right, then sort both sides. Choose a pivot value. Move values smaller than the pivot to its left and larger ones to its right. Repeat the same steps on the left and right parts. Time complexity: O(n log n) on average, O(n²) worst case. Space complexity: O(log n). One of the fastest general sorts in practice. Useful to understand when sorting large data sets in the browser.
Pick a pivot, move smaller values left and larger values right, then sort both sides.
Time: O(n log n) on average, O(n²) worst case. Space: O(log n).
One of the fastest general sorts in practice. Useful to understand when sorting large data sets in the browser.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
Quick sort picks a pivot, moves smaller values to its left and larger ones to its right, then repeats on both sides.
function quickSort(arr, lo = 0, hi = arr.length - 1) {if (lo >= hi) return;const pivot = arr[hi];let i = lo;for (let j = lo; j < hi; j++) {if (arr[j] < pivot) {[arr[i], arr[j]] = [arr[j], arr[i]];i++;}}[arr[i], arr[hi]] = [arr[hi], arr[i]];quickSort(arr, lo, i - 1);quickSort(arr, i + 1, hi);}
Tip: use the arrow keys to step and the space bar to play or pause.