MCPcopy Create free account
hub / github.com/geekcomputers/Python / quick_sort

Function quick_sort

sorting_algos.py:117–130  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

115
116
117def 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
133def counting_sort(arr: list) -> list:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected