Augustana Faculty logo and wordmark


COMPUTING SCIENCE 210
Algorithm Analysis and Data Structures


Exercises on Asymptotic Analysis



Due Date: Monday, October 3 (at start of class session)

Objectives

Assignment

Answer the following questions, either in handwritten form or using some program that supports mathematical notation. In the following, assume that "log n" means "log2 n".

  1. Order the following list of functions by their Big-Oh time complexity, such that if function f(n) is above or to the left of g(n), then f(n) = O(g(n)). (I.e., put them in order, fastest to slowest; more formally, order them by growth rate, from most slowly growing to most quickly growing.)

    1. 6n log n + 2n
    2. ( 1 / 3 )n
    3. n n
    4. log log n
    5. log 2 n    [See the textbook, p. 155, on the meaning of the notation "log c n".]
    6. 1 / n
    7. 210
    8. n - n 3 + 7n 5
    9. n / log n
    10. n !   [That's n factorial.]
    11. 2log n
    12. 2n
    13. 3n + 100 log n
  2. Algorithm A uses 10n log n operations, while algorithm B uses n 2 operations.

    1. Determine the value n0 such that A is better than B for n >= n0.

    2. Repeat the problem assuming B uses n sqrt(n) operations.

  3. For each function f(n) and time t in the following table, determine the largest size n of a problem that can be solved in time t assuming that the algorithm to solve the problem takes f(n) microseconds. (Some entries have already been completed as examples.)

        1 Second     1 Hour     1 Month     1 Century  
    log n approx. 10300000      
      sqrt(n)          
    n        
      n log n          
    n2        
    n3        
    2n        
    n !   12    
  4. Prove or disprove:

    1. 12 is O( 1 ).

    2. 7n + 3n2 - 2 is O( n3 ).

    3. max( n3, 10n2 ) is O(n2).

    4. 3n log n is Big-Omega( n ).

    5. f(n) = n2      for even n >= 0       is O( n2 ).
      n3      for odd n >= 1
    6. 2n + 1 is O( 2n ).

    7. If d(n) is O(f(n)) and e(n) is O(g(n)), then the product d(n)e(n) is O(f(n)g(n)).

  5. Characterize the following summations (exactly) in terms of n:

    1. 5 + 5 + 5 + 5 + . . . + 5
      -- -- -- --- ---
      2 4 8 16 2n

    2. Sigma 1 <= i <= n ( 3i + 4 ) [where Sigma is the summation symbol].

  6. Give a Big-Oh characterization, in terms of n, of the running time of each of the following Java methods.

    1.         public void ExA( int n ) {
                  int a;
                  for ( int i = 0; i < n; i += 2 )
                      a = i;
              }
                      
      
    2.         public void ExB( int n ) {
                  int a;
                  for ( int i = 0; i < n * n; i++ )
                      a = i;
              }
                      
      
    3.         public void ExC( int n ) {
                  int a;
                  for ( int i = 0; i < n; i++ )
                      for ( int j = 0; j <= i;  j++ )
                          a = i;
              }
                      
      
    4.         public void ExD( int n ) {
                  int a;
                  for ( int i = 0; i < n * n; i++ )
                      for ( int j = 0; j <= i;  j++ )
                          a = i;
              }
                      
      
    5.         public void ExE( int n ) {
                  int a;
                  for ( int i = 0; i < n; i++ )
                      for ( int j = 0; j <= n - i;  j++ )
                          a = i;
              }
                      
      
    6.         public void ExF( int n ) {
                  int a;
                  for ( int i = 1; i < n; i *= 2 )
                      a = i;
              }
                      
      
    1. Give an example of a positive function f(n) such that f(n) is neither O(n) nor Big-Omega( n ).

    2. Would the function be Big-Omega( n ) if Big-Omega were redefined as follows?

      f(n) is Big-Omega of g(n) if there is a real constant c > 0 such that f(n) >= c g(n) for infinitely many values of n.

      Provide a proof for your conclusion.

  7. The following conversation was overheard between a programmer and a computer scientist:

    Programmer:
    I just wrote a really fast program to solve the WOW problem. I wrote it in assembler, optimized every loop, and used every special instruction available on the Quadrium-7 processor.
    Computer Scientist
    How fast is it?
    Programmer:
    Well, for 10 BogoUnits, it took 10 seconds to find the optimum, and for 11, it took 20 seconds, and for 12, it took 40 seconds, and for 13, it took 80 seconds, and so on.
    Computer Scientist
    But that's really slow! I have a O( n3 ) algorithm, which is much faster.
    Programmer:
    Faster?! I tried your program and it took 1000 seconds for 10 BogoUnits. How can you claim your method is faster?
    1. Estimate how long it would take the Computer Scientist's algorithm to solve the problem for 20 BogoUnits.

    2. Estimate how long it would take the Programmer's program to solve the problem for 20 BogoUnits.

    3. What additional information do you need to decide which solution is in fact better for the actual problem?

Submission

Submit a hardcopy of your solutions in hard copy form to the instructor by the due date specified.