Sorting . Chapter 9. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is to choose the criteria that will be used to order data.
The efficiency of data handling can often be increased if the data are sorted according to some criteria of order.
for i =1 to n-1
move all elements data[j] greater than data[i] by 1 position
Place data[i] in its proper position
To find the number of movements and comparisons performed by insertion sort, observe that:
for i=0 to n-2
Select the smallest elements among data[i] ….. data[n-1]
Swap it with data[i]
for i =0 to n-2
for j=n-1 down to i+1
Swap elements in position j and j-1 if they are out of order
The main disadvantage is that it looks at two adjacent array elements at a time and swaps them if they are not in order.
if length(array)>1 then choose Bound
while there are elements left in the array
include element in Subarray1 or Subarray 2