Question: PROBLEM 2: Typically, Radix Sort designed/implemented using two two arrays of lists (or queues): a from array and a to array (the dimension of each

 PROBLEM 2: Typically, Radix Sort designed/implemented using two two arrays of

lists (or queues): a "from" array and a "to" array (the dimension

of each array is the radix being used) At the start of

each pass, the elements are distributed among the lists in the from

array; as they are processed they are moved to the to array

PROBLEM 2: Typically, Radix Sort designed/implemented using two two arrays of lists (or queues): a "from" array and a "to" array (the dimension of each array is the radix being used) At the start of each pass, the elements are distributed among the lists in the from array; as they are processed they are moved to the to array In the sample implementation discussed in class a single pass is performed by the code segment below. Code for 1-pass of Radixsort using conventional 2-array approach 1 for (io; ipop-front(x); digit = (x/divisor)%radix; to[digit]->push_back(x); Professor Periwinkle thinks that just one array of dimension radix is sufficient and proposes the following code instead to perform a single pass with just one array called buckets of dimension radix Prof. Periwinkle's code for 1-pass of RadixSort using just one array int len 1 2 for( 3 4 5 6 ilength ( ); // list length before processing elems for (j o jpop-front(x); / x is popped digit = (x/divisor)%radix; buckets[digit]->push_back(x); / same array The first thing you notice is that the condition for the innermost loop has changed (lines 4-8). You figure out that this change prevents infinite loops, because buckets[i] might never become empty (like from i] does in the 2-array approach). Consider for example x 33 and radix 10. During the 2nd pass buckets [3] will never become empty! This explains why variable len set on line 3 is used to determine the number of iterations through the innermost loop So far so good. It doesn't loop forever. Big deal

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!