
Tony Hoare came up with DSA Quicksort in 1959. It is a "Divide and Conquer" algorithm that has worked for a long time. Algorithms like Bubble Sort are good for teaching logic, while Quicksort is made to work fast.
|
Case |
Time Complexity | When does it happen? |
|
Best Case |
O(n log n) |
The pivot always divides the array into two equal halves. |
| Average Case | O(n log n) | This is the standard performance in 99% of real-world scenarios. |
|
Worst Case |
O(n²) |
Happens when the pivot is always the smallest or largest element (e.g., sorting a already sorted array). |
| Space Complexity | O(log n) |
Due to the recursive stack. It is much more memory-efficient than Merge Sort. |
|
Feature |
Quicksort | Merge Sort |
|
Strategy |
Divide and Conquer | Divide and Conquer |
| Extra Space | Very little (O(log n)) |
Significant (O(n)) |
|
Stability |
Not Stable | Stable |
| Best For | Arrays / Memory-limited systems |
Linked Lists / External Sorting |
| Cache Friendly | High (Contiguous access) |
Low |

