15.6 Exercises
Doing more practices is the best way to gain intuition when it comes to asymptotics!
Factual
Prove that .
What is the runtime of the following function?
public static int f(int n) {
if (n <= 1) {
return 0;
}
return f(n - 1) + f(n - 1) + f(n - 1);
}Procedural
Find the runtime of running
print_fibwith for arbitrarily large n.
Do the above problem again, but change the body of the for loop in
print_fibto be:
Find the runtime of the function
fon an input of sizen, given thecreateArrayfunction as described below:
Metacognitive
What would the runtime of
modified_fibbe? Assume that values is an array of size n. If a value in an int array is not initialized to a number, it is automatically set to 0.