Introduction to Algorithms : A Sorting Algorithm
Print this page
 
 

The algorithmic description of insertion sort is given below.

     

Algorithm Insertion_Sort (a[n])

Step 1: for i = 2 to n do
Step 2: current_num = a[i]
Step 3:

j = i

Step 4:

while (( j >1) and (a[j-1] > current_num)) do

Step 5:

a[j] = a[j-1]

Step 6:

j = j-1

Step 7: a[j] = current_num
 

More about sorting algorithms are discussed in the modules 5 and 10.

 
Prev