there is no problem with the exact same logic under CPP. Python reports
RecursionError: maximum recursion depth exceeded in comparison
def merge(a:list, start:int, end:int, mid:int):
t=deepcopy(a)
i=start
j=mid
k=start
while i<mid and j<end:
if(t[i]>t[j]):
a[k]=t[j]
k+=1
j+=1
else:
a[k]=t[i]
i+=1
k+=1
while i<mid:
a[k]=t[i]
i+=1
k+=1
while j<end:
a[k]=t[j]
j+=1
k+=1
def merge_sort(a:list, start:int, end:int):
if start<(end-1):
mid=(end-start)//2
merge_sort(a, start,mid)
merge_sort(a, mid, end)
merge(a, start, end, mid)