Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For learning purposes I'd like to see if anyone could help me on this. I'd like to study it (this uses C and the only

For learning purposes I'd like to see if anyone could help me on this. I'd like to study it (this uses C and the only parts that have to be worked are labeled as TODO)image text in transcribedimage text in transcribed

#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[] = { 2000, 4000, 8000, 16000, 32000, 64000, 128000, 256000}; /* TODO : Fill in you and your partner's names (or N/A if you worked individually) */ printf("This solution was completed by: "); printf(" "); 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(i  Completing the Program (15 points) This program prints a table of runtimes (these are displayed in seconds) for given functions on arrays. The program tests different array sizes to establish a relationship between input size and 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 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}; srand(time(0)); fRT = timeAlgorithm ("Insertion Sort", 6, 5, sizesi, insertionSortInitial ); printRuntimeTable(fRT); freeFunctionRuntimes (fRT); fRT = timeAlgorithm ("quicksort", 12, 8, sizes1, quickSortOptInitial ); printRuntime Table (fRT); freeFunctionRuntimes (fRT); This results in following table: Test #2 0.008 0.030 0.119 0.471 1.902 Test 13 0.007 0.038 0.119 0.476 1.926 Test 4 0.008 0.030 0.119 Test 4 0.008 0.030 0.120 0.475 1.917 Test 6 0.008 0.030 0.129 0.476 1.981 Average 0.008 0.030 0.119 0.476 1.924 Increase N/A 3.950 3.939 3.985 4,043 1.895 1.922 Insertion Sort Test size Test 1 2000 8.008 4000 8.031 3000 8.120 16000 0.484 32000 quicksort Test size Test el 2000 0.000 2000 0.002 16000 32000 0.004 0.008 64000 0.017 128000 0.035 256000 0.076 Test 48 Test #11 0.000 Test #7 0.000 0.001 4000 Test 26 0.000 0.001 0.002 0.001 Test #12 0.000 0.002 Test #S 0.000 0.001 0.002 0.004 0.000 0.001 0.002 Test #2 0.000 0.001 0.002 0.008 0.016 0.034 0.071 0.666 Test #3 0.000 0.001 0.002 0.004 0.000 0.017 0.034 0.071 Test 4 0.000 0.001 0.002 0.008 0.016 0.035 0.071 0.004 0.002 0.004 Test 29 0.000 0.001 0.002 0.004 0.008 0.016 0.034 0.072 0.004 0.008 Test 10 0.000 0.001 0.002 0.004 0.008 0.016 0.034 0.071 0.002 0.004 0.001 0.002 0.004 0.008 0.016 0.034 0.071 2.124 Average 0.000 0.001 0.002 0.004 0.008 0.016 0.034 0.071 0.008 Increase N/A 2.027 2.055 2.071 2.100 2.036 2.076 0.016 0.034 0.071 0.004 0.006 0.016 0.034 0.071 0.008 0.016 0.034 0.071 0.018 0.035 0.070 0.008 0.016 0.034 0.071 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 "runtime Table.c. Specifi- cally you are tasked to complete the functions below the heading "Functions for finding and printing runtime. No other functions should be changed. Using the Program (5 points) After you have the program completed, you should use it to help determine the asymptotic runtimes of the three mystery functions (i.e., mysteryRuntimel, mysteryRuntime2, mystery Runtime3). Be sure to also examine the code of the mystery functions to confirm/improve your estimations. Fill in the following table in the provided file: /* TODO: Give your asymptotic estimates for the runtimes of the following 3 functions: mysteryRuntime1: 00) mysteryRuntime: 0 ) mysteryRuntime3:00) */ Deliverables: Your solution should be submitted as "runtime Table.c". Be sure to fill in the

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

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions