Bubble Sort

Insertion Sort

Analyzing Sorts

  Number of Comparison Number of Exchanges
  Best Worst Best Worst
Selection Sort O(n^2) O(n^2) O(n) O(n)
Bubble Sort O(n) O(n^2) O(1) O(n^2)
Insertion Sort O(n) O(n^2) O(n) O(n^2)

Lecture Code

This code demonstrates (1) insertion sort and (2) how to modify selection sort so that it can be empirically analyzed. The second point will be quite useful for in-lab 6.