Solution to homework #2

Big-oh exercises

  1. Give the definition of f(n) = O( g(n) ).
  2. ANSWER:

    f(N) = O(g(N)) means that there exist positive constants c and n0 such that f(N) ≤ c * g(N) for all N ≥ n0
  3. Demonstrate, by applying the definition of big-oh, that
    1. n2 = O(n2)
      ANSWER:

      We must demonstrate that there exist positive constants c and n0 such that
      n2 ≤ c * n2 for all n ≥ n0

      Choose c = 1. Clearly n2 ≤ n2 holds for all values of n, so it certainly holds whenever n ≥ 1.

      If we choose n0 = 1, we have demonstrated that there exist positive constants c = 1 and n0 = 1 such that

      n2 ≤ c * n2 for all n ≥ n0
    2. n2 + 1 = O(n2)
      ANSWER:

      We must demonstrate that there exist positive constants c and n0 such that
      n2 + 1 ≤ c * n2 for all n ≥ n0

      Choose c = 2. Then

      n2 + 1 ≤ 1 * n2
      holds whenever
      1 ≤ 1 * n2
      which is true for all n ≥ 1.

      If we choose n0 = 1, we have demonstrated that there exist positive constants c = 2 and n0 = 1 such that

      n2 + 1 ≤ c * n2 for all n ≥ n0
    3. k * n2 + 1 = O(n2), where k is a positive constant
      ANSWER:

      We must demonstrate that there exist positive constants c and n0 such that
      k * n2 + 1 ≤ c * n2 for all n ≥ n0

      Choose c = k + 1. Since k is a positive constant certainly k + 1 is too. Then

      k * n2 + 1 ≤ (k + 1) * n2
      holds whenever
      1 ≤ 1 * n2
      which is true for all n ≥ 1.

      If we choose n0 = 1, we have demonstrated that there exist positive constants c = k + 1 and n0 = 1 such that

      n2 + 1 ≤ c * n2 for all n ≥ n0
  4. Demonstrate, by giving appropriate counterexamples, that the following claims are false:
    1. If f(n) = O(g(n)) and f(n) = O(h(n)) then g(n) = h(n).
    2. ANSWER:

      A counterexample is in this case a set of assignments to f, g and h so that f(n) = O(g(n)) and f(n) = O(h(n)) are both true but g(n) ≠ h(n)

      Pick f(n) = n2, g(n)= n3 and h(n)= n4.

      We can show that f(n) = O(g(n)) and f(n) = O(h(n)) are both true. However, it is clearly the case that g(n) ≠ h(n).

    3. If f(n) = O(g(n)) and g(n) = O(f(n)) then f(n) = g(n).
    4. ANSWER:

      A counterexample is in this case a set of assignments to f, g and h so that f(n) = O(g(n)) and g(n) = O(f(n)) are both true but f(n) ≠ g(n)

      Pick f(n) = n2 and g(n)= n2+1.

      We can show that f(n) = O(g(n)) and g(n) = O(f(n)) are both true. However, it is clearly the case that f(n) ≠ g(n).

  5. Prove, by applying the definition of f(n) = O(g(n)), each of the following:
    1. If f(n) = O(g(n)) and g(n) = O(h(n)) then f(n) = O(h(n)).
    2. ANSWER:

      From f(n) = O(g(n)) we know that there exist positive constants c and r such that
      f(n) ≤ c * g(n) ∀ n ≥ r

      From g(n) = O(h(n)) we know that there exist positive constants d and s such that

      g(n) ≤ d * h(n) ∀ n ≥ s

      Both inequalities will hold if n ≥ r and n ≥ s. We can therefore conclude that:

      f(n) ≤ c * g(n) ≤ c * (d * h(n)) ∀ n ≥ max(r,s)
      Thus we have shown that there exist positive constants k = c*d and n0 = max(r,s) such that
      f(n) ≤ k * h(n) ∀ n ≥ n0
    3. If f1(n) = O(g1(n)) and f2(n) = O(g2(n)) then f1(n) f2(n) = O(g1(n)g2(n))
    4. ANSWER:

      From f1(n) = O(g1(n)) we know that there exist positive constants c1 and n1 such that
      f1(n) ≤ c1 * g1(n) ∀ n ≥ n1

      From f2(n) = O(g2(n)) we know that there exist positive constants c2 and n2 such that

      f2(n) ≤ c2 * g2(n) ∀ n ≥ n2

      Both inequalities will hold if n ≥ n1 and n ≥ n2. We can therefore conclude that:

      f1(n) f2(n) ≤ c1 * g1(n) * c2 * g2(n) ∀ n ≥ max(n1,n2)
      or
      f1(n) f2(n) ≤ c1 * c2 * g1(n) * g2(n) ∀ n ≥ max(n1,n2)

Carl G. Alphonce
Last modified: Fri Apr 16 20:50:43 EDT 2004