{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

sorting 4

# sorting 4 - Sorting Analysis Sorts to Consider Selection...

This preview shows pages 1–5. Sign up to view the full content.

Sorting Analysis

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Sorting Analysis 2 Sorts to Consider Selection sort Bubble sort Insertion sort Mergesort Quicksort Radixsort Why do we care about sorting?
Sorting Analysis 3 Selection sort One of the most intuitive sorts Find the largest item, and swap it with the item currently in the last position. Repeat this step on the “unsorted” part of the collection. initial array : 29 10 14 37 13 after 1st swap: 29 10 14 13 37 after 2nd swap: 13 10 14 29 37 after 3rd swap: 13 10 14 29 37 after 4th swap: 10 13 14 29 37 Algorithm: for (last = n-1; last >= 1; --last) { find the index of the largest item swap the largest item with the last item } Order of magnitude = O(n 2 )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Sorting Analysis 4 Bubble sort Not a particularly good algorithm, but simple. Compare adjacent items and exchange them if they are out of order. Repeat. The largest item will eventually “bubble” to the correct position. Pass 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

sorting 4 - Sorting Analysis Sorts to Consider Selection...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online