Sorting & Selection Medium
3-Way Quicksort Partition
This quicksort shuffles before partitioning, but randomizing cannot help when equal keys make both scans run to opposite ends. Strict scans stop on ties and produce balanced partitions for an all-equal array.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
Source scenarios
Complexity
BestO(n log n)
AverageO(n log n)
WorstO(n²)
SpaceO(log n) average; O(n) worst-case call stack
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady to explore
Source behavior & common mistakes
Follow Fisher–Yates shuffling, Hoare-style partition scans, item exchanges, recursive calls, and sorted-range checks for signed 32-bit integers.
- Changing either strict scan from < to <= makes equal keys keep scanning and recreates one-sided partitions.
- Shuffling does not cure the equal-key case when every possible pivot has the same value.
- Stop the left scan at hi and retain the pivot at lo as the right scan's sentinel.
- The final pivot exchange happens after the pointers cross; its returned index separates the recursive ranges.
- Quicksort can exchange equal values, so its item order is not stable.
- The source uses signed Java int comparisons; this adapter accepts only signed 32-bit integers.
Algorithm code
JavaFixQuickSort.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1
Comparisons 0 · Writes 0