Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code in Python. I'll upload for a completed response. Thanks. This is the completed information. data.txt file could be just a single line of

Please code in Python. I'll upload for a completed response. Thanks. This is the completed information. data.txt file could be just a single line of integers.

image text in transcribed

Consider the following pseudocode for a sorting algorithm, for 0 1. badSort(A0...n-1]) if (n = 2) and (A[0] > A[1]) swap A[0] and A[1] else if (n > 2) m = fa.n] badSort(A[O...m 1]) badSort(A[n m...n-1]) badSort(A0...m - 11) Problem 5. Problem 5.a. (3 points) Implementation: Implement badSort from Problem 4 to sort an array of integers. The value of a should be an input parameter to your program. Implement the algorithm in C/C++. Your program should be able to read inputs from a file called "data.txt", where the first value of each line is the number of integers that need to be sorted, followed by the integers. The output will be written to a file called "bad.out". Problem 5.b. (3 points) Modify code: Modify the code to collect running time data. Call the new timing program badSortTime. 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 a = 2/3 and a = 3/4. You may need to modify the values of n if an algorithm runs too fast or too slow to collect the running time data. Provide a table with the timing data. Problem 5.c. (2 points) Plot data and fit a curve: Plot the running time data you collected for each value of ac {2/3, 3/4} on an individual graph with n on the x-axis and time on the y-axis. You may use Excel, Matlab, R or any other software. How does your experimental running time compare to the theoretical running time of the algorithm? Problem 5.d. (2 points) Comparison: Looking at the plots in the previous step for a 2/3, 3/4}, which a provides better performance? Consider the following pseudocode for a sorting algorithm, for 0 1. badSort(A0...n-1]) if (n = 2) and (A[0] > A[1]) swap A[0] and A[1] else if (n > 2) m = fa.n] badSort(A[O...m 1]) badSort(A[n m...n-1]) badSort(A0...m - 11) Problem 5. Problem 5.a. (3 points) Implementation: Implement badSort from Problem 4 to sort an array of integers. The value of a should be an input parameter to your program. Implement the algorithm in C/C++. Your program should be able to read inputs from a file called "data.txt", where the first value of each line is the number of integers that need to be sorted, followed by the integers. The output will be written to a file called "bad.out". Problem 5.b. (3 points) Modify code: Modify the code to collect running time data. Call the new timing program badSortTime. 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 a = 2/3 and a = 3/4. You may need to modify the values of n if an algorithm runs too fast or too slow to collect the running time data. Provide a table with the timing data. Problem 5.c. (2 points) Plot data and fit a curve: Plot the running time data you collected for each value of ac {2/3, 3/4} on an individual graph with n on the x-axis and time on the y-axis. You may use Excel, Matlab, R or any other software. How does your experimental running time compare to the theoretical running time of the algorithm? Problem 5.d. (2 points) Comparison: Looking at the plots in the previous step for a 2/3, 3/4}, which a provides better performance

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 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

=+Where does the focus of labor relations lie? Is it collective

Answered: 1 week ago

Question

=+With whom does the firm have to negotiate?

Answered: 1 week ago