1 / 8

More Sorting

More Sorting. Radix Sort Relies on a stable sorting algorithm (for example counting sort). Radix Sort. Sort an array of numbers Example: { 329, 457, 657, 839, 436, 720, 355 } If we look the digits for any number (ones, tens, hundreds), they are between 0 and 9. Radix Sort.

mikkel
Télécharger la présentation

More 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. More Sorting Radix SortRelies on a stable sorting algorithm (for example counting sort)

  2. Radix Sort • Sort an array of numbers • Example: { 329, 457, 657, 839, 436, 720, 355 } • If we look the digits for any number (ones, tens, hundreds), they are between 0 and 9

  3. Radix Sort • An y digit is between 0 and 9 •  that sets up well for using counting sort (with k = 9) one digit at a time

  4. Radix Sort • Strategy: • Step 1: Sort numbers based on ones digit • Step 2: Sort numbers based on tens digit • Step 3: Sort numbers based on hundreds digit • ….continue if necessary

  5. Radix Sort

  6. Radix Sort • Using a stable sorting algorithm is important: • If we did not and we have, after sorting on 1s: • 456 • 457 • When we sort on 10s (they both have a 5), they could end up inverted

  7. Radix Sort • Running time analysis: • Number of numbers to sort = n • Number of digits per number = d • If we have numbers with different numbers of digits, take the biggest as the standard, pad the other ones with 0s: 7865, 0056, 0341, ..

  8. Radix Sort • We loop through all the digits from right to left ( d iterations) • For each digit, we run counting sort  O( n + k ) if k is the number of possible digits (10 if numbers are decimal) •  O( d ( n + k ) )

More Related