def quickSort(arr):
if len(arr) < 2:
return arr
pivot = arr[0]
i = 0
for j in range(len(arr)-1):
if arr[j+1] < pivot:
arr[j+1], arr[i+1] = arr[i+1], arr[j+1]
i += 1
arr[0], arr[i] = arr[i], arr[0]
return quickSort(arr[:i]) + [arr[i]] + quickSort(arr[i+1:])
import random
# quick sort
def quickSort(arr):
if len(arr) < 2:
return arr
pivot = random.choice(arr)
less = [x for x in arr if x < pivot]
more = [x for x in arr if x >= pivot]
return quickSort(less) + quickSort(more)
def merge(left, right):
i, j = 0, 0
res = []
while i < len(left) and j < len(right):
if left[i] <= right[j]:
res.append(left[i])
i += 1
else:
res.append(right[j])
j += 1
return res + left[i:] + right[j:]
def mergeSort(arr):
if len(arr) < 2:
return arr
index = len(arr) / 2
left = mergeSort(arr[:index])
right = mergeSort(arr[index:])
return merge(left, right)