Question: Use the 10 generated arrays from the code below to give as the input to your six sorting functions (heap, merge, insertion, bubble, selection, and

Use the 10 generated arrays from the code below to give as the input to your six sorting functions (heap, merge, insertion, bubble, selection, and quick) and measure the duration of each function. Comment the statements you used to print the sorted array after each sorting function, as you need to measure only the time taken to sort. The output of each sort is the time taken in milliseconds to sort the given unsorted array. You can use "#include " or "#include" to measure the duration of a function in C++. While measuring the time you only need to measure the time taken by each sorting algorithm to convert the unsorted array into a sorted array. Note: The additional time taken, such as to construct your input unsorted array and to print your sorted array to console should not be included while measuring the duration of the sort.

Update: These are the steps taken before this question:

1. Write six functions to code for the following six sorting algorithms in C++. Make your own header files to declare all the functions you need to implement each of these sorting algorithms. For example, for quicksort, you will have a header file such as "quicksort.h", in which you will declare all the functions that you need to perform quicksort. Then you will include these header files in your main cpp program, in which you will implement and call all these functions. The input to all these sorts is the array of unsorted integers, the size of the array, and if required the start and end variables. The output of each of these sorts is the sorted array of integers printed on the console. Test these sorts with the unsorted array - A [89, 373, 1, 783, 23, 987, 12, 65, 28, 17].

a. Selection Sort

b. Bubble Sort

c. Insertion Sort

d. Merge Sort

e. Quick Sort

f. Heap Sort

2. Write a function to generate 10 unique dataset files of unsorted integers separated by a comma ",". E.g., 34, 32421, 124124, 67, 92, ... The sizes of these 10 datasets are (n) - 1000, 4000, 8000, 10000, 40000, 80000, 100000, 400000, 800000, 1000000. Generate random integers between 0 to 1,000,000 as the elements of each dataset. This function does not take any input arguments. This function generates and saves 10 ".txt" files. The output of this function is just a print statement to console that file generation completed.

3. Write a function to read the data from the above-generated files and construct 10 unsorted arrays. This function does not take any input arguments. This function declares 10 arrays of sizes sufficient to store the content of the above-generated files and constructs these arrays by reading these files. The output of this function is just a print statement to console that unsorted array generation completed.

#include #include using namespace std; // function read data which reads 10 files void readData(){ const int MAX_SIZE = 1000; // declare the max size with 1000, you can modify it if the size is large // declare 10 file objects and 10 corresponding arrays of max size to store ifstream file0,file1,file2,file3,file4,file5,file6,file7,file8,file9; int arr0[MAX_SIZE],arr1[MAX_SIZE],arr2[MAX_SIZE],arr3[MAX_SIZE],arr4[MAX_SIZE],arr5[MAX_SIZE],arr6[MAX_SIZE],arr7[MAX_SIZE],arr8[MAX_SIZE],arr9[MAX_SIZE]; // reading first file, c is denoting the starting index to fill the value int temp; // make a temp variable to read from file int c = 0; file0.open("dataset0.txt"); // open the first file while(file0 >> temp){ // read the file and store the value to temp until eof arr0[c++] = temp; // store the value at first array at index c and increment the c } // do the same for remaining file and their corresponding arrays c = 0; file1.open("dataset1.txt"); while(file1 >>temp){ arr1[c++] = temp; } c = 0; file2.open("dataset2.txt"); while(file2 >>temp){ arr2[c++] = temp; } c = 0; file3.open("dataset3.txt"); while(file3 >>temp){ arr3[c++] = temp; } c = 0; file4.open("dataset4.txt"); while(file4 >>temp){ arr4[c++] = temp; } c = 0; file5.open("dataset5.txt"); while(file5 >>temp){ arr5[c++] = temp; } c = 0; file6.open("dataset6.txt"); while(file6 >>temp){ arr6[c++] = temp; } c = 0; file7.open("dataset7.txt"); while(file7 >>temp){ arr7[c++] = temp; } c = 0; file8.open("dataset8.txt"); while(file8 >>temp){ arr8[c++] = temp; } c = 0; file9.open("dataset9.txt"); while(file9 >>temp){ arr9[c++] = temp; } cout<<"Unsorted array generation completed!"<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!