TopSelection SortInsertion Sort

Insertion Sort

The selection sort builds up the sorted list by finding the smallest element and putting it into the first position, then the second smallest and putting it into the second position, etc., until the entire list is sorted.

Insertion sort takes a different approach. It builds up a sorted list by noticing that we can build a sorted list of size n+1 by taking a sorted list of size n and inserting the n+1st element in its correct position.

We will not look at this algorithm in great detail here, but the details are in the text. Like selection sort, insertion sort takes n2 time. It is included in the searching/sorting demo. Also see the text for details.


TopSelection SortInsertion Sort