part 2 in c programming part 3 sketch the graphSolution2 inc
Solution
2)
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
int main() {
//declaring array with different size
struct timeval stop, start;
int numbers1[1000], numbers2[10000], numbers3[65000];
float countingSort[3],radixSort[3],bucketSort[3];
int i;
/*filling arrays with random numbers*/
/* filling first array*/
for(i=0;i<1000;i++){
numbers1[i] = rand() % 1000 + 1;
}
/* filling second array*/
for(i=0;i<10000;i++){
numbers2[i] = rand() % 10000 + 1;
}
/* filling first array*/
for(i=0;i<65000;i++){
numbers3[i] = rand() % 65000 + 1;
}
// calling functions..
gettimeofday(&start, NULL);
countingSortfun(numbers1,1000);
gettimeofday(&stop, NULL);
countingSort[0] = stop.tv_usec - start.tv_usec;
printf(\"For 1000 numbers counting sort takes: %lu\ \", stop.tv_usec - start.tv_usec);
gettimeofday(&start, NULL);
radixSortfun(numbers1,1000);
gettimeofday(&stop, NULL);
radixSort[0] = stop.tv_usec - start.tv_usec;
printf(\"For 1000 numbers radix sort takes: %lu\ \", stop.tv_usec - start.tv_usec);
gettimeofday(&start, NULL);
bucketSortfun(numbers1,1000);
gettimeofday(&stop, NULL);
bucketSort[0] = stop.tv_usec - start.tv_usec;
printf(\"For 1000 numbers bucket sort takes: %lu\ \", stop.tv_usec - start.tv_usec);
gettimeofday(&start, NULL);
countingSortfun(numbers2,10000);
gettimeofday(&stop, NULL);
countingSort[1] = stop.tv_usec - start.tv_usec;
printf(\"For 10000 numbers counting sort takes: %lu\ \", stop.tv_usec - start.tv_usec);
gettimeofday(&start, NULL);
radixSortfun(numbers2,10000);
gettimeofday(&stop, NULL);
radixSort[1] = stop.tv_usec - start.tv_usec;
printf(\"For 10000 numbers radix sort takes: %lu\ \", stop.tv_usec - start.tv_usec);
gettimeofday(&start, NULL);
bucketSortfun(numbers2,10000);
gettimeofday(&stop, NULL);
bucketSort[1] = stop.tv_usec - start.tv_usec;
printf(\"For 10000 numbers bucket sort takes: %lu\ \", stop.tv_usec - start.tv_usec);
gettimeofday(&start, NULL);
countingSortfun(numbers3,65000);
gettimeofday(&stop, NULL);
countingSort[2] = stop.tv_usec - start.tv_usec;
printf(\"For 65000 numbers counting sort takes: %lu\ \", stop.tv_usec - start.tv_usec);
gettimeofday(&start, NULL);
radixSortfun(numbers3,65000);
gettimeofday(&stop, NULL);
radixSort[2] = stop.tv_usec - start.tv_usec;
printf(\"For 65000 numbers radix sort takes: %lu\ \", stop.tv_usec - start.tv_usec);
gettimeofday(&start, NULL);
bucketSortfun(numbers3,65000);
gettimeofday(&stop, NULL);
bucketSort[2] = stop.tv_usec - start.tv_usec;
printf(\"For 65000 numbers bucket sort takes: %lu\ \", stop.tv_usec - start.tv_usec);
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------
3) By executing above program, with timings we can plot graph easily.

