Lab 3 Fall 2012

This lab is to review parts of Chapter 2 of Das Gupta et al's text book. Please go to your lab, do the problems to get your full credit for the lab.

You are welcome to try this problem ahead of time.
  1. Please plot n, vs T(n), Q(n), X(n),Y(n),Z(n) for the following functions, by using a C++ program to produce comma separated values and the exporting this file into a spreadsheet program to produce a plot. Always round off the arguments to integers.
    1. T(n)= T(n-1) +1, T(0)=0
    2. Q(n) = Q(n-1) + n , Q(0) =0
    3. R(n) = 2*R(n-1)+1, R(0)=0
    4. X(n) = 2*X(n/2)+1, X(0) =0
    5. Y(N) = 2*Y(n/2)+n, Y(0) =0
    6. Z(n) = Z(sqrt(n)) + 1, Z(1)= 0
    
    int main(void)
    {
      int n;
    
      for (n = 10; n <=1000; n=n+10)
        cout << n<<","<< T(n) <<","<< Q(n) << "," << X(n) <<"," << Y(n) <<","<< Z(n) << "\n";
       exit(1);
    }
    
  2. Solve any two of the above recurrence equations in any of the methods (using telescoping (by series summation), or guess and checking or by using Master Theorem)
  3. Implement merge3sort program to split an integer array (filled with randomly chosen elements from -1000 to 1000 )into 3 parts, sort the three parts and merge them. The size of the array i
  4. (Please do not believe all the code you found in the Web) Please see a C langauge implementation of Karp-Rabin String matching here. This code has many problems. In particular do you see a problem with this code segment.
     /* Main comparison loop */
        for (i = 0; i < num_iterations; i) {
            if (pattern_hash == text_hash && 
                !strncmp(pattern, &(text[i]), pattern_len)) return i;
    }
    
    Your instructor created working version of this C code
    here. Your job is to get a C++ version running. Test with three text strings and three pattern strings.
  5. (optional)Implement linear time algorithm for the maximumsubarray problem and test with the input given in Benley's paper first page.{31,-41,59,26,-53,58,97,-93,-23,84} answer is 2 and 6 as the index starts from 0. You need not submit the solution for this problem when you submit your Lab Solution. Here is a nice write up by Bentley Dr. Bentley )