Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are required to choose two sorting algorithms from a specified list: ( P . S . Please use merge sort instead of Heap sort
You are required to choose two sorting algorithms from a specified list: PS Please use merge sort instead of Heap sort for the second algorithm, also the skeleton code to be used will be at the end of the question
the first algorithm must be Bubble Sort, while the second algorithm can be either Merge Sort or Heap Sort.
a Write a C program where you implement the two sorting algorithms you have chosen ensure that they are part of the same program and can be called using methods, functions andor procedures.
b Continue in this C program and generate random input arrays of different sizes, specifically and elements.
c Utilize the implemented TWO sorting algorithms to sort these randomly generated arrays.
d Generate a report to indicate:
The input size number of elements
The execution time for the two different sorting algorithms.
The time complexity formulas for the two different sorting algorithms.
Typical output:
Input Size:
XXXXXX Sort:
Execution Time: seconds
YYYYY Sort:
Execution Time: seconds
Input Size:
XXXXXX Sort:
Execution Time: seconds
YYYY Sort:
Execution Time: seconds
Input Size:
XXXXXX Sort:
Execution Time: seconds
YYYYY Sort:
Execution Time: seconds
The time complexity formula for XXXXX: Give the formula
The time complexity formula for YYYY: Give the formula
SKELETON CODE TO BE USED BELOW:
#include
#include
#include "COSAsPh
using namespace std;
Function for the first sorting algorithm
Function for the second sorting algorithm
Function to generate a random array of a given size
vector generateRandomArrayint size
vector arrsize;
srandtime;
for int i ; i size; i
arri rand; adjust the range to play around with it
return arr;
generateRandomArray
you can make this more code efficient did it this way for more clarity purposes
void measureSortingTimeFirstSortingAlgorithmvector& arr, double& timeExecuted, double& timeComplexity
measure start time
clockt startTime clock;
Call your first sorting algorithm
measure end time
clockt endTime clock;
calculate executation time in secods for first sorting algorithm
timeExecuted endTime startTime CLOCKSPERSEC;
calculate time comlexity for your sorting algorithm
timeComplexity ; this will then be the time complexity you must provide the code
measureSortingTimeFirstSortingAlgorithm
void measureSortingTimeSecondSortingAlgorithmvector& arr double &timeExecuted, double &timeComplexity
measure start time
clockt startTime clock;
Call your second algortihm
measure end time
clockt endTime clock;
calculate executation time in secods for first sorting algorithm
timeExecuted endTime startTime CLOCKSPERSEC;
calculate time comlexity for your sorting algorithm
timeComplexity ; this will then be the time complexity you must provide the code
measureSortingTimeSecondSortingAlgorithm
int main
cout "COS Assessment Project Skeleton
;
cout "ARRAYS";
generate an array with random elements
double timeExecuted timeExecuted;
double timeComplexity timeComplexity;
vector inputSizes ;
for int size : inputSizes
vector arr generateRandomArraysize;
measure the sorting time for sorting algorithm
measureSortingTimeFirstSortingAlgorithmarrtimeExecutedtimeComplexity;
measureSortingTimeSecondSortingAlgorithmarrtimeExecutedtimeComplexity;
The display of your results will go here.
return ;
main
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