Void F1 (int n) {
int a;
for(int i = 0; i < n; i += 2) a = i;
}
Which of the following characterization, in terms of n, of the running time of the above code (F1) is correct?
Θ(n3/2) · O(1/n) · O(n) · Ω(n2)
Void F1 (int n) {
int a;
for(int i = 0; i < n; i += 2) a = i;
}
Which of the following characterization, in terms of n, of the running time of the above code is NOT correct?
· Θ(n3) · O(n2) · Ω(n3/2) · O(n3)
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Consider the following code: Void F1 (int n) { int a; for(int i = 0; i...
Consider the following loop nest: int sum = 0; for(int j = 0; j < N * N; j += 2) for(int i = 2*N; i > 0; i--) sum++; What is the Big-O behavior? Group of answer choices O(1) O(log N) O(N) O(N log N) O(N2) O(N3) 2.Consider the following loop nest: int sum = 0; for(int j = 1; j < N; j *= 2) for(int i = 0; i < N; i += 2) sum++; What is...
What is the worst case running time of the following pseudo-code. void doSomething(int n, int m) { if(m> n) return; System.out.println("m=" + m); doSomething(n, m+2); } A o(n) B O(nlogn) C O(n2) D O(n+m) E None of the above
1,What is the following code an example of: volatile int i = 0; static void *f1(void *p) { while (i==0) { /* do nothing - just keep checking over and over */ } printf("i's value has changed to %d.\n", i); return NULL; } /* i is global, so it is visible to all functions. It's also marked volatile, because it may change in a way which is not predictable by the compiler, here from a different thread.*/ Question 14 options:...
Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?
Consider the following code in c++ template <class T> int F1(T* A, int n) { int v = 1; for (int i = 0; i < n - 1; i++) if (A[i] != A[i + 1]) v++; return v; } int main() { string X[10] = { "aaa","bbb","bbb","bbb","bbb" }; int a = F1(X, 5); return 0; } what is the value of the variable a?
Consider the following piece of code: sum = 0; for (i=1; i<= f(n); i++) sum +=i; where f (n) is a function call. Give a tight big-oh bound on the running of this piece of code as a function of n, on the assumption that (a) The running time of f (n) is O(n), and the value of f (n) is n! (b) The running time of f (n) is O(n), and the value of f (n) is n (c)...
Consider the following C++ code segment: for (int i = 0; i <n; ++i) { for (int j = 0; j <m; ++j) if (i != j) cout << "0"; else cout << "1"; } } Which of the options below gives the correct output if the value of nis 2and the value of mis 3? 1. 100010 2. 011101 3. 100100 4. 010001
Consider the following function definition and variable declarations: void square(int &n){n= n*n;} int arr[] = {1, 2, 3}; int number = 4; Which of the following function calls are acceptable? (can have multiple answer) a.square(1); b.square(2); c.square(arr[number]); d.square(number); What is the output of the following code segment? int arr[] = {1, 4, 1, 0}; for (int i=0; i < 4; ++i) cout<<arr[i]*2; a.1014 b.1 4 1 0 (space in between each number) c.1410 d.0140 e.None of the above Given...
Big-O notation. Consider the following function. int func1(int n) { int sum = 0, i; for(i = 0; i<n; i++;) { sum += i; return sum; } Express the running time of func1 as a function of n using big-O notation. Write a function that has the same functionality as func1, but runs in O(1) time.
Consider the following C code which implements a stack; int data[100]; int sp=0; void push(int n) {data[sp++}=n;} int pop() {return(data{data[--sp]);} For the following questions, show the contents of the data array, as well as the value of sp, in the spaces provided (after all the shown instructions are executed). If the contents are unpredictable, indicate this with "?" Assume the statements are executed in order, i.e., the statements in part (b) are executed after the statements in (a) and so...