Find the worst case runtime f(n) for the following algorithms.
# STAY HOME # STAY SAFE
The solution to the above problem is given in the attached images.Please refer.
If you have any queries please comment in the comments section and kindly upvote.
Find the worst case runtime f(n) for the following algorithms. Specify the number of operations executed...
Show your work Count the number of operations and the big-O time complexity in the worst-case and best-case for the following code int small for ( i n t i = 0 ; i < n ; i ++) { i f ( a [ i ] < a [ 0 ] ) { small = a [ i ] ; } } Show Work Calculate the Big-O time complexity for the following code and explain your answer by showing...
Select all the valid asymptotic runtime bounds for the following function f2 in the worst case: public static int f1 (int n) { int x = 0; for (int i = 0; i < n; i++) { x++; } return x; } public static int f2 (int n) { if (n <= 1) { return 1; } return f1(n) + f2(n/2) + f2(n/2); } Θ(n^2) O(n^2) Θ(log(n)) Θ(log^2(n)) Θ(nlog(n)) Ω(n) Ω(n^2)
5. Calculate the worst-case scenario runtime for int P(int al, int low, int high) int t; int lo = (low <= high)?(low): (high); int hi = (high + low) - lo; int i = lo - 1; int pivot = a[hi]: for(int j = 10; j < hi;j +1) if (a[j] < pivot) i += 1; t = a[i]; a[i] = a[j]; a[j] = t; t = a[i+1]; a[i+1] = a[hi]: a[hi] = t; return (i + 1); where high...
Need to find number of elementary expressions in terms of n, not looking for Big O complexity. 4. Work out the number of elementary operations in the worst possible case and the best possible case for the following algorithm (justify your answer): 0: function Nonsense (positive integer n) 1: it1 2: k + 2 while i<n do for j+ 1 to n do if j%5 = 0 then menin else while k <n do constant number C of elementary operations...
Which big-O expression best characterizes the worst case time complexity of the following code? public static int foo(int N) ( int count = 0; int i1; while (i <N) C for (int j = 1; j < N; j=j+2) { count++ i=i+2; return count; A. O(log log N) B. O(log N2) C. O(N log N) D. O(N2)
(10 pts.) Count the worst-case number of array element comparisons (A[j] < A[j-1]) made by InsertionSort on arrays of size n: void InsertionSort(int A[], int n) { for (int i = 1; i < n; ++i) for (int j = i; j > 0 && A[j] < A[j-1]; --j) swap(A[j], A[j-1]); } Do the same for the number of swap's. 2. Which function grows faster: 2^((lg?))2 or ?^(2019)? Justify your answer. 3. Use "name and conquer" to give a derivation...
Exercise 7.3.5: Worst-case time complexity - mystery algorithm. The algorithm below makes some changes to an input sequence of numbers. MysteryAlgorithm Input: a1, a2....,an n, the length of the sequence. p, a number Output: ?? i != 1 j:=n While (i < j) While (i <j and a < p) i:= i + 1 End-while While (i <j and a 2 p) j:=j-1 End-while If (i < j), swap a, and a End-while Return( aj, a2,...,an) (a) Describe in English...
Find the best case, worst case and average case complexity for numbers of comparison and assignment operations for the following code. Indicate when there is no best or worst case. Comparisons Assignments Given 2-D array of integer map[n][n]: Best: Best: worst: worst: for (i0; 1 <n; i++) for(j = 0j <n; j++) If (map 10] < 0) map[001-mapli01: average: average: For ease of analysis, assume half of the elements in map are negative.
3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int recurseFunc(int n) If n 0, return 1. If n 1, return 1 while i< n do while j <n do print("hi") j 1 end while i i 1 end while int a recurse Func(n/9); int b recurse Func (n/9) int c recurse Func (n/9) return a b c (1) Set up a runtime recurrence for the runtime T n) of this algorithm. (2) Solve...
I must execute in C using parallel Programming techniques the following serial program: void producer_consumer(int *buffer, int size, int *vec, int n) { int i, j; long long unsigned int sum = 0; for(i=0;i<n;i++) { if(i % 2 == 0) { // PRODUCER for(j=0;j<size;j++) { buffer[j] = vec[i] + j*vec[i+1]; } } else { // CONSUMER for(j=0;j<size;j++) {...