Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Exercises

  1. Consider the function tex2html_wrap_inline59718. Using Definition gif show that tex2html_wrap_inline58028.
  2. Consider the function tex2html_wrap_inline59718. Using Definition gif show that tex2html_wrap_inline58888.
  3. Consider the functions tex2html_wrap_inline59718 and tex2html_wrap_inline59728. Using Theorem gif show that tex2html_wrap_inline59730.
  4. Consider the functions tex2html_wrap_inline59732 and tex2html_wrap_inline59734. Using Theorem gif show that tex2html_wrap_inline59736.
  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_inline59752
    tex2html_wrap_inline59754 tex2html_wrap_inline59756
    tex2html_wrap_inline59758 tex2html_wrap_inline59760
    tex2html_wrap_inline58508 tex2html_wrap_inline59764
    tex2html_wrap_inline57482 tex2html_wrap_inline58508
    tex2html_wrap_inline59770 tex2html_wrap_inline58508
    tex2html_wrap_inline59774 tex2html_wrap_inline58508
    tex2html_wrap_inline59778 tex2html_wrap_inline59780
    tex2html_wrap_inline58970 tex2html_wrap_inline59784
    tex2html_wrap_inline59786 tex2html_wrap_inline59788
    tex2html_wrap_inline59790 tex2html_wrap_inline59792

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

    gather2425

    for tex2html_wrap_inline58476.

  7. Prove each of the following formulas:
    1. tex2html_wrap_inline59796
    2. tex2html_wrap_inline59798
    3. tex2html_wrap_inline59800
  8. Show that tex2html_wrap_inline59802, where tex2html_wrap_inline57896 and tex2html_wrap_inline57996.
  9. Show that tex2html_wrap_inline59808.
  10. Solve each of the following recurrences:
    1. tex2html_wrap_inline59810
    2. tex2html_wrap_inline59812
    3. tex2html_wrap_inline59814
    4. tex2html_wrap_inline59816
  11. Derive tight, big oh expressions for the running times of Example-a,Example-b,Example-c,Example-d,Example-f,Example-g,Example-h,Example-i.
  12. Consider the Java program fragments given below. Assume that n, m, and k are non-negative ints and that the methods 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 (int i = 0; i < n; ++i)
          f (n, m, k);
    3. for (int i = 0; i < e (n, 10, 100); ++i)
          f (n, 10, 0);
    4. for (int i = 0; i < e (n, m, k); ++i)
          f (n, 10, 0);
    5. for (int i = 0; i < n; ++i)
          for (int j = i; j < n; ++j)
              f (n, m, k);
      
      	
  13.   Consider the following Java 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 method f.
    class Example
    {
        static int f (int n)
        {
    	int sum = 0;
    	for (int i = 1; i <= n; ++i)
    	    sum = sum + i;
    	return sum;
        }
        // ...
    }
  14.   Consider the following Java program fragment. (The method 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 method g.
    class Example
    {
        // ...
        static int g (int n)
        {
    	int sum = 0;
    	for (int i = 1; i <= n; ++i)
    	    sum = sum + i + f (i);
    	return sum;
        }
    }
  15. Consider the following Java program fragment. (The method f is given in Exercise gif and the method 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 method h.
    class Example
    {
        // ...
        int h (int n)
    	{ return f (n) + g (n); }
    }

next up previous contents index

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