Quick Sort Visualizer

Explore Quick Sort pivots and partitions through animated comparisons, swaps, step controls, live metrics, and algorithm explanations.

Current status: Choosing a pivot to partition the current range.

Comma-separated numbers, up to 20 values.

Balanced

Live operation

pivot

Step 1 / 49
6
[0]
32
[1]
20
[2]
28
[3]
12
[4]
2
[5]
31
[6]
23
[7]
17
[8]
20
[9]
PivotCompareSwapSorted pivot

Comparisons

0

Moves / writes

0

Confirmed sorted

0 / 10

Algorithm notes

What to watch for

Quick Sort fixes one pivot at a time. The partition step creates two independent subproblems, making the divide-and-conquer structure visible in the highlighted pivot and swaps.

Concept guide

Review the mental model, tradeoffs, and practical use cases after you experiment.

Quick Sort Complete Info Card

Divide & ConquerIn-Place

Quick Sort is an efficient divide-and-conquer algorithm that works by selecting a 'pivot' element and partitioning the array around the pivot, placing smaller elements before and larger elements after it.

Algorithm Characteristics

Time Complexity (Best)

Good pivot selection

O(n log n)

Time Complexity (Average)

Randomized pivot works well

O(n log n)

Time Complexity (Worst)

Bad pivot selection (already sorted)

O(n²)

Space Complexity

Recursion stack space

O(log n)

Stable

Default implementation is unstable

No

In-Place

Sorts without significant extra memory

Yes

Sorting Process Steps

1

Select a pivot element

2

Partition the array around the pivot

3

Recursively sort the left partition

4

Recursively sort the right partition

5

Base case: arrays of size 0 or 1 are sorted

Pivot Selection Strategies

StrategyAdvantagesDrawbacks
First ElementSimpleWorst-case on sorted arrays
RandomAvoids worst-case scenariosRandom number overhead
Median-of-ThreeBalanced partitionsSlight computation overhead
LomutoSimple implementationInefficient with duplicates
HoareMore efficientMore complex implementation

Optimal Use Cases

  • General-purpose sorting of large datasets
  • When average-case performance matters most
  • Memory-constrained environments

When to Avoid

  • When worst-case O(n²) is unacceptable
  • When stability is required
  • For small datasets (use Insertion Sort)
Pro Tip: Quick Sort is often used as the default sorting algorithm in standard libraries (like C++ STL and Java Collections) due to its excellent average-case performance.
Fast average caseIn-placeCache-friendly