ELEMENTARY SORTS STUDY GUIDE


Inversions. The number of pairs of elements in a sequence that are out of order. An array with no inversions is ordered.

Selection sort. Be able to selection sort an array. How many compares does it use? How many exchanges?

Insertion sort. Be able to insertion sort an array. How many compares does it use in the best and worst case? How many exchanges in the best and worst case?

Partially ordered arrays. Why is insertion sort linear for partially sorted arrays?

Shellsort. An elementary sorting algorithm with a subquadratic running time. Its analysis is beyond the scope of this course.

Shuffling. Can use sorting to shuffle in N log N time by assigning each value an arbitrary unique value between 0 and 1. Can shuffle in N time using Knuth shuffle.

Recommended Problems

C level

  1. Final 2008 midterm, #9
  2. Give a worst case and best case input for insertion sort and selection sort.

B level

  1. Textbook 2.1.2
  2. Textbook 2.1.6, 2.1.7
  3. Fall 2012 midterm, #8

A level

  1. Textbook 2.1.28