In Online Course of Algorithms by Robert Sedgewick, Insertion sort is described as -
for(i = 0; i< length of array ; i++) // *i represents pointer which increments uniformly*
for( j = i ; j > 0 ; j--) // *j is subpart of i which compares previous elements*
if( array[j] < array[j-1])
swap( array[j] , array[j-1] ) ;
else
break;
in CLRS book , it is shown as -
for(i=2; i< length of array; i++)
key_value = array[i] ;
j = i-1 ;
while( j > 0 && array[j] > key_value)
array[j+1] = array[j]
j = j-1
array[j+1] = key_value
My question is - These 2 code are similar or different???