b)
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
c) The best case complexity is O(1)
d)
A =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Consider the following algorithms int add.them (int n, int AI) index iふk; j=0; for (i =...
void subelement ( int n, const array S[]) { if(n<3) { print("Not enough elements for subset") } index i, j, k; for( i =1; i <=n; i++) { for(j=i+1; j<=n; j++) { for (k = j +1; k<=n;k++) { print(S[i],S[j],S[k]) } } } } Is the time complexity O(n^3)?? is there an worst case complexity?
Array manipulation (a) Write Java code for a method exchange (int [] a, int i, int j) that exchanges the values stored at indices i and j in the array a. You do not need to worry about cases where either i or j is an invalid index. Give the best estimate you can for its time complexity (b) In an ordered array of n items, how can we determine whether or not an item belongs to the list using...
(c) int sum(int n) un { int sum=0; for (int i=0; i<n; i++) for(int j=0; j<i/2; j++) for(int k=0; k<min(j,5); k++) { sum=sum+1; } return sum; }
COMPLETE BigMerge public class BigMerge { /* * Returns j such that a[j][index[j]] is the minimum * of the set S={a[i][index[i]] for every i such that index[i]<a[i].length} * If the set S is empty, returns -1 * Runs in time a.length. * * NOTE: normally this would be private, but leave it * public so we can test it separately from your merge. */ public static int argMin(int [][]...
Convert the following to mips assembly: int recursion (int N) { int i, j, k; if (N greater than 9) { print "End recursion\n"; return N; } print "Recursion in "; print N; print ":"; for (k=0; k less than N; k=k+1) print "x"; print "\n"; i = N + 7; j = N + 1; k = 13 - i; j = recursion (j); j = j - k; j = j + i; print "Recursion...
Consider the following pseudocode: Algorithm RecursiveFunction (a, b) // a and b are integers if (as1 ) return b; else return RecursiveFunction (a-2, a/2); endif a. What is the time complexity of the RecursiveFunction pseudocode shown above? b What is the space complexity of the RecursiveFunction pseudocode shown above? n(n+1) C. What is the time complexity of the following algorithm (Note that 21-, i = n(n+1)(2n+1). and Σ.,1 ): Provide both T(n) and order, Ofn)). int A=0; for (int i=0;i<n;i++)...
Explain please II. (7 points) Consider the following bit of pseudocode: for (int k = 1; ks Ign; k++) (for (int i = 1; i r: i++) Print "Hello World"; for (int j-1;jsn:j++) Print "Hello World" when n = 2, how many times will "Hello World" be printed? When n 4, how many times will "Hello World be printed? O Assuming that the print is the basic operation, what is the complexity function of this pseudocode? II. (7 points) Consider...
3) [16 points total] Consider the following algorithm int SillyCalc (int n) int i; int Num, answer; if (n <= 4) return n 10; else { Num-SillyCalcl n/4) answer = Num + Num + 10; for (i-2; i<-n-1; ++) answer- answer+ answer; return answer; Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2* for some...
you will analyse two algorithms for finding the median of an array of integers. You will compare both algorithms in terms of timing, and hopefully design a hybrid algorithm that uses both, depending on input size. You will write a report describing your experiments and results. the following Java program implements two algorithms for finding the median of an array of integers. The first uses merge sort, and the other implements the recursive linear time selection algorithm, the task is...
#9 What is time complexity of fun()? int fun(int n) { int count = 0; for (int i = n; i > 0; i /= 2) for (int j = 0; j < i; j++) count += 1; return count; } Group of answer choices O(n^2) O(nLogn) O(n) O(nLognLogn)