Data Structures

PA 05

Improving the Time-efficiency of the Radix Sort


Due by Friday, October 30th at the start of class


The introduction

IN PA04 we considered the Radix sort.  In that assignment we looked at iteratively sorting the numbers into "bins" (represented by a queue) based on the value of a given digit from each number, and then reassembling a master list from the values in these bins.  We discussed in class that there was some time overhead in reassembling this master list because you have to move each of the n items being sorted from their bins into the master queue and in PA04 this was done by moving each item one at a time.  Thus, each pass through the data took 2N operations (one set of N to move the values into their bins, and another set of N to move the values back into the master queue).

Yet, when I describe this sort to you in class I talk about picking up bin 0 and putting it's cards into the master queue - one operation.  Then picking up bin 1 and putting all of it's cards into the master queue - one operation.  In other words, I describe taking only ten operations to move the 10 bins back to the master queue, regardless of how big the value of n.

The way to do this in code is to use bins which are represented by queues using linked nodes as we did in Lab09.  In this assignment you will write such a sort and test it's efficiency.


Before you start:

To complete this assignment you must use the LinkedQueue class defined in linkedQueue.py

If you had problems getting PA04 to work properly you may want to check out my solution (PA04.py)


Part A

Again, you should do this by using your linked representation of the queue. 

The data above is clearly Bin 6 after processing the ones digit.  What you need to figure out is how you can move this to the end of the main Bin and then move Bin 7 to the end of this queue/bin without moving each of the items individually.  Furthermore, you need to figure out how to then tell bin 6 that it is now empty (that is, both front and rear should be marked as None.


Part B

For example, to use this you might type:

  >>> aList = range(100000)
  >>> import random
  >>> random.shuffle(aList)
  >>> radixTimer(aList)
  It took 14.334 seconds to sort 100000 items using the linked queue.
  It took 7.982 seconds to sort 100000 items using the list based queue.
  

By the way,  if you get different times, no problem.

Finally, you should run this code with several different sets of data (I would suggest trying each of the powers of 10 from 10 to 100,000)  and observe the differences between these two implementations of the Radix Sort.


Submitting your assignment

To get full credit for this assignment you must: