Language: EN FI

Exercises > Insertion sort

These exercises demonstrate the content of the ByTheMark service. These are meant for private individuals for learning data structures and algorithms. If you want to try out more content, you can register to the ByTheMark Personal free of charge.

Apply insertion sort to the Input table below.

You can simulate the algorithm by performing all the necessary assignment operations in code lines 2, 5 and 7. In order to assign, for example, the value in array position 1 into the tmp variable (tmp = a[1]), drag and drop the corresponding value from Input on top of the tmp beneath the array.

InsertionSort(a)
1 for i = 1 to n-1 do
2   tmp = a[i]
3   j = i
4   while j > 0 AND a[j-1] > tmp do
5     a[j] = a[j-1]
6     j = j - 1
7   a[j] = tmp

  Last modified Tue Mar 01 20:54:04 EET 2011