1 / 8

Sorting

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

ponce
Download Presentation

Sorting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sorting

  2. 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

  3. 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

  4. 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

  5. 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)

  6. 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/

  7. 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.

  8. Quick Sort Animations • http://en.wikipedia.org/wiki/File:Sorting_quicksort_anim.gif • http://www.sorting-algorithms.com/quick-sort

More Related