Not sure of what can be done to achieve the time limit as getting TLE in this python code present at https://ide.codingblocks.com/s/201794.
ML Python Merge Sort
Hey @tisandas2011, the link is not opening due to some issue, plz provide the new link or the code directly.
Hey @tisandas2011, complexity of your code is little high due to the line,
barr = [0]*(high)
I made some change and now your code runs fine like,
barr = [0]*(high-low+1)
and, for i in range(low,high+1):
array[i] = barr[i-low]
Here is the complete code,
def mergeSort(low,high,array):
# print(hex(id(array)))
if low<high:
mid = int((low+high)/2)
mergeSort(low,mid,array)
mergeSort(mid+1,high,array)
merge(low,mid,high,array)
def merge(low,mid,high,array):
i=low
j=mid+1
k=0
barr = [0]*(high-low+1)
# print(low, high, len(barr))
while i<=mid and j<=high:
if array[i]<=array[j]:
barr[k] = array[i]
i += 1
else:
barr[k] = array[j]
j += 1
k += 1
if i<=mid:
while i<=mid:
barr[k] = array[i]
i += 1
k += 1
else:
while j<=high:
barr[k] = array[j]
j += 1
k += 1
for i in range(low,high+1):
array[i] = barr[i-low]
def main():
elements = int(input())
array = [int(x) for x in input().split()]
mergeSort(0,len(array)-1,array)
for i in array:
print(str(i),end=" ")
print()
if __name__ == "__main__":
main()
Happy Learning 
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.