Documente Academic
Documente Profesional
Documente Cultură
STATEMENT:
In ‘Radix Sort’, sorting operation is carried out by means of distribution based on the
constituent components in the elements. This is why the sorting method is called sorting by
distribution. Sorting without key comparison-this feature makes this sorting algorithm
distinguished from others type of sorting. This sorting technique is based on radix or base
of constituent elements in keys so it is called ‘Radix Sort’.
Step 1.1: Set or initialise the all elements of an integer type array ‘d’ at 0 i.e
Set d[i] 0 [ i= 0 to 9]
Step 1.2: Take the max number of digit in an integer type variable ‘max’ and this is
the number of required pass to do the sorting.
Step 1.3: While(pass ≤ max) then repeat Step 1.4 to Step 1.22
Step 1.4: For i=0 to i<n repeat Step 1.5 to Step 1.13
Step 1.18: For k=0 to k<d[j] repeat Step 1.19 and Step 1.20
[End of ‘If’]
Step 2.1 Take the number of elements from the user in an integer type variable ‘n’ .
Step 2.2: Take the unsorted elements from the user in an array ‘a’.
Step 3: Stop.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
#define NULL 0
//*Creation of the function 'radixsort()' to sort an unsorted array using radix sort
technique*//
int i,b[20][20],pass=1,c,max,p,r,d[10],j,k;
for(i=0;i<10;i++)
d[i]=NULL;
scanf("%d",&max);
while(pass<=max)
for(i=0;i<n;i++)
c=0;
p=a[i];
while(c<pass)
r=p%10;
p=p/10;
c++;
j=d[r];
b[r][j]=a[i];
d[r]=d[r]+1;
pass++;
i=0;
for(j=0;j<10;j++)
{
if(d[j]>0)
for(k=0;k<d[j];k++)
a[i]=b[j][k];
i++;
for(i=0;i<10;i++)
d[i]=NULL;
void main()
int n,a[20],i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
printf("%d->",a[i]);
radixsort(a,n);
for(i=0;i<n;i++)
printf("%d->",a[i]);
getch();
OUTPUT:
DISCUSSION:
The runtime complexity of the radix sort algorithm is O(n) i.e the time complexity of radix
sort algorithm is O(n). The run time of the radix sort algorithm is mainly due to two
operations: distribution of key elements and followed by a combination. It can be easily
checked that the run time remains invariant irrespective of the order of the elements in the
list.