Big O
: TRUE TRUE FALSE FALSE
Growth Rates of Functions
For
Other Notation
- Big O
is an upper bound notation ( ) - Little O
is a weak upper bound notation ( ) - Big Omega notation
is a lower bound notation ( ) - Little Omega notation
is a weak lower bound notation ( ) - Big Theta notation
if an exact bound notation ( )
Examples
Example
What is the worst case runtime?
int fun3(int n) {
assert(n > 0);
for (int i = 0; i <= n; i++) {
for (int j = i; j < n; j++) {
printf("something");
}
}
}
Answer:
Recursion
- Identify the order of the function excluding any recursion
- Determine the size of the data for the next recursive call(s)
- Write the full recurrence relation
- Look up the closed-form solution in the table (wow)
Relationship | Runtime |
---|---|
= |
|
...cont | |
Where |
|
(table provided on exams) |
Example
int fib(int num) {
if (num <= 1) {
return num;
}
return fib(num - 2) + fib(num - 1);
}
Which is
Amortized Constant Time
Doesn't matter if it's slow "every once in a while", as long as it's every once in a while.