Question: What is the big-oh runtime for the following functions? 1. int suggested_foo(int n) { int i, sum = 0; for (i = 0; i <
What is the big-oh runtime for the following functions?
1.
int suggested_foo(int n) { int i, sum = 0; for (i = 0; i < 100; i++) { // Assume foo3(n) is an O(log n) function sum += foo3(n); // Assume foo1(n) is an O(n) function sum += foo1(n); } return sum; } Same Question
int foo13(void) { return 13; } 2.
int misleading_foo(int **array, int n) { int i = 0, j = 0; while (i < n) { while (j < n && array[i][j] == 1) j++; i++; } return j; } 3.
int foo12(int n) { int i, sum = 0; for (i = 0; i < 100; i++) { // recall foo3(n) is O(log n) sum += foo3(n); // recall foo1(n) is O(n) sum += foo1(n); } } 4.
int foo12(int n) { int i, sum = 0; for (i = 0; i < 100; i++) { // recall foo3(n) is O(log n) sum += foo3(18); // recall foo1(n) is O(n) sum += foo1(13); } return sum; } 5.
How many times is the statement x++ executed in the following piece of code?
int nested_foo(int n) { int i, j, x = 0; for (i = 1; i <= n; i++) for (j = i; j <= n; j++) x++; return x; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
