Americas
Europe
Q51E
Expert-verifiedWhen a list of elements is in close to the correct order, would it be better to use an insertion sort or its variation described in Exercise 50?
Hence, it is concluded that the changed insertion sort algorithm will work nicely if the list is close to the correct order.
Now, the required insertion sort algorithm is:
Procedure insertionsort ( : real numbers, )
For j : = 2 to n
i : = 1
While
For k = 0 to j - i - 1
{ is in increasing order}
Now, see the changed insertion sort algorithm:
Procedure insertionsort ( : real numbers, )
For j : = 2 to n
i : = j - 1
While
For k = 0 to j - i - 1 to 0
{ is in increasing order}
So, from the above two algorithm its is concluded that the use of linear search at the time of insertion of element will make the process fast if the elements are close to the correct order and the reason behind the statement is that the linear search goes from back to front.
94% of StudySmarter users get better grades.
Sign up for free