CS506 (2023-I) Lab Exercise 1
CS506 (2023-I) Lab Exercise 1
Purpose of this lab is to implement and analyse time complexity of different comparison-based
sorting algorithms.
Prog. Language C
Input:
First line will have positive number T that will tell you the number of each test case. This will be
followed by T lines (or say, rows), each indicating an independent test case.
Currently for today, consider each test case entry to have four non-negative numbers: N, S, k
and p,
where N indicates number of elements to be there in array (i.e. N is considered as input array
size)
S indicates which sorting algorithm to be implemented.
S will be either 0,1,2,3 or 4 (0 Bubble, 1 Selection , 2 Insertion, 3 Merge, 4 Quick)
k and p will be either 0, 1 or 2.
For k, 0=> Array elements are in random order, 1 indicates Input array is already sorted
and 2 indicates that input array is reversely sorted).
For p, 0=> Neither print input array nor output array, 1 indicates that you also print
output array elements (max. 50 elements to be printed if corresponding N is more than
50) and 2 indicates that the code prints both input and output array elements (only at
most first 50 elements of each) You may note is p=1, then there will be 2T output rows.
And if p=2, then there will be 3T output rows.
Else (for p=0), there will be T output rows/ lines where each line indicates the time
taken by the sorting algorithm to sort the elements in non-decreasing order.
Constraints:
0< N < 10000 (This constraint is for our testing, for your analysis you may use higher N)
S will be either 0,1,2,3 or 4 (0 Bubble, 1 Selection , 2 Insertion, 3 Merge, 4 Quick)
k and p will be either 0, 1 or 2
Note:
- Google form for submitting assignment code and Comparative analysis report will be
provided soon and Deadline for submission is 5th-Aug midnight.
- For analysis, it is preferred that you have graphs showing comparative
performance. Few graphs, if required for some reason, can be for single sorting
algo/case.
=====================================================
Following code might be helpful to you in lab assignment. I have also checked it on
https://www.onlinegdb.com/online_c_compiler
=======================================================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void){
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime(&rawtime);
printf("Current local time and date: %s", asctime (timeinfo) );
int n,num=5;
double total_time_consumed,t1,t2,t3;
printf("\n Time Consumed when n=%d => %f \t %f \t %f",n, t1, t2, t3);
}
return 0;
}