Q-1: Given the following code fragment, what is its Big-O running time?
test = 0
for i in range(n):
for j in range(n):
test= test + i *j
Q-2: Given3 the following code fragment what is its Big-O running time?
for i in range(n):
test=test+1
for j in range(n):
test= test - 2
Q-3: Given the following code fragment what is its Big-O running time?
i = n
while i > 0:
k=2+2
i = i // 2
Here is the answer..

If you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP...
Q-1: Given the following code fragment, what is its Big-O running time? test = 0 for...
Analyze the following code and provide a "Big-O" estimate of its running time in terms of n. Explain your analysis. Assume k is a constant given by the problem. for (i=1; i<=n; i++) p = pow(i,k); // p = i to the power of k for (j=1; j<=p; j++) Some O(1) work end for end for
What is the Big-Oh order of the following code fragment? The fragment is parametrized on the variable N. Assume that you are measuring the number of times j is decremented. public static void sort(Comparable[] a) { int N-a.length; for (int i = 1; i < N;i++) { for (int j = i; j > && less(a[5], a[j-1]); j--) //measure j -- exch(a, j, j-1); O(nlogn) O O(n^2) Q(n) Does not exist.
For the following program fragment give a Big-O analysis of the running time. Briefly explain your answer: int t = 0; for(int i=1; i <= n; i++) for(int j=1; j <= i*i; j++) if(j % i == 0) t++; What I have so far, O(1) + O(n) + O(n2) + O(1) + O(1) Drop Low order terms: O(n) + O(n2) And I believe the final answer to be O(n3), but not sure if just drop the O(n) or...
Calculate the running time for the following code fragment. Show your work. for (i:= 0; i < n; i++) { for (j:=1; j < n; j*=2) { counter := counter +1 } }
Given the following code, find their big(O) for I in range of n: for j in range of n: for k in range of 10000: print(“test”) If an algorithm takes n3+1000n2+1000n2+9999 time, what is the Big O for this algorithm? Proof: O(nK) < O (2n), need to do some research on polynomial time and exponential time.
In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here, n) int *a = new int [10]; // new is O(1) int size = 10; for (int i = 0; i < n; i ++) { if (i == size) { int newsize = 3*size/2; int *b = new int [newsize]; // new is O(1) for (int j = 0; j < size; j ++)...
In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here, n) for(int i=n-1; i >=0; i--){ for(int k=0; k < i*n; k++){ // do something that takes O(1) time } }
Using C++ please explain
What is the Big-O time complexity of the following code: for (int i=0; i<N; i+=2) { ... constant time operations... Select one: o a. O(n^2) O b. O(log n) c. O(n) O d. 0(1) What is the Big-O time complexity of the following code: for(int i=1; i<N; i*=2) { ... constant time operations... Select one: O O a. O(n^2) b. 0(1) c. O(n) d. O(log n) O What is the Big-O time complexity of the following...
What are the Big-Oh and Omega orders of the following code fragment? What is Tilde approximation? The fragment is prameterized on the variable n. Assume that you are measuring the number of swap calls. for(int j=0;j<n-1;j++){ int z = j; for (int i=j+1; i<n; i++){ if(a[i] < a[z]){ z=i;} } if(z!= j){ swap(a[j], a[z]); //count these } }
(10') 6. For each of the following code blocks, write the best (tightest) big-o time complexity i) for (int i = 0; ǐ < n/2; i++) for (int j -0: ni j++) count++ i) for (int í = 0; i < n; i++) for (int ni j0 - for (int k j k ni kt+) count++ İİİ) for (int í ー 0; i < n; i++) for(int j = n; j > 0; j--) for (int k = 0; k...