Docsity

COT 5405 Summer 09 Homework: Asymptotic Analysis and Recurrences, Assignments of Algorithms and Programming

Toggle sidebar
bg1
COT 5405 Summer 09 Homework 1
1. (10pts) Prove or disprove.
(a) n1.001 +n log n =θ(n1.001)
(b) n3/log n =ω(n2)
2. (10pts) Use equivalence (≡) and less than (<) to order the below functions
according to asymptotic order.
n!n lg n (lg n)n(1 + 1/444)nlg∗n
2nlog444 n en4 4lg n 42lg n
3. (15pts) Solve the following recurrences without using masters theorem.
(a) T(n) = 2T(n/2) + n3
(b) T(n) = T(√n) + 1
(c) T(n) = 2T(n/3) + T(n/4) + n
4. (10pts) Solve the following recurrence relations. Use master theorm when
applicable.
(a) T(n) = 4T(n/4) + 5n(log n)2+n√n
(b) T(n) = 4T(n/2) + n2log n
5. (15pts) You are given an array of numbers of size n, where each number
in the array is either 1, 2, or 3. Derive an algorithm that only uses
comparisions to sort the array in O(n). Write the pseudo-code for that
algorithm and prove that it takes O(n). Also give the invariant condition
and the proof of correctness.
6. (10pts) In an array of sorted numbers, first nnumbers are fractions (greater
than 0 but less than 1) and the rest are all 1’s. The array is infinitely long,
and you are not aware of the value n. You need to give an algorithm to
check if a user-given fraction Foccurs in that array. Analyze the time
complexity of your algorithm as a function of n.
7. (15pts) In this problem we are interested in solving a modified ’closest
pair’ problem. This time rather than having nindistinguishable points,
there will be nred and nblue points. The task is to find the closest
red-blue pair (i.e. the minimum distance between a red point and a blue
point). Can this problem be solved within the same O(n log n) b ound by
modifying the divide-and-conquer algorithm given in class? If yes, give
the modified algorithm with its running time, if no explain why.
8. (15pts) N p ersons checked in their coats with the valet at a restaurant.
However, the valet incorrectly tagged all the coats. Now, since all the
coats look identical, the only way to identify one’s coat is to wear it and
1
pf2

Partial preview of the text

Download COT 5405 Summer 09 Homework: Asymptotic Analysis and Recurrences and more Assignments Algorithms and Programming in PDF only on Docsity!

COT 5405 Summer 09 Homework 1

  1. (10pts) Prove or disprove.

(a) n^1.^001 + n log n = θ(n^1.^001 ) (b) n^3 /log n = ω(n^2 )

  1. (10pts) Use equivalence (≡) and less than (<) to order the below functions according to asymptotic order. n! n lg n (lg n)n^ (1 + 1/444)n^ lg∗^ n 2 n^ log 444 n en^4 4 lg n^42 lg n
  2. (15pts) Solve the following recurrences without using masters theorem.

(a) T (n) = 2T (n/2) + n^3 (b) T (n) = T (

n) + 1 (c) T (n) = 2T (n/3) + T (n/4) + n

  1. (10pts) Solve the following recurrence relations. Use master theorm when applicable.

(a) T (n) = 4T (n/4) + 5n (log n)^2 + n

n (b) T (n) = 4T (n/2) + n^2 log n

  1. (15pts) You are given an array of numbers of size n, where each number in the array is either 1, 2, or 3. Derive an algorithm that only uses comparisions to sort the array in O(n). Write the pseudo-code for that algorithm and prove that it takes O(n). Also give the invariant condition and the proof of correctness.
  2. (10pts) In an array of sorted numbers, first n numbers are fractions (greater than 0 but less than 1) and the rest are all 1’s. The array is infinitely long, and you are not aware of the value n. You need to give an algorithm to check if a user-given fraction F occurs in that array. Analyze the time complexity of your algorithm as a function of n.
  3. (15pts) In this problem we are interested in solving a modified ’closest pair’ problem. This time rather than having n indistinguishable points, there will be n red and n blue points. The task is to find the closest red-blue pair (i.e. the minimum distance between a red point and a blue point). Can this problem be solved within the same O(n log n) bound by modifying the divide-and-conquer algorithm given in class? If yes, give the modified algorithm with its running time, if no explain why.
  4. (15pts) N persons checked in their coats with the valet at a restaurant. However, the valet incorrectly tagged all the coats. Now, since all the coats look identical, the only way to identify one’s coat is to wear it and

see if it fits EXACTLY (not too tight or too loose). You can assume that all the persons (and their coats) are of distinct size. There is no way to directly sort the persons (or the coats) based on their size i.e., you cannot compare any person or coats directly. A person after trying on a coat can tell if it is 1. an exact fit 2. too tight or 3. too loose. However, if two coats are too tight (or too loose), he can’t tell which one is tighter (or looser). Help the valet to tag the coats correctly, while minimizing the total number of person-coat trys.