Sorting --- Insertion Sort

Steven J. Zeil

Old Dominion University, Dept. of Computer Science

Table of Contents

1. The Algorithm>
2. Insertion Sort: Worst Case Analysis
2.1. Looking at the Inner Loop
2.2. Inner Loop
2.3. Complexity of the Inner Loop
2.4. Outer Loop Body
2.5. Outer Loop Complexity
2.6. Complexity of insertionSort
3. Insertion Sort: special case
4. Average-Case Analysis for Insertion Sort
4.1. Inversions
4.2. A Speed Limit on Adjacent-Swap Sorting

Sorting: given a sequence of data items in an unknown order, re-arrange the items to put them into ascending (descending) order by key.

Sorting algorithms have been studied extensively. There is no one best algorithm for all circumstances, but the big-O behavior is a key to understanding where and when to use different algorithms.

The insertion sort divides the list of items into a sorted and an unsorted region, with the sorted items in the first part of the list.

Idea: Repeatedly take the first item from the unsorted region and insert it into the proper position in the sorted portion of the list.


In the Forum:

(no threads at this time)