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...
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.
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 } }
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...
1. Determine the appropriate big-o expression for each of the following functions, and put your answer in the table we have provided in section 2-1 of ps5_parti. We've included the answer for the first function. (Note: We're using the “ symbol to represent exponentiation.) a (n) = 5n + 1 b. b(n) = 5 - 10n - n^2 o c(n) = 4n + 2log (n) d. e. d(n) = 6nlog (n) + n^2 e(n) = 2n^2 + 3n^3 - 7n...
Analyze the following code fragments and write down the Big-O estimates of the following code fragments. Provide a concise explanation how you got your answer. c. for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) cout << (j + k) << endl; } d. while (n > 1) { k += n *3; n = n / 2; } e. int temp = n; for (int j...
Analyze the following code fragments and write down the Big-O estimates of the following code fragments. Provide a concise explanation how you got your answer. c. for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) cout << (j + k) << endl; } d. while (n > 1) { k += n *3; n = n / 2; } e. int temp = n; for (int j...
Python 3 5. (16 points) Determine the big-O running time of each of the following functions: def pi (a) for i in range(len (a)): print (a[i]) for i in range(len(a)): print (ali]) def p2(a): for i in rangeClen(a)): for j in a: print (ati].j) def p3(a): for i in a: for j in a: print (i,j) def p4(a): for i in range(len(a)): pi(a) def p5(a): for i in range(len(a)): p3 (a) def p6(a): for i in range(len(a)): p5(a) def p7...