80 likes | 235 Views
Sorting. Selection Sort (Basic). Find the smallest element Move to the front of the array (swap with front) Repeat Steps 1&2, but ignore the sorted the front area. Selection Sort Animations. http://courses.cs.vt.edu/~csonline/Algorithms/Lessons/SelectionCardSort/selectioncardsort.swf
E N D
Selection Sort (Basic) • Find the smallest element • Move to the front of the array (swap with front) • Repeat Steps 1&2, but ignore the sorted the front area
Selection Sort Animations • http://courses.cs.vt.edu/~csonline/Algorithms/Lessons/SelectionCardSort/selectioncardsort.swf • http://www.sorting-algorithms.com/selection-sort • http://en.wikipedia.org/wiki/File:Selection-Sort-Animation.gif • http://www.cosc.canterbury.ac.nz/mukundan/dsal/SSort.html • http://www.cs.oswego.edu/~mohammad/classes/csc241/samples/sort/Sort2-E.html
Selection Sort (Detailed) • The front starts at the beginning • Find (search) for the smallest element from the front to the end • Swap the smallest element with the front element • Advance the front (to ignore it) • Repeat steps 2 through 4
Bubble Sort (Basic) • Start at the beginning • Compare the two adjacent elements to see if they are in the correct order • If not in the correct order, then swap them • Move up one--to the next two adjacent elements (one of which you have already “seen”) • When you hit the end, repeat steps 1-3, but ignore the sorted end (end moves down one)
Bubble Sort Animations • http://upload.wikimedia.org/wikipedia/commons/c/c8/Bubble-sort-example-300px.gif • http://www.sorting-algorithms.com/bubble-sort • http://www.cs.oswego.edu/~mohammad/classes/csc241/samples/sort/Sort2-E.html • http://math.hws.edu/TMCM/java/xSortLab/
Quick Sort • http://en.wikipedia.org/wiki/Quicksort • Pick an element, called a pivot, from the list. • Reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation. • Recursively apply the above steps to the sub-list of elements with smaller values and separately the sub-list of elements with greater values.
Quick Sort Animations • http://en.wikipedia.org/wiki/File:Sorting_quicksort_anim.gif • http://www.sorting-algorithms.com/quick-sort