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?
Silly-Sort(A,i,j) if A[i] > A[j] then exchange A[i] and A[j]; if i+1 >= j then return; k = floor(j-i+1)/3); Silly-Sort(A,i,j-k); Silly-Sort(A,i+k,j); Silly-Sort(A,i,j-k); (a) Argue (by induction) that if n is the length of A, then Silly- Sort(A,1,n) correctly sorts the input array A[1...n] (b) Give a recurrence relation for the worst-case run time of Silly-Sort and a tight bound on the worst-case run time (c) Compare this worst-case runtime with that of insertion sort, merge sort, heapsort and quicksort.
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; }
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 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...
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 [][]...
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++)...
What is the run-time of this recursive code: int maximum(int array[], int index, int len); //define maximum function. int minimum(int array[], int index, int len);//define minimum function. int main() { //Main method int array[MAX_SIZE], N, max, min; //Defining all the variable. int i; printf("Enter size of the array: ");//Taking input from user as a array size scanf("%d", &N); printf("Enter %d elements in array: ", N);//Taking input from user for(i=0; i<N; i++) { scanf("%d", &array[i]);//storing all the element in array. }...
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...