Question: 3. Using the radix sort algorithm, implement the code below IN PYTHON and add this to the code: generate a list of 100 random numbers

3. Using the radix sort algorithm, implement the code below IN PYTHON and add this to the code: generate a list of 100 random numbers from 1000 possible values. Print the list. Run the algorithm and make sure you show the list after each pass (in other words, if there are, say, three digits max in each number, then your output should show the original list, the list after the units digit is processed, the list after the tens digit is processed, and then the final sorted list.) Commentwill the code run successfully if all of the digits are not the same length? In other words, if I have values of, say, 76 and 124, do I need to make the 76 be represented as 076 or will the code handle it correctly?

Here is the radix sort code:

from llistqueue import Queue

from array import Array

def radixSort( intList, numDigits):

binArray = Array (10)

for k in range(10):

binArray[k]= Queue()

column = 1

for d in range(numDigits):

for key in intList:

digit = (key//column)%10

binArray[digit].enqueue(key)

i = 0

for bin in binArray:

while not bin.isEmpty():

intList[i] = bin.dequeue()

i += 1

column *=10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!