Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Choose the last element as pivot. Partition the array so all elements less than the pivot are on the left and all greater are on the right. The pivot lands in its correct final position. Recursively sort the two partitions. The partition function is the key operation.
Partition places the pivot in its correct position in O(n) time. On average, the pivot splits the array roughly in half, giving O(log n) recursive levels. Worst case occurs when the pivot is always the min or max (sorted input), giving O(n) levels.
Updated Feb 2026