What is the Big-Oh order of the following code fragment? The fragment is parametrized on the...
6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during the sort. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Insertion ( public static void sort (String[] a) f int n- a.length; for (int i-1; i < n; i++) f for (int j i; j 0; j--) if...
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 } }
8. R-4.8 Order the following functions by asymptotic growth rate. 4nlogn + 2n 2^10 2^logn 3n + 100logn 4n 2^n n^2 + 10n n^3 nlogn 9. R-4.9 Give a big-Oh characterization, in terms of n, of the running time of the example 1 method shown in Code Fragment 4.12. 10. R-4.10 Give a big-Oh characterization, in terms of n, of the running time of the example 2 method shown in Code Fragment 4.12. 11. R-4.11 Give a big-Oh characterization, in...
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...
USE JAVA PROGRAMMING Create a program that would collect list of persons using double link list and use a Merge Sort to sort the object by age. Create a class called Person : name and age Create methods that add, and delete Person from the link list Create a method that sorts the persons' objects by age. package mergesort; public class MergeSortExample { private static Comparable[] aux; // auxiliary array for merges public static void sort(Comparable[] a) { aux =...
Hey i got the program to work but i cant get the merge sorter from big to little import java.util.*; class MergeSorter { public static void sort(int[] a) { if (a.length <= 1) { return; } int[] first = new int[a.length / 2]; int[] second = new int[a.length - first.length]; for (int i = 0; i < first.length; i++) { first[i] = a[i]; } for (int i = 0; i < second.length; i++) { second[i] =...
Give a big-Oh characterization, in terms of n,of the running time for each of the following code segments (use the drop-down): - public void func1(int n) { A. @(1). for (int i = n; i > 0; i--) { System.out.println(i); B. follogn). for (int j = 0; j <i; j++) System.out.println(j); c.e(n). System.out.println("Goodbye!"); D.@(nlogn). E.e(n). F.ein). public void func2 (int n) { for (int m=1; m <= n; m++) { system.out.println (m); i = n; while (i >0){ system.out.println(i); i...
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...
[Acuña] Give sortints' Big-Oh order if its input was already sorted, where the expression bounds the number of swaps. Include a short explanation public static void sortints (int[] data) { for(int i = 1; i < data.length; i++) { int j = i; while(j > 0 && data[j-1] > data[j]) { swap (data[j], data[j-1]) //f(n) counts these j--;
4. (5 Points) The following is another merge sort top down implementation, what is the running time and space complexity for this implementation in big-0? Briefly explain your answer. public static 〈T extends Comparable〈 T> > void sort2(T[] a) { sort2(a, , a.length - 1); @Suppresswarnings ("unchecked") private static <T extends Comparable<T>> void sort2(ΤΠ a, intlo, int hi) { if (hi (z lo) return; T[] aux- (TLD new comparable[a,length]; int mid- (10 + hi) / 2; sort2 (a, lo, mid);...