Quick Sort
Quick Sort uses divide-and-conquer by selecting a pivot element and partitioning the array around it.
IntermediateTime: O(n log n)Space: O(log n)
Take QuizCurrent Step
Press Play to start the visualization
## How Quick Sort Works
Quick Sort is a divide-and-conquer algorithm. It selects a 'pivot' element and partitions the array around the pivot, then recursively sorts the sub-arrays.
### Algorithm Steps:
1. Choose a pivot element (often the last element)
2. Partition: Rearrange so elements < pivot are left, > pivot are right
3. Pivot is now in its final position
4. Recursively apply to left and right sub-arrays
5. Base case: Arrays of size 0 or 1 are sorted
### Key Characteristics:
- **In-place**: Can be implemented with O(log n) extra space
- **Not Stable**: May change relative order of equal elements
- **Very Fast**: Average case O(n log n), often faster in practice
Time & Space Complexity
| Case | Time Complexity |
|---|---|
| Best | O(n log n) |
| Average | O(n log n) |
| Worst | O(n²) |
| Space | O(log n) |
Practice Problems
10 problems81 total points
1
Basic Quick Sort
Beginner5 pts
2
Partition Array
Beginner5 pts
3
Find Kth Smallest
Beginner5 pts
4
Quick Sort with Random Pivot
Intermediate8 pts
5
Three-Way Partition
Intermediate8 pts
6
Quick Select (Kth Element O(n))
Advanced10 pts
7
Iterative Quick Sort
Advanced10 pts
8
Sort Colors (Dutch Flag)
Advanced10 pts
9
Median of Medians
Advanced10 pts
10
Nuts and Bolts Problem
Advanced10 pts