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

Exercises

  1. Consider the function tex2html_wrap_inline60001. Using Definition gif show that tex2html_wrap_inline58309.
  2. Consider the function tex2html_wrap_inline60001. Using Definition gif show that tex2html_wrap_inline59169.
  3. Consider the functions tex2html_wrap_inline60001 and tex2html_wrap_inline60011. Using Theorem gif show that tex2html_wrap_inline60013.
  4. Consider the functions tex2html_wrap_inline60015 and tex2html_wrap_inline60017. Using Theorem gif show that tex2html_wrap_inline60019.
  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_inline60035
    tex2html_wrap_inline60037 tex2html_wrap_inline60039
    tex2html_wrap_inline60041 tex2html_wrap_inline60043
    tex2html_wrap_inline58789 tex2html_wrap_inline60047
    tex2html_wrap_inline57763 tex2html_wrap_inline58789
    tex2html_wrap_inline60053 tex2html_wrap_inline58789
    tex2html_wrap_inline60057 tex2html_wrap_inline58789
    tex2html_wrap_inline60061 tex2html_wrap_inline60063
    tex2html_wrap_inline59251 tex2html_wrap_inline60067
    tex2html_wrap_inline60069 tex2html_wrap_inline60071
    tex2html_wrap_inline60073 tex2html_wrap_inline60075

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

    gather2431

    for tex2html_wrap_inline58757.

  7. Prove each of the following formulas:
    1. tex2html_wrap_inline60079
    2. tex2html_wrap_inline60081
    3. tex2html_wrap_inline60083
  8. Show that tex2html_wrap_inline60085, where tex2html_wrap_inline58177 and tex2html_wrap_inline58277.
  9. Show that tex2html_wrap_inline60091.
  10. Solve each of the following recurrences:
    1. tex2html_wrap_inline60093
    2. tex2html_wrap_inline60095
    3. tex2html_wrap_inline60097
    4. tex2html_wrap_inline60099
  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 C# 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 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 method F.
    public class Example
    {
        public static int F(int n)
        {
    	int sum = 0;
    	for (int i = 1; i <= n; ++i)
    	    sum = sum + i;
    	return sum;
        }
        // ...
    }
  14.   Consider the following C# 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.
    public class Example
    {
        // ...
        public 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 C# 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.
    public class Example
    {
        // ...
        public int H(int n)
    	{ return F(n) + G(n); }
    }

next up previous contents index

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