human
In | Merges two subarrays of arr . First subarray is arr [ l . . m ] Second subarray is arr [ m + 1. . r ] Inplace Implementation.
If the direct merge is already sorted.
Two pointers to maintain start of both arrays to merge.
If element 1 is in right place.
Shift all the elements between element 1 element 2 , right by 1..
Update all the pointers.
* l is for left index and r is right index of the sub - array of arr to be sorted.
Same as ( l + r ) / 2 , but avoids overflow for large l and r.
Sort first and second halves.
Function to pran array.
Driver program to test above functions"
How can the above be solved in Python?
assistant
#Here is code to in and the other steps required.
 def merge ( arr , start , mid , end ) :
	start2 = mid + 1
	if ( arr [ mid ] <= arr [ start2 ] ) :
		return
	while ( start <= mid and start2 <= end ) :
		if ( arr [ start ] <= arr [ start2 ] ) :
			start += 1
		else :
			value = arr [ start2 ]
			index = start2
			while ( index != start ) :
				arr [ index ] = arr [ index - 1 ]
				index -= 1
			arr [ start ] = value
			start += 1
			mid += 1
			start2 += 1
def mergeSort ( arr , l , r ) :
	if ( l < r ) :
		m = l + ( r - l ) // 2
		mergeSort ( arr , l , m )
		mergeSort ( arr , m + 1 , r )
		merge ( arr , l , m , r )
def printArray ( A , size ) :
	for i in range ( size ) :
		print ( A [ i ] , end = " ▁ " )
	print ( )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 12 , 11 , 13 , 5 , 6 , 7 ]
	arr_size = len ( arr )
	mergeSort ( arr , 0 , arr_size - 1 )
	printArray ( arr , arr_size )