**Problem 1: Asymptotic Analysis **

Considering the following pairs of functions f and g, show for each pair whether *f *∈ Θ(*g*), *f *∈ *O*(*g*), *f *∈*o*(*g*), *f *∈ Ω(*g*), *f *∈*ω*(*g*), *g*∈ Θ(*f*), *g*∈*O*(*f*), *g*∈*o*(*f*), *g*∈ Ω(*f*), or *g*∈*ω*(*f*).

*f*(*n*) = 3*n*and*g*(*n*) =*n*^{3}.

√

*f*(*n*) = 7*n*^{0.7 }+ 2*n*^{0.2 }+ 13log*n*and*g*(*n*) =*n*.*f*(*n*) =*n*^{2}*/*log*n*and*g*(*n*) =*n*log*n*.*f*(*n*) = (log(3*n*))^{3 }and*g*(*n*) = 9log*n*.

**Problem 2: Selection Sort **

In class, we discussed Insertion Sort. Selection Sort is similar to Insertion Sort and works as follows. Given an array of elements, you always take the current element and exchange it with the smallest element that can be found on the right hand side of the current element. In doing so, you will gradually build up a sorted list on the left side (just as in Insertion Sort), and in each iteration “attach” the smallest element from the remaining unsorted right side to it.

*Implement*Selection Sort.- Show that Selection Sort is correct (consider the loop invariant).
- Generate random input sequences of length
*n*as well as sequences of length*n*that represent the worst case and the best case for the Selection Sort algorithm. Briefly describe how you generated the sequences (e.g. programmatically with a random sequence generator). - Run the algorithm on sequences of (c) with length
*n*for increasing values of*n*and measure the computation times. Plot curves that show the computation time of the algorithm in the best, average, and worst case for increasing input length*n*. Note that in order to compute reliable measurements for the average case, you have to run the algorithm multiple times for each entry in your plot. You can use whatever plotting method you like (R, Matlab, Excel, by hand, …). - Interpret the plots in (d) with respect to asymptotic behavior and constants.

## Reviews

There are no reviews yet.