Module 4.2 - More Complex Arrays
Our sorting algorithm is worse than Selection Sort because it actually swaps each number in the array with the value in the current array position if it's smaller.
As shown in the Selection Sort description in Wikipedia and by Michael Lamont, this algorithm, Selection Sort tracks the position in the array that contains the smallest value, and only swaps values at the end of the inner for loop.
Regardless, both versions have a complexity of n-squared, which means that for n array items, it takes n-squared time to sort the array. The best sorting algorithms (MergeSort or QuickSort, for example) have a complexity of nlog(n). Wikipedia also lists the complexity of sorting algorithms.
For more information on sorting algorithms, take a look at
- the Wikipedia summary of sorting algorithms.
- This animation of Selection Sort from HP/Compaq's System Research Center.
- Jason Harrison's visual animation of sorting algorithms.
For more information on arrays,
- HowStuffWorks also provides a continuation on the topic of arrays called More on Arrays.
- also check out About.com's tutorial on arrays,
- Finally, Todd Gibson provides a tutorial on arrays that includes some very good visuals.
Continue to the Extend Section ->