Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C please do the TODO in the code #include #include #include #include const char DATA_FILE_NAME[] = TestData.txt; typedef struct functionRuntimes { char *szName; /ame

in C please do the TODO in the code

#include  #include  #include  #include  const char DATA_FILE_NAME[] = "TestData.txt"; typedef struct functionRuntimes { char *szName; /ame of the function being tested double **arrRuntimes; //run times double *arrAvg; //average runtime int iNumRepeats; /umber of times to repeat each test size int iNumTestCaseSizes; /umber of test case sizes int *arrTestSizes; //array containing the test case sizes } functionRuntimes; //Functions used to test the runtimes functionRuntimes timeAlgorithm( char*, int, int, int[], void (*f)(FILE *) ); FILE *generateTestInput( int, int, int ); void computeAvg( functionRuntimes fRT ); void printRuntimeTable( functionRuntimes fRT ); void freeFunctionRuntimes( functionRuntimes fRT ); //Functions whose runtime will be tested (and helper functions) void insertionSortInitial( FILE* input ); void insertionSort( int* points, int low, int high ); void quickSortOptInitial( FILE* input ); void quickSortOpt( int* points, int low, int high ); int partition( int* points, int low, int high ); void mysteryRuntime1( FILE* input ); void mysteryRuntime2( FILE* input ); void mysteryRuntime3( FILE* input ); /* * Provided code - DO NOT CHANGE THIS METHOD OTHER THAN TO ADD YOUR NAME AND YOUR PARTNER'S NAME * (if you make alterations for the sake of testing be sure to revert them before submission) */ int main( int argc, char *argv[] ) { functionRuntimes fRT; int sizes1[] = { 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 128000, 256000}; /* TODO : Fill in your name */ printf("This solution was completed by: "); printf(" "); srand(time(0)); fRT = timeAlgorithm("Insertion Sort", 6, 5, sizes1, insertionSortInitial ); printRuntimeTable(fRT); freeFunctionRuntimes(fRT); fRT = timeAlgorithm("quicksort (uses insertion sort when sorting 1; n/=1.01 ) { array[n-1] = array[n]; } } free(array); } /* provided code - DO NOT CHANGE */ void mysteryRuntime2( FILE* input ) { int temp; int size; int i=0, j=0; int *array; if( fscanf( input, "%d", &size ) != 1 ) { exit(-1); } array = (int *) malloc( size*sizeof(int) ); if( array == NULL ) { exit(-1); } while( fscanf( input, "%d", &temp ) == 1 && i=size ) { j++; i=0; } } free(array); } /* provided code - DO NOT CHANGE */ void mysteryRuntime3( FILE* input ) { int temp; int size; int i=0; int *array; if( fscanf( input, "%d", &size ) != 1 ) { exit(-1); } array = (int *) malloc( size*sizeof(int) ); if( array == NULL ) { exit(-1); } while( fscanf( input, "%d", &temp ) == 1 && i1 ) { size = size/2; array[size/2] = array[size]; } free(array); } /* * Provided code - DO NOT CHANGE THIS METHOD */ void insertionSortInitial( FILE* input ) { int i; int size; int *array; fscanf( input, "%d", &size ); array = (int *) malloc( size*sizeof(int) ); for( i=0; iarray[i]) { printf("Not sorted!"); exit(-1); } }*/ free(array); } /* * Provided code - DO NOT CHANGE THIS METHOD */ void insertionSort( int* points, int low, int high ) { int i, j; double temp; for( i = low+1; i  low && points[j]array[i]){ printf("Not sorted!"); exit(-1); } }*/ free(array); } /* * Provided code - DO NOT CHANGE THIS METHOD */ void quickSortOpt( int* points, int low, int high ) { if( high =low && points[j] > pivotValue ) { j--; } if(iimage text in transcribedimage text in transcribedimage text in transcribed
Assignment 1: Function Runtimes Table After you have the program completed, you should use it to help determine the asy Completing the Program (15 points) totic runtimes of the three mystery functions (i.e., mysteryRuntime1, mysteryRuntim mysteryRuntime3). This program prints a table of runtimes (these are displayed in seconds) for given functions on arrays. Be sure to also examine the code of the mystery functions to confirm/improve your estis The program tests different array sizes to establish a relationship between input size and tions. runtime. It tests each array size multiple times and then takes an average of the times. We also output how much the average runtime increased relative to the previous average. This Fill in the following table in the provided file: is calculated by dividing the current average by the previous average (output "N/A" for the first increase value). Here are example calls to the timing functions: functionRuntimes fRT; int sizes1[] ={2000,4000,8000,16000,32000,64000,128000,256000}; /* TODO: Give your asymptotic estimates for the runtimes of the following 3 func srand(time (0)); mysteryRuntime1: or ) mysteryRuntime2:mysteryRuntime3:o()o() *J Deliverables: Your solution should be submitted as "runtimeTable.c". Be sure to fill in the runtis fRT = timeAlgorithm("Insertion Sort", 6, 5, sizes1, insertionSortInitial ); described above as well as fill in your name in the "runtimeTable.c" file. printRuntimeTable(fRT); freeFunctionRuntimes(fRT) ; Upload this file to Blackboard under Assignment 1. Do not zip your file. fRT= timeAlgorithm("quicksort", 12, 8, sizes1, quickSort0ptInitial ); To receive full credit, your code must compile and execute. You should use valgrind to ens printRuntimeTable(fRT); that you do not have any memory leaks. freeFunctionRuntimes(fRT); This results in following table: functionRuntimes fRT; int sizes1 []={2000,4000,8000,16000,32000,64000,128000,256000}; srand(time(0)); fRT = timeAlgorithm("Insertion Sort", 6, 5, sizes1, insertionSortInitial ); printRuntimeTable(fRT); freeFunctionRuntimes(fRT); fRT = timeAlgorithm("quicksort", 12, 8, sizes1, quickSortOptInitial ); printRuntimeTable(fRT); freeFunctionRuntimes(fRT); Deliverables: Your solution should be submitted as "runtimeTable.c". Be sure to fill in the runti described above as well as fill in your name in the "runtimeTable.c" file. Upload this file to Blackboard under Assignment 1. Do not zip your file. To receive full credit, your code must compile and execute. You should use valgrind to ens that you do not have any memory leaks. This results in following table: Note your runtimes will vary a bit since the test data is randomly generated. The runtimes are stored in a functionRuntimes struct. You are completing a program to create and fill data in this struct, print the data of this struct, and free this struct. You are given a partial implementation in the file "runtimeTable.c". Specifically you are tasked to complete the functions below the heading "Functions for finding and printing runtime". No other functions should be changed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is a money market fund? Why would it appeal to investors?

Answered: 1 week ago

Question

What factors are involved in group decision making?

Answered: 1 week ago