ECE250: Assignment 1* - University of Waterlooece250/assignments/A1.pdf · Consider the following...

1

Click here to load reader

Transcript of ECE250: Assignment 1* - University of Waterlooece250/assignments/A1.pdf · Consider the following...

Page 1: ECE250: Assignment 1* - University of Waterlooece250/assignments/A1.pdf · Consider the following recursive algorithm that computes minimum value out of real numbers stored in the

ECE250: Assignment 1* Due Date: Wednesday, September 27, 2017 – 11:00PM

1. Prove that f (n) = 96 +10n8 logn+3n6 is Ο(n8 logn) using the definition of “Big-Oh”.

2. Consider the following recursive algorithm that computes minimum value out of real numbers stored in the array A on positions from l to r.

PUZZLE(A: array of real numbers, l: integer, r: integer)

if l = r then return A[l]

temp1← PUZZLE(A, l, l + r2

"

#"$

%$)

temp2 ← PUZZLE(A, l + r2

+1"

#"$

%$, r)

if temp1 temp2 then return temp1 else return temp2

Write a recurrence describing the cost of running this algorithm on n element array: PUZZLE(A,1,n). Solve the recurrence and give the resulting running time of the algorithm.

3. Consider sorting n numbers stored in array A by first finding the smallest element of A and exchanging it with the element in A 1[ ] . Then, find the second smallest element of A , and exchange it with A 2[ ] . Continue in this manner for the first 1−n elements of A . This algorithm is known as selection sort. Write your pseudocode for this algorithm. Give the best-case and worst-case running times of your algorithm in Θ notation.

4. Give asymptotic upper and lower bounds for )(nT in each of the following recurrences. Assume that )(nT is constant for sufficiently small n. Make your bounds as tight as possible and justify your answers.

• T (n) = T (n−1)+ n

• T (n) = 36T (n6)+ n5 lgn

5. Write an algorithm Find(A,a,b,e) for a sorted array that returns true if A[i]= e for some 1≤ a ≤ i ≤ b ≤ n and otherwise returns false. The asymptotic time complexity of Find(A,a,b,e) should be Ο(lgn). Justify the running time of your algorithm.

* NOTE: Your assignment solutions must be typed for marking and should be submitted through LEARN. The name of your file should be xxxxxxxx_an.pdf, where xxxxxxxx is your UW user id and n is the assignment number that is 1 for this submission.