1 / 12

CS2006 - Data Structures I

CS2006 - Data Structures I. Chapter 10 Algorithm Efficiency & Sorting IV. Topics. Sorting Radix Sort. Radix (Bucket) Sort. Idea: Form groups and then combine them to sort a collection of data Arrange the data according to their rightmost (least significant) letter (value)

yanni
Download Presentation

CS2006 - Data Structures I

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. CS2006 - Data Structures I Chapter 10 Algorithm Efficiency & Sorting IV

  2. Topics • Sorting • Radix Sort

  3. Radix (Bucket) Sort • Idea: • Form groups and then combine them to sort a collection of data • Arrange the data according to their rightmost (least significant) letter (value) • Combine the groups into one • Arrange again according to the next least significant value • Repeat until you reach the most significant value • Restriction • Can work only on certain key types

  4. Radix Sort •  Example: Original Digits 0123 2154 0222 0004 0283 1560 1061 2150

  5.  Radix Sort • Pseudocode radixSort(ItemArray the array, integer n, integer d) // Sorts n d-digit integers in the array theArray for (j = d down to 1) { Initialize 10 groups to empty Initialize a counter for each group to 0 for (i = 0 through n-1) { k = jth digit of theArray[i] Place theArray[i] at the end of group k Increase kth counter by 1 } // end for i Replace the items in theArray with all the items in group 0, followed by all items in group 1, …etc. } // end for j

  6.  Radix Sort • Say that the number of digits in our integers is ‘k’ • The maximum size of an integer is constant • If an unsigned long is 32 bits, then the largest integer is 4 294 967 296 (k=10) • Often even more restricted • Eg. Student number k=7 • F(n) = ? • Why?

  7.  Radix Sort • Say that the number of digits in our integers is ‘k’ • The maximum size of an integer is constant • If an unsigned long is 32 bits, then the largest integer is 4 294 967 296 (k=10) • Often even more restricted • Eg. Student number k=7 • F(n) = kn • We are not comparing the items with each other • Just looking at the digits

  8.  Radix Sort • Analysis: • O(n) • Key size is a factor, but will still be a linear relationship • Constant proportionality(k) may be high • Why not use it all the time?

  9.  Comparison of Sorting Algorithms Sorting Worse case Average Case ------------------------------------------------------------------- Bubble Sort n2 n2 Selection Sort n2 n2 Insertion Sort n2 n2 Mergesort nlogn nlogn Quicksort n2 nlogn Radix Sort n n Treesort n2 nlogn Heap Sort nlogn nlogn

  10.  True or False 1 The analysis of an algorithm must take into consideration the computer that will be used to run a program that implements the algorithm. 2. The values of the growth-rate function O(log2n) grow faster than the values of the growth-rate function O(n).

  11.  True or False • Low-order terms can be ignored in an algorithm’s growth-rate function. • The efficiency of the selection sort depends on the initial arrangement of the data.

  12.  True or False • For large arrays, the insertion sort is prohibitively inefficient. • The mergesort is not a recursive sorting algorithm.

More Related