Sorting by counting :

I cant say this is the best method. But every method has its advantages and disadvantages when used appropriately.

set count[i]=0 for all i from 0 to n-1

for(i=n;i>1;i++) {

for(j=i-1;j>=1;j++) {

if element[i]>element[j] count[i]++;

else count[j]++;

Now we have an auxiliary table within which we have the position of the elements in the sorted list.

Distribution counting sort:

This technique is applicable when we have to sort the numbers which belongs to a small range.

That is all the values to sort should be less than v(upper limit) and greater than u(lower limit) and v-u is small(<10 i="0;i

Thanks

Layman

## No comments:

## Post a Comment