Question
*PLEASE HELP* (in language C) Compare the execution time for different sorting algorithms.You need to implement one kind of sorting algorithm and compare its execution
*PLEASE HELP* (in language C)
Compare the execution time for different sorting algorithms.You need to implement one kind of sorting algorithm and compare its execution time with that of the qsort function in header file stdlib.h
Both of these two sorting algorithms will do sort on arrays which contain x randomly generated integers where the value of x could be 10000, 20000, 40000 and 80000
The whole process of the program is as follows:
a. Set x = 10000, randomly generate x integers. Call qsort function to sort these
integers and get the execution time.
b. Randomly generate another x integers. Call your own sorting algorithm and get
the execution time.
c. Print the above two execution time on the screen. Program terminates if x =
80000, otherwise set x = x * 2.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HINTS
1. Dynamic memory allocation and deallocation is suggested but not required. You need to check carefully to make sure your own sorting algorithm works fine.
2. The rand() function in header file stdlib.h could be used to generate a random integer.
The sample codes for using the qsort function and measuring the program execution time are listed in three3.c
3. You may implement selection sort, bubble sort or any other existing sorting algorithm for comparison. You do not need to propose a new kind of sorting algorithm. It is totally fine if your own sorting algorithm is slower than qsort.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SAMPLE OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Three3.c
#include
#include
#include
int cmp(const void* p,const void* q)
{
int *p1,*q1;
p1=(int*)p;
q1=(int*)q;
return *p1>*q1;
}
int main()
{
int i,a[]={3,1,2,4,5};
clock_t t1,t2;
qsort(a,5,sizeof(int),cmp);
for(i=0;i
printf("%d ",a[i]);
t1=clock();
for(i=0;i
{
}
t2=clock();
printf(" execution time:%fs",(t2-t1)/((float)CLOCKS_PER_SEC));
return 0;
}
CAUsersyli30Dropboxlsort.exe Size qsort my own sort 10000 0.000000s 0.10900 20s 20000 0.000000s 2.452000s 40000 0.000000s 1.763000s 80000 2.000000s 6.942000s
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started