import random# TO-DO: complete the helper function below to merge 2 sorted arraysdefmerge( arrA,arrB ): elements =len( arrA )+len( arrB ) merged_arr = [0] * elements# Iterate through marged_arr to insert smallest item in arrA and arrB until merged_arr is fullfor i inrange(0, len(merged_arr)):# If arrA is empty, use arrB to filliflen(arrA)==0: merged_arr[i]=min(arrB) arrB.remove(min(arrB))# If arrB is empty, use arrA to filleliflen(arrB)==0: merged_arr[i]=min(arrA) arrA.remove(min(arrA))# If the smallest item in arrA is smaller than the smallest item in arrB, insert arrA's smallest item and then remove from arrAelifmin(arrA)<min(arrB): merged_arr[i]=min(arrA) arrA.remove(min(arrA))# If the smallest item in arrB is smaller than the smallest item in arrA, insert arrB's smallest item and then remove from arrBelifmin(arrA)>=min(arrB): merged_arr[i]=min(arrB) arrB.remove(min(arrB))return merged_arr# TO-DO: implement the Merge Sort function below USING RECURSIONdefmerge_sort( arr ):iflen(arr)==0orlen(arr)==1:return arr mid_point =round(len(arr)/2) arrA =merge_sort(arr[:mid_point]) arrB =merge_sort(arr[mid_point:])returnmerge(arrA,arrB)# STRETCH: implement an in-place merge sort algorithmdefmerge_in_place(arr,start,mid,end):# Updating the pointers# Getting past the halfway # Assign a variable to track the index of the other starting point # Decrementreturn arrdefmerge_sort_in_place(arr,l,r): # TO-DOreturn arr# STRETCH: implement the Timsort function below# hint: check out https://github.com/python/cpython/blob/master/Objects/listsort.txtdefinsertion_sort(arr):for i inrange(1, len(arr)):# Starts looping from first unsorted element unsorted = arr[i]# Starts comparing against last sorted element last_sorted_index = i-1# While unsorted is less than the last sorted...while last_sorted_index >=0and unsorted < arr[last_sorted_index]:# Shifts last sorted to the right by one arr[last_sorted_index +1]= arr[last_sorted_index]# Decrements down the last sorted index, until no longer larger than or hits zero last_sorted_index -=1# Places unsorted element into correct spot arr[last_sorted_index +1]= unsortedreturn arrdeftimsort( arr ):# Divide arr into runs of 32 (or as chosen)# If arr size is smaller than run, it will just use insertion sort minirun =32for i inrange(0, len(arr), minirun): counter =0 range_start = minirun * counter range_end = minirun * (counter+1)print(range_start, range_end)print(f"i is: {i}")print(insertion_sort(arr[range_start:range_end])) counter +=1# Sort runs using insertion sort# Merge arrays using merge sort# return insertion_sort(arr)test_sort = random.sample(range(100), 64)print(timsort(test_sort))