6. (16 points) For each C++ function below, give the tightest asymptotic upper bound that you can determine for the function<img alt=”int mocha(int n) { int r = 0; for (int i=0; i<=n; i – i+16) for (int j=0; j<img alt=”(e) int latte(int n) { int j = 0; for (int k = 0; k

6. (16 points) For each C++ function below, give the tightest asymptotic upper bound that you can determine for the function’s runtime, in terms of the input parameter. Where prompted, also compute the return value of the function. Express both runtime and return value in simplest terms. For all function calls, assume that the input parameter n > 1. (a) int coffee(int n) { int s = n*n; for (int q = 0; q 0; –) ses – q; return s + 2; Return value for (a): Running time of (a): int tea(int n) { int r = 0; for (int i = 1; i int mocha(int n) { int r = 0; for (int i=0; i
(e) int latte(int n) { int j = 0; for (int k = 0; k



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *