I implemented merge-sort in python
import sys
def mergeSort(array):
if len(array) < 2:
return array
middle = len(array) / 2
left = mergeSort(array[:middle])
right = mergeSort(array[middle:])
return merge(left, right)
def merge(left, right):
result = []
while left and right:
if left[0] < right[0]: result.append(left.pop(0))
else: result.append(right.pop(0))
while left: result.append(left.pop(0))
while right: result.append(right.pop(0))
return result
array = map(int, sys.stdin)
print mergeSort(array)
But someone told me that the time complexity of list.pop(0) in python is linear or O(n). In that case the above code won't sort in O(n log n). What changes should I make to it?