Using C Modify Code Collect Running Time Data Call New Timing Program Badstoogesort Instea Q43899135
Using C++ Modify the code to collect running time data. Call the new timing program badStoogeSort. Instead of reading arrays from the file data.txt and sorting, you will now generate arrays of size n containing random integer values from 0 to 10,000 to sort. Use the system clock to record the running times of each algorithm for n = 5000, 10000, 15000, 20,000, …. for two values of α = 2/3 and α = 3/4. You may need to modify the values of n if an algorithm runs too fast or too slow#include <iostream>#include <string>#include <fstream>#include <cmath>using namespace std;/*our base case for the sorting will be when there are only 2 elementsif we meet that condition we compare the 2 elements and perform a swap operation if neededelse we perform a recursive call on 2/3 of the size of the arraywe are creating 3 sub problems1 focuses on the initial 2/3rd of our data the other will focus on the other 2/3rd of our dataAnother way to visualize it is we analyze 2/3rd from our starting point firstwe them analyze 2/3rd from our end pointour last recursive call is to analyze the initial 2/3rd againwe continue until we only have 2 elements than we swap if needed and trace back to the callsstill follows the divide and conquer rules.we divide into 2/3rdswe conquer by swapping first and last elements of a subproblems*/void stoogeSort(int arr[], int start, int end){ int size = end – start+1; // base case when there are only 2 elements if (size == 2) { // condition to check if we need to perform a swap operation if (arr[start] > arr[end]) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; } } else if (size > 2) { // here we get the index value that represents our focal point // you can view this as our midpoint but instead of half we are focused with what index falls at 2/3rds of our array int point = size/3; // we recursively sort the first 2/3rd stoogeSort(arr, start, end – point); // here we do the second 2/3rd stoogeSort(arr, start+point, end); // we perform another recursion on the first 2/3rd again to verify // this repeated call is in the case if there was a swap that took place in the second call stoogeSort(arr, start, end – point); }}int main(){ ifstream readFile(“data.txt”); ofstream outputFile(“stooge.out”); while (!readFile.eof()) { int size; int* list; // getting the number of elements readFile >> size; // allocating enough room for our dynamic array list = new int[size]; // getting the elements for our dynamic array int temp; for (int x = 0; x < size; x++) { readFile >> temp; list[x] = temp; } // Sorting our values stoogeSort(list, 0, size-1); // writing the result to the insert.out file for (int x = 0; x < size; x++) { outputFile << list[x] << ” “; } outputFile << endl; // deallocation delete[] list; } // closing our file streams readFile.close(); outputFile.close(); return 0;}
Expert Answer
Answer to Using C++ Modify the code to collect running time data. Call the new timing program badStoogeSort. Instead of reading a…
OR