

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Total possible marks: 100. Homeworks must be solved individually. This set covers chapters 1–4 of the textbook Introduction to Algorithms, 3rd. ed., by Cormen et al.
Exercise 1: asymptotic behavior (20 points). Assume you have two computers, CA and CB capable of performing 10^6 and 10^8 operations per second, respectively. Both computers run a set of algorithms whose precise complexities f (n) are given below. Determine the size n∗^ of the biggest input that can be processed in 1 second for each computer.
f (n) n∗^ for CA n∗^ for CB lg lg√ n n 14 n + 4 n log 3 n + n n^2 + 7n n^10 2 n 3 n n! nn
The precise complexity tells you how many operations are performed to solve an instance of size n. Assume each operation takes the same time and that the input sizes are natural numbers.
Exercise 2: running time (38 points). Consider the following function, where A is an array containing integers and v an integer.
Function-X(A, v)
1 s = 0 2 for i = 1 to A.length 3 if A[i] == v 4 s = s + 1 5 return s
Answer the following questions concisely:
Exercise 3: recurrent equations (42 points). (This is based on textbook problems 4. and 4.3.) Give asymptotic upper and lower bounds for T (n) in each of the following recurrences. Assume that T (n) is constant for n ≤ 2.
n
n) + 1
n
Justify your answers. If you use the master theorem, specify which case and show that its hypotheses are satisfied. If you use recursion trees to find a good guess, verify the guess with the substitution method.
Bonus exercise: recurrent equations (20 points). Consider the recurrence
T (n) = aT (n/b) + f (n).
Case 3 of the master theorem requires that f (n) = Ω(nlogb^ a+) for some constant > 0 and that f (n) satisfies the regularity condition af (n/b) ≤ cf (n) for some constant c < 1 and all sufficiently large n. Prove that the regularity condition is always satisfied if f (n) = nk. (This means we don’t need to check it when f is a polynomial.)