Quick sort
Additional details
Quick sort is a divide-and-conquer algorithm that works by selecting a 'pivot' element from the array and partitioning the other elements into two sub-arrays according to whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively.
Time complexity: O(n²) in the worst case, O(n log n) in the average case.
Space complexity: O(log n) due to the recursion stack.
This implementation uses an iterative approach with a stack to avoid actual recursion, allowing us to visualize the algorithm's steps and pause/resume at any point.
Color code:
- Red: Pivot element
- Blue: Current element being compared
- Teal: Index tracking elements smaller than pivot