Quick Sort Visualization & Animation

Picks a pivot, partitions around it, and recursively sorts each side; O(n log n) average, in-place.

## What is it? Quick Sort is a fast, in-place, divide-and-conquer sorting algorithm. It picks a "pivot" element and partitions the array so that all elements smaller than the pivot are to its left and all larger elements are to its right. It then recursively sorts each partition. ## How it works - **Choose a pivot** (commonly the last element, first element, or a random element) - **Partition:** rearrange elements so everything < pivot is to its left, everything > pivot to its right; the pivot lands in its final sorted position - Recursively apply the same process to the left and right sub-arrays - Base case: sub-array of size ≤ 1 is already sorted ## When to use - General-purpose in-memory sorting (standard library `sort()` in many languages) - When average-case performance matters more than worst-case guarantee - Cache-friendly — works well with modern CPUs due to locality of reference ## Key Points - Not stable — equal elements can change relative order - In-place — O(log n) stack space for recursion - Average O(n log n), worst case O(n²) — avoided with random pivot selection - Faster than Merge Sort in practice due to better cache performance

Category: algorithms

Difficulty: intermediate

Time Complexity: O(n log n) avg, O(n²) worst

Space Complexity: O(log n)

Quick Sort

intermediate

Picks a pivot, partitions around it, and recursively sorts each side; O(n log n) average, in-place.

64
[0]
34
[1]
25
[2]
12
[3]
22
[4]
11
[5]
90
[6]
Comparing
Pivot
Swapping
Sorted
Starting with unsorted array: [64, 34, 25, 12, 22, 11, 90]