Mohamed G. Gouda CS 313K Fall 2012 Exercise 13 1. Show, by direct inference, that the function f(x) = 10 is Theta(g(x)) where g(x) = 1. Sol: Proving f(x) is O(g(x)): |f(x)| = |10| = 10 = 10*1 = C*|1| for C=10 =< C*|g(x)| for K is any value and C=10 Proving f(x) is Omega(g(x)): |f(x)| = |10| = 10 = 10*1 = C*|1| for C=10 >= C*|g(x)| for K is any value and C=10 2. Show, by direct inference, that f(x) = 3*x-7 is Theta(g(x)) where g(x)=x. Sol: Proving f(x) is O(g(x)): |f(x)| = |3*x-7| = 3*x-7 for x>3 =< 3*x = 3*|x| = C*|x| for C=3 = C*|g(x)| for K=3 and C=3 Proving f(x) is Omega(g(x)): |f(x)| = |3*x-7| = 3*x-7 for x>3 >= 2*x for x>7 = 2*|x| = C*|x| for C=2 = C*|g(x)| for K=7 and C=2 3. Show, by direct inference, that f(x) = x^2-x-1 is Theta(g(x)) where g(x)=x^2. Sol: Proving f(x) is O(g(x)): |f(x)| = |x^2-x-1| = x^2-x-1 for x>2 =< x^2 = 1*|x^2| = C*|x^2| for C=1 = C*|g(x)| for K=2 and C=1 Proving f(x) is Omega(g(x)): |f(x)| = |x^2-x-1| = x^2-x-1 for x>2 = (x^2)/2 + (x^2)/2 - x - 1 >= (x^2)/2 for x>4 = (1/2)*|x^2| = C*|x^2| for C=(1/2) = C*|g(x)| for K=4 and C=(1/2) 4. Show, by direct inference, that f(x) = 5*log(x) is Theta(g(x)) where g(x)=log(x). Sol: Proving f(x) is O(g(x)): |f(x)| = |5*log(x)| = 5*log(x) for x>2 = C*log(x) for C=5 = C*|log(x)| =< C*|g(x)| for K=2 and C=5 Proving f(x) is Omega(g(x)): |f(x)| = |5*log(x)| = 5*log(x) for x>2 >= (4)*log(x) = C*log(x) for C=4 = C*|log(x)| = C*|g(x)| for K=2 and C=4 5. Show, by direct inference, that f(x) = ceiling(x) is Theta(g(x)) where g(x)=x. Sol: Proving f(x) is O(g(x)): |f(x)| = |ceiling(x)| = ceiling(x) for x>1 =< 2*x = C*|x| for C=2 = C*|g(x)| for K=1 and C=2 Proving f(x) is Omega(g(x)): |f(x)| = |ceiling(x)| = ceiling(x) for x>1 >= x = C*|x| for C=1 = C*|g(x)| for K=1 and C=1 6. Show, by direct inference, that f(x) = (x^2+1)/(x+1) is Theta(g(x)) where g(x)=x. Sol: Proving f(x) is O(g(x)): |f(x)| = |(x^2+1)/(x+1)| = (x^2+1)/(x+1) for x>1 =< (x^2+1)/x =< (x^2+x^2)/x = 2*x = C*|x| for C=2 = C*|g(x)| for K=1 and C=2 Proving f(x) is Omega(g(x)): |f(x)| = |(x^2+1)/(x+1)| = (x^2+1)/(x+1) for x>1 >= (x^2+1)/(2*x) >= (x^2)/(2*x) = (1/2)*x = C*|x| for C=(1/2) = C*|g(x)| for K=1 and C=(1/2) 7. Show, by direct inference, that (f1(x) is O(g1(x))) and (f2(x) is O(g2(x))) => (f1(x)*f2(x) is O(g1(x)*g2(x))) Sol: (f1(x) is O(g1(x))) and (f2(x) is O(g2(x))) => {Definition of "O"} (Exist K1, C1, K2, C2, (All x>K1, |f1(x)| =< C1*|g1(x)|) and (All x>K2, |f2(x)| =< C2*|g2(x)|)) => {Let K be max(K1,K2)} (Exist K, C1, C2, (All x>K, |f1(x)| =< C1*|g1(x)|) and (All x>K, |f2(x)| =< C2*|g2(x)|)) => {Arithmetics} (Exist K, C1, C2, (All x>K, |f1(x)| =< C1*|g1(x)| and |f2(x)| =< C2*|g2(x)|) => {Arithmetics} (Exist K, C1, C2, (All x>K, |f1(x)|*|f2(x)| =< C1*C2*|g1(x)|*|g2(x)|) => {Arithmetics} (Exist K, C1, C2, (All x>K, |f1(x)*f2(x)| =< C1*C2*|g1(x)*g2(x)|) => {Let C be C1*C2} (Exist K, C, (All x>K, |f1(x)*f2(x)| =< C*|g1(x)*g2(x)|) => {Definition of "O"} (f1(x)*f2(x)) is O(g1(x)*g2(x)) 8. Show, by direct inference, that f(x) = 4x^2-5x+3 is O(g(x)) where g(x) = x^2. Sol: |f(x)| = |4x^2-5x+3| = 4x^2-5x+3 for x>1 =< 4x^2+5x^2+3x^2 = 12x^2 = C*|x^2| for C=12 = C*|g(x)| 9. Show, by direct inference, that f(x) = (x+5)*log(3x^2+7) is O(g(x)) where g(x) = x*log(x). Sol: |f(x)| = |(x+5)*log(3x^2+7)| = (x+5)*log(3x^2+7) for x>1 =< (x+5x)*log(3x^2+7x^2) = 6x*log(10x^2) = 6x*log(x^3) for x>10 = 18x*log(x) = C*|x*log(x)| for C=18 = C*|g(x)| for K=10 and C=18 10. Show, by direct inference, that f(x) = (x^2+5*log(x))/(2x+1) is O(g(x)) where g(x) = x. Sol: |f(x)| = |(x^2+5*log(x))/(2x+1)| = (x^2+5*log(x))/(2x+1) for x>1 =< (x^2+5*x^2)/(2x+1) = (6*x^2)/(2x+1) =< (6*x^2)/(2x) = 3*x = C*|x| for C=3 = C*|g(x)| for K=1 and C=3 11. Show, by direct inference, that f(n) = log(1) + log(2) + ... + log(n), where n is a positive integer, is O(g(n)) where g(n) = n*log(n). Sol: |f(n)| = |log(1) + log(2) + ... + log(n)| = log(1) + log(2) + ... + log(n) for n>1 =< log(n) + log(n) + ... + log(n) = n*log(n) = C*|n*log(n)| for C=1 = C*|g(n)|