Sorting_Algorithms_Complexity
Sorting_Algorithms_Complexity
1. **QuickSort:**
- If all elements are the same, it does not split efficiently, leading to O(n²) complexity.
- If already sorted and a bad pivot is chosen (like first or last element), it leads to O(n²).
- A randomized pivot improves it to O(n log n).
2. **Insertion Sort:**
- Works in O(n) for both cases because it simply scans without swaps.
3. **Bubble Sort:**
- Takes O(n²) for identical elements but O(n) if already sorted (since no swaps happen).
5. **Counting Sort:**
- Works optimally in O(n) when elements are the same or already sorted.