210 likes | 398 Views
Sequential Sorting . Sean Lyn COP4800 February 5, 2008. A Lower Bound on Speed. The fastest any comparison based sort can sort a list is O(NlogN) The longest any comparison based sort should take is O(N²). Sorting Algorithms . Selection Sort Insertion Sort Bubble Sort Shell Sort
E N D
Sequential Sorting Sean Lyn COP4800 February 5, 2008
A Lower Bound on Speed • The fastest any comparison based sort can sort a list is O(NlogN) • The longest any comparison based sort should take is O(N²)
Sorting Algorithms • Selection Sort • Insertion Sort • Bubble Sort • Shell Sort • Bucket Sort • Radix Sort • Quick Sort • Merge Sort – not covered • Heap Sort – not covered
Selection Sort • “Selects” the smallest element • Find the smallest element • Put that element at the beginning • Repeat • Speed: O(N²)
Insertion Sort • “Inserts” the element into the right position • Start with the first element • Insert the next element into the current list in the right position • Repeat • Speed: O(N²)
Bubble Sort • Compare the first two elements • Put them in order • Compare the second and third • Put them in order • Repeat this process • Speed: O(N²)
Shell Sort • Sort the kth element of every nth set of elements where k goes from 1 to n • Repeat the process on (n-1) until n=1 • n <= size/2 • Speed: up to O(N^(7/6))
Bucket Sort • Put the elements into “buckets” of smaller denominations based on their most significant digits • Repeat on each bucket • Speed: O(N) – varies due to the bound of the digits
Numbers are bound from 1 to 29starting with: 5 2 19 22 25 7 3 16
Radix Sort • Sort the array based on the least significant digit • Sort the array based on the next least significant digit • Repeat until the array is sorted • Speed: O(N) – varies depending on the bound of the digits
Quick Sort • Pick a pivot • Put all numbers lower than the pivot to the left of it and all numbers higher to the right • Repeat on the smaller arrays until only 1 element remains • Speed: O(NlogN) (average)
The fastest any comparison based sort can sort a list is O(NlogN) • The longest any comparison based sort should take is O(N²) • Selection Sort – O(N²) • Insertion Sort – O(N²) • Bubble Sort – O(N²) • Shell Sort – O(N^(7/6)) • Bucket Sort – O(N) - depends • Radix Sort – O(N) - depends • Quick Sort – O(NlogN) - average
Works Cited • Dewdney, A. The New Turing Omnibus. New York: Computer Science Press, 1989. • Douglass, Ben. Computer Science 2. UCF, 2006. • Weiss, Mark. Data Structures and Problem Solving Using Java. Boston: Pearson Education, Inc, 2006.