AiTechWorlds
AiTechWorlds
Visualize Quick Sort partitioning around a pivot, with live code, swap counters, and worst-case explanation.
def quick_sort(a, lo=0, hi=None):
if hi is None: hi = len(a) - 1
if lo >= hi: return
pivot, i = a[hi], lo - 1
for j in range(lo, hi):
if a[j] <= pivot:
i += 1
a[i], a[j] = a[j], a[i]
a[i + 1], a[hi] = a[hi], a[i + 1]
quick_sort(a, lo, i); quick_sort(a, i + 2, hi)Quick Sort picks a pivot, partitions elements around it, then recursively sorts each partition — very fast in practice with low constant factors.
| Best | O(n log n) |
| Average | O(n log n) |
| Worst | O(n²) |
| Space | O(log n) |
| Stable | No |
| In-place | Yes |
The Quick Sort Visualizer animates how Quick Sort works: it picks a pivot, partitions elements so smaller values move left and larger move right, then recursively sorts each partition. Quick Sort runs in O(n log n) on average, O(n²) worst case with bad pivots, uses O(log n) stack space, and is not stable. Use Play, Step, and the timeline to follow the pivot and partition.
Generate an array
Click New Array or set the size slider for a random dataset.
Play the animation
Press Play to watch the pivot (purple) and partition swaps (red).
Step and scrub
Use Step Forward/Back or the timeline to study each partition step.
Read the synced code
The highlighted pseudocode line tracks partitioning; switch tabs for C++, Java, Python, or JavaScript.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.