Robotics C++ Java AP Java Electronics  Summer   Physics II AP Physics Astronomy Other

 

Comparison Graphs

 

O(n2) Sorts 

 

*Shell sort (see note below) is not tested on AP exam.

 

O(nlog n) Sorts

 

*Shell sort is a generalization of insertion sort, with two observations in mind:
  1. Insertion sort is efficient if the input is "almost sorted".
  2. Insertion sort is inefficient, on average, because it moves values just one position at a time.

Shell sort improves insertion sort by comparing elements separated by a gap of several positions. This lets an element take "bigger steps" toward its expected position. Multiple passes over the data are taken with smaller and smaller gap sizes. The last step of Shell sort is a plain insertion sort, but by then, the array of data is guaranteed to be almost sorted