Starting from:

$25

CH08-320201-HOMEWORK1 Solved

HOMEWORK1

ALGORITHMS AND DATA STRUCTURES (CH08-320201)


Problem 1: Asymptotic Analysis                                                                                                                   (2+2+2+2=8 points)

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).

(a)    f(n) = 3n and g(n) = n3.

√ 

(b)    f(n) = 7n0.7 + 2n0.2 + 13logn and g(n) = n.

(c)     f(n) = n2/logn and g(n) = nlogn.

(d)    f(n) = (log(3n))3 and g(n) = 9logn.

Problem 2: Selection Sort                                                                                                                       (2+5+3+5+1=16 points)

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.

(a)    Implement Selection Sort.

(b)    Show that Selection Sort is correct (consider the loop invariant).

(c)     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).

(d)    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, ...).

(e)    Interpret the plots in (d) with respect to asymptotic behavior and constants.

More products