| Homework 6Details
- 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).
- 13 n2 log12(n) + n2.0001
- 1,000 n3 + n5 + 1,000,000 n2
- n11 + 5n + n101 log200(n) + 3n + 25,432,000 + 23 n + 13 n2
- 2n + 3n
- 12 n3 log(n) + 23 n2 log5(n) - 988 n + 99
- 12 n3 + 23 n2-988 n + 99,000,000
- 4n + n5
- 32×2log(n) +23 n
- (n2 log(n) + n3)(n2+n+32)(2n+3n+n2+n+1+log(n))
- n2log3(n)/ log5(n) + 3 n2
-
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.
- n log(n)
- 453 n3
- 13 n3 + 27 n2-563 n + 67
- 22n
- n2
- 3n
- 11 n log(n2)
- n2.0001
- 4n
- 23 log10(n)
- n2 log(n)
- 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.
-
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;
}
-
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;
}
-
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;
}
-
void HalfIt(int n) {
while(n > 0) {
n = n/2;
}
}
-
// 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;
}
|
|
|