I would like to find the best, average, worst-case complexities of below code.
Its a variant of selection sort. In each pass both min and max is calculated and placed at proper position
def double_selection_sort(arr):
n = len(arr)
for i in range(int(n/2)):
_min, _max = i, n-i-1
for j in range(i+1, n-i-1):
if arr[_min] > arr[j]:
_min = j
if arr[_max] < arr[j]:
_max = j
arr[i], arr[_min] = arr[_min], arr[i]
arr[n-i-1], arr[_max] = arr[_max], arr[n-i-1]
I think its in the order of O(nlogn).
Thanks in Advance