Question
SortHelper.h : #pragma once #include #include #include #include using namespace std; namespace SortHelper { /*generate an array of n integers and every integer is in
SortHelper.h :
#pragma once #include
using namespace std;
namespace SortHelper { /*generate an array of n integers and every integer is in the range [rangeL, rangeR] */ int* generateRandomArray(int n, int min, int max) { int *arr = new int[n]; srand(time(NULL)); for (int i = 0; i void printArray(T arr[], int n) { for (int i = 0; i bool isSorted(T arr[], int n) { for (int i = 0; i arr[i + 1]) { cout void timing(string sortAlgorithm, void(*Sort)(T[], int), T arr[], int n) { clock_t startTime = clock(); Sort(arr, n); clock_t endTime = clock(); assert(isSorted(arr, n)); cout
main.cpp:
#include
/*To fill merge function to merge sorted sublists arr[l, l+1, ..., mid] and arr[mid+1, mid+1, ..., r] such that arr[] is sorted at the end.*/ template
template
template
/*To fill the partition function: pick arr[L] as the pivot and reorder arr[] such that all numbers before pivot in arr[] are smaller and all other behind it are larger. return the index of pivot after partition. */ template
}
//Apply quick sort on the subarray arr[l, l+1, ..., r-1, r] of arr[] template
template
/*To fill count sort function it applies counting sort on arr[] according to the d-th digit;*/ template
/*o fill radix sort function. Apply radix sort sorts arr[] of size n*/ template
int main() { int n = 10000; if (n==0) { cout 1 Introduction In this homework, you will implement three sorting algorithms, and then test their efficiency (running time). This assignment will consist of not only coding, but also testing your code on large data set. The three sorting algorithms to implement are Merge Sort, Quick Sort and Radix Sort. Note that to realize Radix Sort, a function of counting Sort by digits is needed to be implemented firstly. 2 Instructions The following files have been given to you: 1. A C++ header file (SortHelper.h) declaring a namespace SortHelper of functions. 2. A C++ source file (main.cpp containing a main function with tests. Download the files on blackboard. In Sort Helper.h, there are several functions which are creating a data set of the given size, measuring the running time of any given function in milliseconds, checking whether the array is sorted, etc. In main.cpp, you need to implement the three sorting algorithms and test the efficiency of each sorting function. Please read the instruction in the main.cpp carefully. Efficiency Test: After you have correctly implemented the sorting algorithms, executing the main func- tion, you will see how long each sorting function takes to run on both random and sorted inputs. Please test each algorithm on both random and sorted input of different sizes: 5000, 10000, 25000, 50000, 75000, 100000, 250000, 500000, 750000 and 10000000. You will get a list of running time in milliseconds. (The timing() function in Sort Helper is to test the speed of an given function.) 3 What to submit You need to submit the following files via blackborad. 1. A C++ source file (main.cpp containing a main function with tests. 2. A pdf file contains a table of running times for three algorithms on random and sorted arrays of sizes 5000, 10000, 25000, 50000, 75000, 100000, 250000, 500000, 750000 and 10000000, and two charts to statistic the efficiency. The first chart is for running times of three algorithms on random arrays of the above different sizes, while the second chart is for sorted arrays. In addition, your observation, discussion and comments about the efficiency should be included. 1 Introduction In this homework, you will implement three sorting algorithms, and then test their efficiency (running time). This assignment will consist of not only coding, but also testing your code on large data set. The three sorting algorithms to implement are Merge Sort, Quick Sort and Radix Sort. Note that to realize Radix Sort, a function of counting Sort by digits is needed to be implemented firstly. 2 Instructions The following files have been given to you: 1. A C++ header file (SortHelper.h) declaring a namespace SortHelper of functions. 2. A C++ source file (main.cpp containing a main function with tests. Download the files on blackboard. In Sort Helper.h, there are several functions which are creating a data set of the given size, measuring the running time of any given function in milliseconds, checking whether the array is sorted, etc. In main.cpp, you need to implement the three sorting algorithms and test the efficiency of each sorting function. Please read the instruction in the main.cpp carefully. Efficiency Test: After you have correctly implemented the sorting algorithms, executing the main func- tion, you will see how long each sorting function takes to run on both random and sorted inputs. Please test each algorithm on both random and sorted input of different sizes: 5000, 10000, 25000, 50000, 75000, 100000, 250000, 500000, 750000 and 10000000. You will get a list of running time in milliseconds. (The timing() function in Sort Helper is to test the speed of an given function.) 3 What to submit You need to submit the following files via blackborad. 1. A C++ source file (main.cpp containing a main function with tests. 2. A pdf file contains a table of running times for three algorithms on random and sorted arrays of sizes 5000, 10000, 25000, 50000, 75000, 100000, 250000, 500000, 750000 and 10000000, and two charts to statistic the efficiency. The first chart is for running times of three algorithms on random arrays of the above different sizes, while the second chart is for sorted arrays. In addition, your observation, discussion and comments about the efficiency should be included
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