outer for loop is running for i = n to i = 1 (>0) which means total n times. inner for loop is running for j = 0 to j = i-1 (<i) which means i times so,
Total = n + n-1 + n-2 + ..... + 2 + 1 = n(n+1)/2 = =
for loop is running for m = 1 to m = n which means total n times. while loop inside for loop is running for fixed logn times (every time value of i is divided by 2) .
Total = n*(logn) = nlogn =
There are no loops. If-else condition will take constant time as there is only one print statement which will get executed.
Total = C (constant) =
outer-most for loop is running for i = n to i = 1 (>0) which means total n times. outer for loop is running for j = 0 to j = i-1 (<i) which means i times. Inner for loop will run 1000 time for each value of j which is constant. so,
Total = n*1000 + (n-1)*1000 + (n-2)*1000 + ..... + 2*1000 + 1*1000 = 1000*(n(n+1)/2) = =
Note that higher order polynomial is considered as complexity.
Give a big-Oh characterization, in terms of n,of the running time for each of the following...
3. Determine the general result (in terms of n) of the following recursive function (4 pts.) public static void func2(int n) { if(n == 1) System.out.println(“*”); else { for (int i = 1; i <= n; i++) System.out.print(“*”); System.out.println(); func2(n-1); } } 4. Does func2 above perform down or bottom up computation? ___________________ (2 pts.)
Describe the worst case running time of the following pseudocode functions in Big-Oh notation in terms of the variable n. Show your work b) void func(int n) { for (int i = 0; i < n; i = i + 10) { for (int j = 0; j < i; ++i) { System.out.println("i = " + i); System.out.println("j = " + j);
Provide a "big oh" run-time analysis for each of the following. When a value of “n” is used, it is the size of the input. 4.) void problem 40 cin n min max for (int i min i n, i++) for (int j- 1: j< max, j++) tota while (total n tota total 2 total 5.) void problem 50 cin n; for (int i 0: i n, i++) for (int j 0; j i2; j++) for (int k 0; k...
Make the Sudoku algorithm for checking for duplicates to be Big -O of N, instead of N-squared. I.E. No nested for loops in rowIsLatin and colIsLatin. Only nested loop allowed in goodSubsquare. public class Sudoku { public String[][] makeSudoku(String s) { int SIZE = 9; int k = 0; String[][] x = new String[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++)...
4. Big-Oh and Rune time Analysis: describe the worst case running time of the following pseudocode functions in Big-Oh notation in terms of the variable n. howing your work is not required (although showing work may allow some partial t in the case your answer is wrong-don't spend a lot of time showing your work.). You MUST choose your answer from the following (not given in any particular order), each of which could be re-used (could be the answer for...
What is the runtime of each method? Give answer in Θ(big Theta) notation as a function of n, give a brief explanation. A. public static int method1(int n){ int mid = n/2; for (int i = mid; i >= 0; i--) System.out.println(i); for (int i = mid + 1; i <= n; i++) System.out.println(i); return mid; } B. public static int method2(int n){ for (int i = n; i >= 0; i / 3){ System.out.println(i ); } return mid; }...
need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...
1(5 pts): For each code fragment below, give the complexity of the algorithm (O or Θ). Give the tightest possible upper bound as the input size variable increases. The input size variable in these questions is exclusively n. Complexity Code public static int recursiveFunction (int n)f f( n <= 0 ) return 0; return recursiveFunction (n - 1) 1; for(int i 0i <n; i+) j=0; for ( int j k=0; i; k < < j++) for (int j; m <...
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.
Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular array implementation of the bounded queue by growing the elements array when the queue is full. Add assertions to check all preconditions of the methods of the bounded queue implementation. My code is! public class MessageQueue{ public MessageQueue(int capacity){ elements = new Message[capacity];...