Download presentation
Presentation is loading. Please wait.
Published byNigel Bradford Modified over 9 years ago
1
SORTING
2
Selection Sort (Basic) 1. Find the smallest element 2. Move to the front of the array (swap with front) 3. Repeat Steps 1&2, but ignore the sorted the front area
3
Selection Sort Animations http://courses.cs.vt.edu/~csonline/Algorithms/Lessons/Sel ectionCardSort/selectioncardsort.swf http://courses.cs.vt.edu/~csonline/Algorithms/Lessons/Sel ectionCardSort/selectioncardsort.swf http://www.sorting-algorithms.com/selection-sort http://en.wikipedia.org/wiki/File:Selection-Sort- Animation.gif http://en.wikipedia.org/wiki/File:Selection-Sort- Animation.gif http://www.cosc.canterbury.ac.nz/mukundan/dsal/SSort.ht ml http://www.cosc.canterbury.ac.nz/mukundan/dsal/SSort.ht ml http://www.cs.oswego.edu/~mohammad/classes/csc241/s amples/sort/Sort2-E.html http://www.cs.oswego.edu/~mohammad/classes/csc241/s amples/sort/Sort2-E.html
4
Selection Sort (Detailed) 1. The front starts at the beginning 2. Find (search) for the smallest element from the front to the end 3. Swap the smallest element with the front element 4. Advance the front (to ignore it) 5. Repeat steps 2 through 4
5
Bubble Sort (Basic) 1. Start at the beginning 2. Compare the two adjacent elements to see if they are in the correct order 1. If not in the correct order, then swap them 3. Move up one--to the next two adjacent elements (one of which you have already “seen”) 4. When you hit the end, repeat steps 1-3, but ignore the sorted end (end moves down one)
6
Bubble Sort Animations http://upload.wikimedia.org/wikipedia/commons/c/c8/Bubb le-sort-example-300px.gif http://upload.wikimedia.org/wikipedia/commons/c/c8/Bubb le-sort-example-300px.gif http://www.sorting-algorithms.com/bubble-sort http://www.cs.oswego.edu/~mohammad/classes/csc241/s amples/sort/Sort2-E.html http://www.cs.oswego.edu/~mohammad/classes/csc241/s amples/sort/Sort2-E.html http://math.hws.edu/TMCM/java/xSortLab/
7
Quick Sort http://en.wikipedia.org/wiki/Quicksort 1. Pick an element, called a pivot, from the list. 2. 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. 3. Recursively apply the above steps to the sub-list of elements with smaller values and separately the sub-list of elements with greater values.
8
Quick Sort Animations http://en.wikipedia.org/wiki/File:Sorting_quicksort_anim.gif http://www.sorting-algorithms.com/quick-sort
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.