Counting Sort in Radix Sort

How many passes of counting sort does a base-10 radix sort perform on the following list?

A = [ 0 , 33 , 100 , 2 , 14 , 27 , 101 , 104 , 8 ] A = [0,33,100,2,14,27,101,104,8]


The answer is 3.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Karleigh Moore
May 23, 2016

Radix sort performs a counting sort for each place digit present in the list. There are numbers in the list that have a value in the one’s place, the ten’s place, and the hundred’s place — therefore, there is a maximum of three places of digits that radix sort must sort using the counting sort subroutine.

Another way to think about this is:

104 104 is the largest number in the list, therefore, 104 104 is the k k value. To determine the number of digits needed to represent k k (and therefore, all the numbers less than k k ), use the following formula: d = ( log b ( k ) + 1 ) d = \lfloor(\log_b(k) +1)\rfloor . Plugging in, we get d = ( log 10 ( 104 ) + 1 ) = 3 d = \lfloor(\log_{10}(104) +1)\rfloor = 3 .

The question is incomplete. The number of counting passes depends on the number of digits and the number base you choose to use.

John Hemmer - 3 years, 11 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...