human
Can you provide a code to difference between Insertion sort and Selection sort and the other steps required given the following:
Difference between Insertion sort and Selection sort | Function to sort an array using insertion sort.
Move elements of arr [ 0. . i - 1 ] , that are greater than key to one position ahead of their current position.
Function to print an array of size N.
Print the array.
Driver Code.
Function Call"
Solution in Python:
assistant
#Here is code to difference between Insertion sort and Selection sort and the other steps required.
 def insertionSort ( arr , n ) :
	i = 0
	key = 0
	j = 0
	for i in range ( 1 , n , 1 ) :
		key = arr [ i ]
		j = i - 1
		while ( j >= 0 and arr [ j ] > key ) :
			arr [ j + 1 ] = arr [ j ]
			j = j - 1
		arr [ j + 1 ] = key
def printArray ( arr , n ) :
	i = 0
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )
	print ( " " , end ▁ = ▁ " " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 12 , 11 , 13 , 5 , 6 ]
	N = len ( arr )
	insertionSort ( arr , N )
	printArray ( arr , N )