such a poor explanation. he could use the pseudo code that he wrote line by line for the example. he himself is confused whether to move "i " after each iteration. Its better to watch videos of mit or stanford if professors from iit are poor in explaining. I m not saying all iit professors are bad. when the mooc is poor its better to move on.
He is utterly, thoroughly, hopelessly confused. At 12:50, he is flailing about,. not sure where is "i" and Where is "j". He must be the world's worst Algorithms teacher! Probably got appointed into IIT with political influence. And someone here calls his rambling confusion "one of the best explanation"!!!
if anyone has problem in understanding his ways plz keep a pdf of book " introduction to algorithms" by Thomas H. Cormen , you will understand better .... thank you
Code for the algo explained in the lecture: (C++) void insertionSort(int arr[], int n) { for (int i = 1; i < n; i++) { int key = arr[i]; int j = i - 1; // Move elements of arr[0..i-1] that are greater than key // to one position ahead of their current position while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j--; } arr[j + 1] = key; } }