TC : O(nlogn) (TC can be n^2 for SUUUper worst case i.e. If the Pivot is continuously bad) SC : O(n) for this version ... But SC can be reduced to O(logn)
(arr: list)
| 115 | |
| 116 | |
| 117 | def quick_sort(arr: list) -> list: |
| 118 | """TC : O(nlogn) (TC can be n^2 for SUUUper worst case i.e. If the Pivot is continuously bad) |
| 119 | SC : O(n) for this version ... But SC can be reduced to O(logn)""" |
| 120 | |
| 121 | if len(arr) <= 1: |
| 122 | return arr |
| 123 | |
| 124 | piv = arr[-1] |
| 125 | L = [x for x in arr[:-1] if x <= piv] |
| 126 | R = [x for x in arr[:-1] if x > piv] |
| 127 | |
| 128 | L, R = quick_sort(L), quick_sort(L) |
| 129 | |
| 130 | return L + [piv] + R |
| 131 | |
| 132 | |
| 133 | def counting_sort(arr: list) -> list: |
nothing calls this directly
no outgoing calls
no test coverage detected