go to previous page   go to home page   go to next page
14 26 7

Answer:

By swapping 26 and 7

14 7 26

And then 14 and 7

7 14 26

Growing a Sorted List

Your browser does not support the HTML 5 Canvas. Try Chrome.

In the above list, the 26 by itself is a sorted sub-list. The sorted sublist is shown in red. (If 26 is not the left-most integer of the list, click "refresh" in your browser.)

The 26 and 14 are out of order. Extend the sorted sub-list by swapping them. Do this by sliding the 14 over the 26.

Now the sub-list is one integer bigger. Extend it by one integer by moving the integer just to the right of the sorted sub-list (7) to its proper place. This takes two swaps, done by sliding the 7 over the integers to be swapped.

Now the sorted sub-list is three integers long. Grow it again by moving the integer just to its right (8) to its proper place. Slide it until its neighbor to the left is smaller than it.

Keep growing the sub-list until the entire list is sorted.

In this algorithm, the integer just to the right of the sorted sub-list is inserted into the sub-list by repeatedly swaping it with the element to the left until it is in position. This is done left to right until the sub-list becomes the entire list.


QUESTION 4:

What do you suppose is the name of this algorithm?


go to previous page   go to home page   go to next page