CSCI 235 Spring 2013
Data Structures and Software Design
Archived Class
Charles Cusack
Computer Science
Hope College
Main
Schedule
Grading
Gradebook

Policies
Advice
College
    Policies

Notes
Programs
Tutorials

CSCI 385
MATH 160
Others

Admin

Homework 6

Details

  1. For each of the following, give the simplest Θ(tight) bound possible. Assume all logs are base 2 unless specified otherwise.
    (e.g. your answer should be something like Θ(n2), not Θ(263 n2-198 n + 999).
    1. 13 n2 log12(n) + n2.0001
    2. 1,000 n3 + n5 + 1,000,000 n2
    3. n11 + 5n + n101 log200(n) + 3n + 25,432,000 + 23 n + 13 n2
    4. 2n + 3n
    5. 12 n3 log(n) + 23 n2 log5(n) - 988 n + 99
    6. 12 n3 + 23 n2-988 n + 99,000,000
    7. 4n + n5
    8. 32×2log(n) +23 n
    9. (n2 log(n) + n3)(n2+n+32)(2n+3n+n2+n+1+log(n))
    10. n2log3(n)/ log5(n) + 3 n2

  2. Rank the following functions in increasing order of rate of growth. If two of them have the same growth rate, write them on the same line. Otherwise, put them one per line in increasing order of growth.
    1. n log(n)
    2. 453 n3
    3. 13 n3 + 27 n2-563 n + 67
    4. 22n
    5. n2
    6. 3n
    7. 11 n log(n2)
    8. n2.0001
    9. 4n
    10. 23 log10(n)
    11. n2 log(n)

  3. For each of the following functions, give a simple tight bound for the best-case and the worst-case running times. Briefly justify your answers (That means you do not need to give a formal proof, but justify your answer somehow.). Assume A.length=n.
    1. int sumArray(int []A) {
          int sum=0;
          int i=0;
          while(i < A.length) {
              sum = sum + A[i];
      	i++;
      	if(sum>12345) {
                  i=A.length;
      	}
          }
          return sum;
      }
      
    2. int computeGruhop(int []A) {
          int sum=0;
          for(int i=0 ; i < A.length ; i++) {
              for(int j=0 ; j < A.length ; j++) {
                  sum = sum + A[i]*A[j];
      	    if(sum==1000000) {
                      i = A.length;
      	    }
      	}
          }
          return sum;
      }
      
    3. int anotherSum(int []A) {
          int sum=0;
          for(int i=0 ; i < A.length ; i++) {
              for(int j=0 ; j < 100 ; j++) {
                  sum = sum + A[j] + A[i];
      	}
          }
          return sum;
      }
      
    4. void HalfIt(int n) {
          while(n > 0) {
              n = n/2;
          }
      }
      
    5. // Assume A and B are both n by n.
      Matrix MatrixMultiply(Matrix A, Matrix B) {
          Matrix C;
          for(int i=0 ; i < n; i++) {
              for(int j=0 ; j < n ; j++) {
      	    C[i][j]=0;
                  for(int k=0 ; k < n ; k++) {
      		C[i][j] += A[i][k]*B[k][j];
      	    }
      	}
          }
          return C;
      }