samedi 3 mars 2018

How to I modify insertion sort algorithm to a 2 way insertion sort?

Here is the description of the algorithm. The two way insertion sort is a modification of your simple insertion sort. Suppose you are sorting the array x. A seperate output array of size 2n+ 1 is set aside. Initially x[0] is placed into the middle element of the array n. Continue inserting elements until you need to insert between a pair of elements in the array. As before you need to make room for the new element by shifting elements. Unlike before, you can choose to shift all smaller elements one step to the left or all larger elements one step to the right since there is additional room on both sides of the array. The choice of which shift to perform depends on which would require shifting the smallest amount of elements. But how do I implement it?

Aucun commentaire:

Enregistrer un commentaire