Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sorting.

Similar presentations


Presentation on theme: "Sorting."— 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

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

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


Download ppt "Sorting."

Similar presentations


Ads by Google