For the following pairs of functions, indicate whether the ?? could be replaced with O, Ω or Θ. More than one may be applicable.
Pr. | f(n) | g(n) | f(n)∈??(g(n)) |
---|---|---|---|
a) | 6n | n2+2 | |
b) | 0.00001n2 | 22100(nlogn) | |
c) | 5n20+n2log2n | n! | |
d) | 4n | 4log2(2n) | |
e) | 2n1.5 | 5nlogn | |
f) | 1.000001n | 7n1024 | |
g) | 2n2logn | 4n |
List each of the functions from the previous problem from slowest to fastest growing in a table like the table below (include both the f(n) and g(n) functions). Group the functions by complexity class. Indicate which functions are in the same complexity class (same big-Θ set).
Complexity class | Functions from previous problem. |
---|---|
Θ( ) | |
Θ( ) | |
Θ( ) | |
Θ( ) | |
Θ( ) | |
Θ( ) | |
Θ( ) |
NOTE: The number of rows in the table above may not match the number of complexity classes required.
For each of the following Java methods, analyze the running time by:
Code Listing A
public int A(int[] array) {
int result = 10;
int i = array.length;
while (i > 1) {
if (array[i - 1] < 0) {
return 0;
}
for (int j = 0; j < array.length; j++) {
result += 3 * array[j];
}
i = i / 2;
}
return result;
}
Code Listing B
public int B(int[] array1) {
int result = 0;
for (int i = array1.length-1; i >= 0; i--) {
result += array1[j] * 10;
}
for (int j = 0; j < array1.length / 2; j++) {
result += array1[j] * 3;
}
return result;
}
Code Listing C
public int C(int[] array1) {
int result = 0;
for (int i = 0; i < array1.length; i++) {
for (int j = 0; j < array1.length; j++) {
for (int k = 1; k < array1.length; k = k * 2) {
result += j * array1[k] + array1[i] + array1[j];
}
}
}
return result;
}
Consider the following two algorithms: Algorithm A requires 14n+4 steps to complete on an input of size n. Algorithm B requires n2 steps. For what values of n should we prefer algorithm A? For what values of n should we prefer algorithm B? Justify your answer.
Use either formal definition of big-Θ to demonstrate that 2n3+2n2∈Θ(n3).
Use an appropriate typesetting program to produce a PDF of your solutions and submit them via the turn-in link on Canvas. (We encourage you to used LaTeX, but are not requiring it for this submission. Overleaf is a relatively user-friendly cloud-based LaTeX editor.)