Starting from:

$25

CH-231-A- Homework3 Solved

Submit one ZIP file per homework sheet which contains one PDF file (including pictures,computations, formulas, explanations, etc.) and your source code file(s) with one makefile and without adding executable, object or temporary files.

The implementations of algorithms has to be done using C, C++, Python or Java.
Problem 3.1 Asymptotic Analysis                                                                        
Considering the following pairs of functions f and g, show for each pair whether or not it belongs to each of the relations 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).

(2 points) f(n) = 9n and g(n) = 5n3,


(2 points) f(n) = 9n0.8 + 2n0.3 + 14logn and g(n) = n,
(2 points) f(n) = n2/logn and g(n) = nlogn,
(2 points) f(n) = (log(3n))3 and g(n) = 9logn.
Problem 3.2 Selection Sort                                                                                   
Insertion Sort was discussed during the lecture. 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 sequence on the left side (like in Insertion Sort), and in each iteration ”attach” the smallest element from the remaining unsorted right side to it.

(2 points) Implement Selection Sort.
(3 points) Show that Selection Sort is correct (Hint: consider the loop invariant).
(3 points) Generate random input sequences of length n as well as sequences of length n that represent Case A and Case B for the Selection Sort algorithm. Case A: the case which involves the most swaps (Hint: it is not a decreasingly ordered array). Case B: the case with the least swaps. Briefly describe how you generated the sequences (e.g., with a random sequence generator using your chosen language).
(4 points) Run the algorithm on the sequences from (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 Case A, Case B, and average case for an 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 a plotting tool/software of your choice (Gnuplot, R, Matlab, Excel, etc.).
(1 point) Interpret the plots from (d) with respect to asymptotic behavior and constants.

More products