Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Exercises

  1. Consider the function tex2html_wrap_inline60763. Using Definition gif show that tex2html_wrap_inline59085.
  2. Consider the function tex2html_wrap_inline60763. Using Definition gif show that tex2html_wrap_inline59939.
  3. Consider the functions tex2html_wrap_inline60763 and tex2html_wrap_inline60773. Using Theorem gif show that tex2html_wrap_inline60775.
  4. Consider the functions tex2html_wrap_inline60777 and tex2html_wrap_inline60779. Using Theorem gif show that tex2html_wrap_inline60781.
  5. For each pair of functions, f(n) and g(n), in the following table, indicate if f(n)=O(g(n)) and if g(n)=O(f(n)).

    f(n) g(n)
    10n tex2html_wrap_inline60797
    tex2html_wrap_inline60799 tex2html_wrap_inline60801
    tex2html_wrap_inline60803 tex2html_wrap_inline60805
    tex2html_wrap_inline59565 tex2html_wrap_inline60809
    tex2html_wrap_inline58535 tex2html_wrap_inline59565
    tex2html_wrap_inline60815 tex2html_wrap_inline59565
    tex2html_wrap_inline60819 tex2html_wrap_inline59565
    tex2html_wrap_inline60823 tex2html_wrap_inline60825
    tex2html_wrap_inline60021 tex2html_wrap_inline60829
    tex2html_wrap_inline60831 tex2html_wrap_inline60833
    tex2html_wrap_inline60835 tex2html_wrap_inline60837

  6.   Show that the Fibonacci numbers (see Equation gif) satisfy the identities

    gather2331

    for tex2html_wrap_inline59533.

  7. Prove each of the following formulas:
    1. tex2html_wrap_inline60841
    2. tex2html_wrap_inline60843
    3. tex2html_wrap_inline60845
  8. Show that tex2html_wrap_inline60847, where tex2html_wrap_inline58953 and tex2html_wrap_inline59063.
  9. Show that tex2html_wrap_inline60853.
  10. Solve each of the following recurrences:
    1. tex2html_wrap_inline60855
    2. tex2html_wrap_inline60857
    3. tex2html_wrap_inline60859
    4. tex2html_wrap_inline60861
  11. Derive tight, big oh expressions for the running times of sum.c,horner.c,factorial.c,findmax.c,geometric.c,geometric2.c,power.c,geometric3.c.
  12. Consider the C++ program fragments given below. Assume that n, m and k are unsigned ints and that the functions e, f, g and h have the following characteristics: Determine a tight, big oh expression for the worst-case running time of each of the following program fragments:
    1. f (n, 10, 0);
      g (n, m, k);
      h (n, m, 1000000);
    2. for (unsigned int i = 0; i < n; ++i)
          f (n, m, k);
    3. for (unsigned int i = 0; i < e (n, 10, 100); ++i)
          f (n, 10, 0);
    4. for (unsigned int i = 0; i < e (n, m, k); ++i)
          f (n, 10, 0);
    5. for (unsigned int i = 0; i < n; ++i)
          for (unsigned int j = i; j < n; ++j)
              f (n, m, k);
      
      	
  13.   Consider the following C++ program fragment. What value does f compute? (Express your answer as a function of n). Give a tight, big oh expression for the worst-case running time of the function f.
    unsigned int f (unsigned int n)
    {
        unsigned int sum = 0;
        for (unsigned int i = 1; i <= n; ++i)
            sum = sum + i;
        return sum;
    }
  14.   Consider the following C++ program fragment. (The function f is given in Exercise gif). What value does g compute? (Express your answer as a function of n). Give a tight, big oh expression for the worst-case running time of the function g.
    unsigned int g (unsigned int n)
    {
        unsigned int sum = 0;
        for (unsigned int i = 1; i <= n; ++i)
            sum = sum + i + f (n);
        return sum;
    }
  15. Consider the following C++ program fragment. (The function f is given in Exercise gif and the function g is given in Exercise gif). What value does h compute? (Express your answer as a function of n). Give a tight, big oh expression for the worst-case running time of the function h.
    unsigned int h (unsigned int n)
        { return f (n) + g (n); }

next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.