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

Exercises

  1. Consider the function tex2html_wrap_inline59798. Using Definition gif show that tex2html_wrap_inline58108.
  2. Consider the function tex2html_wrap_inline59798. Using Definition gif show that tex2html_wrap_inline58968.
  3. Consider the functions tex2html_wrap_inline59798 and tex2html_wrap_inline59808. Using Theorem gif show that tex2html_wrap_inline59810.
  4. Consider the functions tex2html_wrap_inline59812 and tex2html_wrap_inline59814. Using Theorem gif show that tex2html_wrap_inline59816.
  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_inline59832
    tex2html_wrap_inline59834 tex2html_wrap_inline59836
    tex2html_wrap_inline59838 tex2html_wrap_inline59840
    tex2html_wrap_inline58588 tex2html_wrap_inline59844
    tex2html_wrap_inline57562 tex2html_wrap_inline58588
    tex2html_wrap_inline59850 tex2html_wrap_inline58588
    tex2html_wrap_inline59854 tex2html_wrap_inline58588
    tex2html_wrap_inline59858 tex2html_wrap_inline59860
    tex2html_wrap_inline59050 tex2html_wrap_inline59864
    tex2html_wrap_inline59866 tex2html_wrap_inline59868
    tex2html_wrap_inline59870 tex2html_wrap_inline59872

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

    gather2425

    for tex2html_wrap_inline58556.

  7. Prove each of the following formulas:
    1. tex2html_wrap_inline59876
    2. tex2html_wrap_inline59878
    3. tex2html_wrap_inline59880
  8. Show that tex2html_wrap_inline59882, where tex2html_wrap_inline57976 and tex2html_wrap_inline58076.
  9. Show that tex2html_wrap_inline59888.
  10. Solve each of the following recurrences:
    1. tex2html_wrap_inline59890
    2. tex2html_wrap_inline59892
    3. tex2html_wrap_inline59894
    4. tex2html_wrap_inline59896
  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.