Can't get insertion sort from 'The introdaction to algorithms 2nd edition'

48 Views Asked by At
INSERTION-SORT(A)
1   for j <- 2 to length[A]
2       do key <- A[j]
3          //Insert A[j] into the sorted sequence A[1 □ j - 1].
4          i <- j - 1
5          while i > 0 and A[i] > key
6           do A[i+1] <- A[i]
7              i <- i -1
8          A[i + 1] <- key

In line 1 we start from the second element of an array (it's how I understand the translation of pseudocode to actual code on any prog lang) but what if we were given a collection of just one element? Or was that case just excluded from consideration? (I'm not studying in uni just by myself so I can't get help from a prof, sorry if the question is basic)

0

There are 0 best solutions below