Find the Big- notations for the following pseudocode snippets with regard to n (the size of data).
Question:
Find the Big-ϴ notations for the following pseudocode snippets with regard to n (the size of data). Please note, you must show us how to find both the upper bound and the lower bound, or you will get zero points. You may also use the l'Hopital's trick for your convenience.
A. // Assuming n is always larger than 10
for (k = 0; k < n; k + +) { for (j = 10; j < n; j + +) { // code block that takes a constant amount of runtime } }
|
B. k = 1; do { j = 1; do { // code block that takes a constant amount of runtime j = j * 3; } until (j >= 0.5*n); // if j < 0.5*n, continue the loop k = k + 1; } until (k >= n); |
PART 2 - Comparing the orders of growth between two algorithms (4pts)
Say we have two different algorithms with respective runtimes of f(n) and g(n). Given the following cases, prove whether or not f(n) is O(g(n)) in each case.
Please follow the entire instructions for both parts. Please show me how to find Upper and lower bounds for Part 1
You need to show your work with the crucial steps, e.g. finding the necessarily constant c in the definition of Big-O. You may utilize the pull-up/pull-down or the l'Hopital's trick discussed in class whenever needed.
You will be penalized for up to 1 pt in total if all your work for this entire PART exceeds a whole A4/US letter page in 12px font size (assuming you start from the top of the page).
P.S. sqrt(n) means the square-root of n, aka n^(½).
Case | f(n) | g(n) |
A | log(n1000) | log(n0.0001) |
B | sqrt(n) | n |
C | 3n | 5n |
D | cos(n)+1 | sin(n)+10 |