## Description

- (4 pts) For each of the following pairs of functions, select the best relationship from the

options: f(n) is O(g(n)), f(n) is Ω(g(n)), or f(n) is Θ(g(n))

a. | f(n) = n^{0.25}; |
g(n) = n^{0.5} |
||

b. | f(n) = log n^{2}; |
g(n) = lg n | ||

c. | f(n) =log logn | g(n) = log n | ||

d. | f(n) = 5000n^{3}+n^{2} |
g(n) = 0.000001n^{4} |
||

^{ } |
g(n) =n√ |
|||

e. | f(n) = nlogn + n; | |||

f. | f(n) = e^{n}; |
g(n) = 2^{n} |
||

g. | f(n) = 2^{n}; |
g(n) = 2^{n+1} |
||

h. | f(n) = n^{n}; |
g(n) = n! |

- (6 pts) Determine the theoretical running time of the following algorithms. Use theta notation and give a brief explanation.

a.

b.

**CS 325 HW 1 – 30 points**

** **

c.

- (10 pts)
**Merge Sort and Insertion Sort Programs**

Implement merge sort and insertion sort to sort an array/vector of integers. You may implement the algorithms in C, C++, Java or Python, name the programs “mergesort” and

“insertsort”. Your programs 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.

Example values for data.txt: 4192511

812345612

The output will be written to files called “merge.txt” and “insert.txt”. For the above example the output would be:

251119

11223456

*Note: All code must be commented. To receive full credit*

*Submit to TEACH (in a ZIP file) copy of all your code files and a README file that explains how to compile and run your code on the Flip servers. We will test execution with an input file named data.txt.*

**CS 325 HW 1 – 30 points**

- (10 pts)
**Merge Sort vs Insertion Sort Running time analysis**

__Modify code__– Now that you have verified that your code runs correctly using the data.txt input file, you can modify the code to collect running time data. 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 ten different values of n for example: n = 5000, 10000, 15000, 20,000, …, 50,000. You may need to modify the values of n if an algorithm runs too fast or too slow to collect the running time data (do not collect times over a minute). Output the array size n and time to the terminal. Name these new programs insertTime and mergeTime.

*Submit a copy of the timing programs to TEACH in the Zip file from problem 3.*

* *

__Collect running times__– Collect your timing data on the engineering server. You will need at least eight values of t (time) greater than 0. If there is variability in the times between runs of the same algorithm you may want to take the average time of several runs for each value of n. Create a table of running times for each algorithm.

__Plot data and fit a curve__– For each algorithm plot the running time data you collected 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. What type of curve best fits each data set? Give the equation of the curves that best “fits” the data and draw that curves on the graphs.

__Combine__– Plot the data from both algorithms together on a combined graph. If the scales are different you may want to use a log-log plot.

__Comparison__– How does your experimental running times compare to the theoretical running times of the algorithms?