CSE 431/531 Homework 1 Due date: Feb 22, 2016 Lecturer: Shi Li Your Name: Your University ID: Problems Max. Score Your Score 1 7 2 7 3 6 4 6 5 6 6 8 Total Score 40 Problem 1 (7 points). For each pair of functions f, g in the following table, indicate whether f is O, o, Ω, ω or Θ of g. Assume that k ≥ 1, > 0 and c > 1 are constants. Write down “yes” or “no” in each box. Give a proof for your answer for (row (d), column Ω). (a) (b) (c) (d) f lgk n 2n √ n lg(n!) g n 2n/2 nsin n lg(nn ) O o Ω ω Θ 1 point for each row; 3 points for the proof. Problem 2 (7 points). Assume f (n) and g(n) are asymptotically positive functions. Indicate whether the following statements are true or false. Give proofs for (e) and (f). (a) f (n) = O(g(n)) implies 2f (n) = O(2g(n) ). true / false (b) f (n) = O((f (n))2 ). true / false (c) If f (n) = o(g(n)), then f (n) = O(g(n)). true / false (d) f (n) + g(n) = Θ(n) implies f (n) = O(n). true / false (e) f (n) + g(n) = Θ(n) implies either f (n) = Θ(n) or g(n) = Θ(n). true / false (f) f (n) + o(f (n)) = Θ(f (n)). true / false 0.5 points for each “true/false” answer; 2 points for each proof. Problem 3 (6 points). Consider the interval scheduling problem given by a set S = {1, 2, · · · , n} of activities, each activity i has a starting time si and finish time fi . Decide whether each of the following two greedy strategies is safe of not. If the answer is yes, give a proof; if the answer is no, give a counterexample. 1 1. Select the job i ∈ S with the biggest length (the length of job i is fi − si ). If i is incompatible with some other job in S, then we do not schedule i; otherwise we schedule i. 2. Select the job i ∈ S with the smallest si (i.e, earliest starting time). If there is a job j ∈ S \{i} such that [sj , tj ) ⊆ [si , ti ), then we do not schedule i; otherwise we schedule i. 3 points for each strategy. Problem 4 (6 points). Let I = (k, n, T, (p1 , p2 , · · · , pk ), (r1 , r2 , · · · , rT )) be an optimal caching instance, where • k is the number of pages that can be held in the cache, • n is total number of pages, • T is the length of the request sequence, • p1 , p2 , · · · , pk ∈ [n] ∪ {⊥} are the k pages held in the cache initially(⊥ means an empty page), • rt ∈ [n] is the page requested at time t. Let I 0 = (k, n, T, (p01 , p02 , · · · , p0k ), (r1 , r2 , · · · , rT )) be another instance such that p0i = pi for every i = 2, 3, · · · , k. Prove the value for I 0 (i.e, the total number of misses in an optimum solution to I 0 ) is at most the value for I plus 1. Remark In a valid solution, if a requested page is in the cache, we can not bring any page to the cache; if a requested page is not in the cache, we can only bring the requested page to the cache. Problem 5 (6 points). Design a data structure that maintains a set S of elements, each element v ∈ S with an associated value key[v], and supports the following two operations: • median: return the element whose key is the b(n + 1)/2c-th smallest among all elements in S, where n = |S|; • add(v): add the element v to S. The running time for each operation should be O(lg n). (Hint: you can use the heap data structure as a black-box.) Problem 6 (8 points). S In the interval covering problem, we are given n intervals [s1 , t1 ), [s2 , t2 ), · · · , [sn , tn ) such that i∈[n] [si , ti ) = [0, T ). The goal of the problem is to return a smallest-size set S S ⊆ [n] such that i∈S [si , ti ) = [0, T ). Design a greedy algorithm for this problem. 2