This action might not be possible to undo. Are you sure you want to continue?
YEON JIN LEE; TA: HOA LONG TAM CS170-FALL2011
1. DPV0.1 In each of the following situations, indicate whether f = O(g) or f = Ω(g) or both (in which case f = Θ(g)) (a) n − 100, n − 200 n−100 f = Θ(g) because n−200 approaches 1 as n → ∞. (b) n1/2 , n2/3 f = O(g) because na = O(nb ) if a < b (c) 100n + log n, n + (log n)2 f = Θ(g). Simplifying by only keeping the dominant terms we get f = 100n and g = n. |f (n)/g(n)| approaches 100 as n → ∞. (d) n log n, 10n log 10n f = Θ(g). Divide both f and g by n. We get f = log n, g = 10 log 10n. We can ignore the coeﬃcient 10 in g. Then f = log n, g = log 10n. Break up g into addition of two logs: g = log 10 + log n. We ignore the constant term log 10. We see that both f and g are equal to log n. Therefore f = Θ(g). (e) log 2n, log 3n f = Θ(g) We can rewrite f and g as f = log 2 + log n and g = log 3 + log n. We can ignore the constant terms log 2 and log 3. We see that f = 1. Therefore f = Θ(g). g (f) 10 log n, log(n2 ) f = Θ(g). We ignore the coeﬃcient 10 as it becomes insigniﬁcant as n → ∞. Replace n log n with 2k . We get f = k, g = 2kThe log(n2 ) approaches ﬁnite nonzero constant as n → ∞. (g) n1.01 , n log2 n f = Ω(g) Rewrite n1.01 as n ∗ n.01 . Then we can cancel out from f and g by dividing both of them by n. Now f = n.01 and g = log2 n. Replacing n with 2k (or any base raised to kth power), we get f = 2.01∗k , g = k 2 . f grows exponentially whereas g grows polynomially. Therefore, f is an upperbound of g.
Replacing n with 2k . This approaches 0 as n → ∞ because the exponential 3n term (2/3)n dominates the polynomial term n. |f (n)| approaches 0 as n → ∞ . (j) (log n)log n .. g = 2k .n! grows much faster then n2 (i. n! = 1 ∗ 2 ∗ 3 ∗ . 2n+1 = 1/2. n2 = n ∗ (2/3)n . Comparing just the exponents (since exponent term dominates polynomial term when n → ∞. Replacing k n with 2k . f is an upper bound of g. nonzero constant as n → ∞ |f (n)| |g(n)| approaches a ﬁnite (l) n1/2 . 3n n f = O(g). which equals n ∗ nk .n and 2n = 2 ∗ 2 ∗ 2 ∗ 2. Therefore f is an upper bound of g. Any polynomial dominates any logarithm.. 2(log2 n) 2 f = O(g).. 2n+1 2n f = Θ(g). Any polynomial dominates any logarithm. Replacing n with 2k . n(log n)2 f = Ω(g) First. we get f = 2k/2 .We know that if |f (n)/g(n)| approaches 0 as n → ∞. then f = O(g). therefore f is an upper bound of g. Proof for f = O(g) f = n ik is essentially f = 1k + 2k + .. we get 2k and g = k 2 . 5log2 n f = O(g). g = nk is essentially replacing each i=1 term of f with nk like so: nk + nk + . √ (k) n. g = 2k /k. As n approaches ∞. (q) n ik . g is an upper bound of f because na = O(nb ) if a < b (m) n2n . f grows exponentially whereas g grows polynomially. (log n)10 f = Ω(g). |g(n)| (p) (log n)log n .n − 1k + nk . (o) n!. therefore. (log n)3 f = Ω(g).. As n → ∞.. 2n f = Ω(g). g = (log n)2 . g is the lower bound of f.nk . TA: HOA LONG TAM CS170-FALL2011 (h) n2 / log n.. we see that g grows faster then f.1 ..2 YEON JIN LEE. Replacing n with 2k . n/ log n f = Ω(g). f = k k grows much faster than g. Therefore g is the upper bound of f. we get f = k k . Therefore. we see 2 . (i) n0. divide both sides by n and we get f = n/ log n.e. (n) 2n . we get f = k k . g = 5k . nk+1 i=1 f = Θ(g).Therefore.
PROBLEM SET 1 3 that g is the upper bound of f. Therefore f = O(g) Proof for f = Ω(g) k+1 k+1 k+1 Therefore f = Ω(g). = i |n = n k+1 0 k+1 < n n k i=1 i di .
since cn approaches 0.. + cn is: (a) Θ(1) if c < 1. DPV0. then it is just multiplying 1 n times since 1 raised to any power equals 1. Therefore the term in numerator. And the entire sum approaches a constant. (c) Θ(cn ) if c > 1 We can rewrite g(n) as a geometric series. as n → ∞. If c > 1.Therefore. Therefore (b) holds true. n+1 . If c < 1.. This value approaches cn as n → ∞. So (c) holds true. then g(n) = 1 + c + c2 + . we consider only the dominant terms which is the exponential in the numerator.4 YEON JIN LEE. the numerator term approaches 1. TA: HOA LONG TAM CS170-FALL2011 2. g(n) = 1−c .2 Show that if c is a positive real number. (a) holds true. 1−c We know that any exponential dominates any polynomial. If c = 1. cn+1 . (b) Θ(n) if c = 1. 1 − cn dominates 1 − c.
1 > log2 1. . running time of ﬁb3 is O(M (n)). ﬁb3 takes O(M(n)* log(n)) time. Prove that the running time of ﬁb3 is O(M (n) log n). (d) Let M (n) be the running time of an algorithm for multiplying n-bit numbers. DPV0. ce + dg cf + dh e f . For X 8 case. d = 1.). This ”c” value can be found by taking the log of n since log N is the power to which you need to raise 2 in order to obtain n.4 (a) Show that two 2 x 2 matrices can be multiplied using 4 additions and 8 multiplications. it takes exactly c multiplications. Say there are two matrices: a b A= .PROBLEM SET 1 5 3. Therefore. where c is number of power of 2s that is less than n. A∗B = ae + bg af + bh . b = 2. Multiply this by itself to get X 4 matrix. In general. (Hint: think about computing X 8 . Multiplication of d x d matrix by another d x d matrix.the lower right element will be the biggest element . 1 1 xn = (xn/2 )2 = (xn/2 )(xn/2 ) T (n) = T (n/2) + O(nd ) T (n) = T (n/2) + M (n) Using the Master Theorem. c d B= Then. ﬁb3’s intermediate results are all 2x2 matrices whose elements are at most 2n bits long (this can be proved by multiplying out the matrix few times . retains dimension (the result is d x d).we track its length in bits. x= 0 1 .(TALK ABOUT WHEN N IS ODD) (c)Show that all intermediate results of ﬁb3 are O(n) bits long. and assume that M (n) = O(n2 ). g h (b) Show that O(log n) matrix multiplications suﬃce for computing X n . (e) Can you prove that the running time of ﬁb3 is O(M (n))? Assume M (n) = Θ(na )) for some 1 ≤ a ≤ 2. Therefore. store the X 2 matrix. ﬁb3 does at most n bit multiplication (as proved in (c)). Store this matrix. Multiply this by it self to get X 8 . we set a= 1. for X n case. at most log(n) times (as proved in (b)).
This value is clearly less than nn (which is n*n*.. To show a lower bound. TA: HOA LONG TAM CS170-FALL2011 4. n/2 and log 2 are both constants so we can simplify this to log n! > n log n... Proof for f = O(g) We can represent n! as 1 ∗ 2 ∗ 3 ∗ . ..n − 1 ∗ n.n) as n → ∞.4 Show that log(n!) = Θ(n log n) (Hint: to show an upper bound..6 YEON JIN LEE. we can take log of both sides and get log n! > n/2 log n/2. compare it with (n/2)n/2 . Therefore. compare n! with nn . DPV1.. 2 This is equal to log n! > (n/2 log n − log 2). f = Θ(g) iﬀ f = O(g) and f = Ω(g). n! = O(nn ) Proof for f = Ω(g) n Assuming we know n! > n 2 ..
imin = max(i-(d+1).0) jmax = min(j+d.jmin] end for end for . s] that is quickly computable. j] = r=0 i for i = 0 to n-1 for j = 0 to n-1 S[i. n-1) s=0 jA[r.jmax] +T[imin.jmin]-T[imin.j] += T[imax. 5 Assume we have T [i.jmax]-T[imax.0) imax = min(i+d.PROBLEM SET 1 7 5. n-1) jmin = max(j-(d+1). S[i.j] = 0.
(n + 1) ∗ 10d − 1.. we see that it equals 1 (this is approximate calculation using big-Oh notation). We can set x = n ∗ 10d and x = (n) ∗ 10d+1 − 1. which can be approximated as ln(2n+1 −1 − ln 2n = ∆ (we will call this value ∆). TA: HOA LONG TAM CS170-FALL2011 6. Say n is some scalar constant (i.. . we can prove that there is more than 1 prime between n ∗ 10d and (n) ∗ 10d+1 − 1. for some d ∈ 0. Expected number of iterations of this algorithm is E = 1 + (1 − prob) ∗ E. Π(x = n ∗ 10d ) = Π((n) ∗ 10d+1 − n∗10d ln(n∗10d ) (n)∗10d+1 −1 1) = ln((n)∗10d+1 −1) By replacing n with ek and getting rid of constant terms. 2. this is simply 2n+1 −1) 2n Π(2n+1 − 1) − Π(2n ). Prime Number Theorem states that Π(x) = x/(ln(x)). 6 (a) Prove: Given any sequence of digits in any base.∞ Using Prime Number Theorem.∞.. 2200+1 −1) 2200 ∆ = ln(2200+1 −1 − ln 2200 −1−2 p= 2 = 140 ∆ Answer: 140 iterations 200+1 200 .. we know that there is at least 1 prime between x = n ∗ 10d and x = (n) ∗ 10d+1 − 1. we can calculate the number of primes that exist between 2n+1 − 1 and 2n . (b) What is the probability that a random number. Therefore. Probability is then number of primes in given range divided by all values in ∆ range: prob = 2n+1 −1−2n .... is prime? What is the expected number of iterations of this algorithm before it halts? n-bit number has value of 2n to 2n+1 − 1 in base 10. where d ∈ 0. n+1 n we get E = 1/prob = 2 −1−2 δ (c)Compute the expected number of iterations for n=200 bits. there are inﬁnitely many primes that start with these digits. that is exactly n bits long. Solving for E. If x − x ≥ 1. we get k Π(x) = ek k +1 Π(x ) = e k Subtracting x from x’.e 1234).8 YEON JIN LEE. Using Prime Number Theorem. we can conclude that there are inﬁnitely many primes that start with given sequence of digits. 1. All numbers that start with n can be written as n ∗ 10d .
PROBLEM SET 1 9 .
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.