human
Merge two sorted arrays | Merge arr1 [ 0. . n1 - 1 ] and arr2 [ 0. . n2 - 1 ] into arr3 [ 0. . n1 + n2 - 1 ].
Traverse both array.
Check if current element of first array is smaller than current element of second array . If yes , store first array element and increment first array index . Otherwise do same with second array.
Store remaining elements of first array.
Store remaining elements of second array.
Driver code"
Solution in Python:
assistant
#Here is code to merge two sorted arrays and the other steps required.
 def mergeArrays ( arr1 , arr2 , n1 , n2 ) :
	arr3 = [ None ] * ( n1 + n2 )
	i = 0
	j = 0
	k = 0
	while i < n1 and j < n2 :
		if arr1 [ i ] < arr2 [ j ] :
			arr3 [ k ] = arr1 [ i ]
			k = k + 1
			i = i + 1
		else :
			arr3 [ k ] = arr2 [ j ]
			k = k + 1
			j = j + 1
	while i < n1 :
		arr3 [ k ] = arr1 [ i ] ;
		k = k + 1
		i = i + 1
	while j < n2 :
		arr3 [ k ] = arr2 [ j ] ;
		k = k + 1
		j = j + 1
	print ( " Array ▁ after ▁ merging " )
	for i in range ( n1 + n2 ) :
		print ( str ( arr3 [ i ] ) , end = " ▁ " )
arr1 = [ 1 , 3 , 5 , 7 ]
n1 = len ( arr1 )
arr2 = [ 2 , 4 , 6 , 8 ]
n2 = len ( arr2 )
mergeArrays ( arr1 , arr2 , n1 , n2 ) ;