2. Iterative Insertion Sort

Insertion_sort.gif
!500

Outer loop: for loop

for loop to check each element

Inner loop: while loop

conditional while loop to find the correct element position

def insertionSort(array):
	for i in range(1, len(array)):
		j=i
		while j>0 and array[j]<array[j-1]:
		#while element index(2) larger than zero
		#while second element is smaller than first element and 
			array[j-1],array[j]=array[j],array[j-1]
			j-=1#1-1=0# second element is sorted
	return array

every index is sorted to its left most(ascending order) position before the index is incremented to sort the next index

2. Recursive Insertion Sort