high level explanation mergesort is a divide and conquer algorithm that splits in halves the array and then builds it back up by merging and sorting at the same time its elements time complexity mergesort has a time complexity of on log n copy data to temp arrays l and r checking if any element was left this code is contributed by mayank khanna and extented by thanasis mpalatsoukas finding the mid of the array dividing the array elements into 2 halves sorting the first half sorting the second half copy data to temp arrays l and r checking if any element was left this code is contributed by mayank khanna and extented by thanasis mpalatsoukas
def merge_sort(arr):
    if len(arr) >1:
        mid = len(arr)//2 
        L = arr[:mid] 
        R = arr[mid:] 

        merge_sort(L) 
        merge_sort(R) 

        i = j = k = 0

        
        while i < len(L) and j < len(R):
            if L[i] < R[j]:
                arr[k] = L[i]
                i+=1
            else:
                arr[k] = R[j]
                j+=1
            k+=1

        
        while i < len(L):
            arr[k] = L[i]
            i+=1
            k+=1

        while j < len(R):
            arr[k] = R[j]
            j+=1
            k+=1

test_array = [10,30,20,100,40,80,90,210,34]

merge_sort(test_array)

print(test_array)