Insertion Sort

Notation

Step by Step

Advanced
Step 1 − If it is the first element, it is already sorted. return 1;
Step 2 − Pick next element
Step 3 − Compare with all elements in the sorted sub-list
Step 4 − Shift all the elements in the sorted sub-list that is greater than 
the value to be sorted
Step 5 − Insert the value
Step 6 − Repeat until list is sorted
  1. Go from left to right
  1. If value is less than value to its left then swap
  1. Look at next item in the list

Pseudocode

a = list
n = size of list

for (i = 0; i < n; i++)
	for (j = i; j > 0; j--)
		if(a[j] > a[j - 1])
			swap(a[j], a[j - 1]);
		else
			break;

Video