Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The problem is listed in the comments there are two driver files titled a2 driver. the instructions for the code are written in the notes

The problem is listed in the comments

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

there are two driver files titled a2 driver. the instructions for the code are written in the notes of the source code
A Task List X Find Activate... ? 6 7 8 9 eclipse-workspace - assignmentTwo/src/A2Work.java - Eclipse IDE File Edit Source Refactor Navigate Search Project Run Window Help PRO 12-16 Package Expl.. X A2Work.java X DA2Driver.java 1 import java.util. Random; assignmentTwo 3 public class A2Work { > JRE System Library [jdk-1 /* src 5 * NOTES: # (default package) * Include notes about f(n) for partial credit, similar to what I put in sumo() > A2Driver.java * your f(n) does not need to produce the exact answer as your op count for all sums, but it should be close > D A2Work.java * use estimates based on rules we discussed to determine f(N) * For algorithm 1-3, assume random number generator never produces the same value twice in a given loop, but that it does produce the worst possible order of values 10 11 * 12 130 14 Grading: 15 * THIS IS AN EXAMPLE 16 170 public static String[] sumo(int N) 18 19 //DO NOT COUNT IN op Count long opCount = 0; 21 String fn = "f(N) = 5N+4";//sum assignment, loop, and return combined 22 String On = "O(N) = N";//Growth rate of function as value of N changes - Linear //BEGIN opCounts long sum = 0; op Count++;//assignment of sum /* Outline X op Count++;//assignment of i - happens as loop starts opCount++;//comparison - happens as loop starts for(int i = 0; i JRE System Library [jdk-1 43 return new String[] {fn, On, opCount+""}; src 44 . (default package) 450 /* > A2Driver.java 46 * Grading: 47 > D A2Work.java * Add operation counts - 0.5pt 48 * f(N) formula (show your work) - 0.5pt 49 * O(N) reduction 0.5pt 50 510 public static String[] suml(int N) 52 { 53 //DO NOT COUNT IN opCount 54 long op Count = 0; 55 String fn = "f(N) = (answer]"; 56 String On = "O(N) = (answer]"; 57 //BEGIN opCounts 26 58 long sum = 0; 59 for(int i = 0; i JRE System Library [jdk-1 85 v src 86 return new String[] {fn, On, op Count+""}; . (default package) 87 > A2Driver.java 89 * Grading: > D A2Work.java 90 * Add operation counts - 0.5pt 91 * f(N) formula (show your work) - 0.5pt 92 * O(N) reduction 0.5pt 93 940 public static String[] sum3 (int n) 95 { 96 //DO NOT COUNT IN opCount 97 long opCount = 0; 98 String fn = "f(N) = (answer]"; 99 String On - "O(N) = [answer]"; 100 //BEGIN opCounts long sum = 0; 102 for(int i = 0; i JRE System Library [jdk-1 127 for(int j = 0; j A2Driver.java 130 } 131 > D A2Work.java 132 return new String[] {fn, On, opCount+""}; 133 } 1340 135 * Grading: 136 * Add operation counts - 0.5pt 137 * f(N) formula (show your work) - 0.5pt 138 * O(N) reduction 0.5pt 139 */ 1400 public static String[] sum(int N) 141 { 142 //DO NOT COUNT IN opCount 143 long op Count = 0; 144 String fn = "f(N) = (answer]"; 145 String On = "O(N) = (answer]"; 146 //BEGIN opCounts 9.147 long sum = 0; 148 for(int i = 0; i JRE System Library [jdk-1 169 long opCount = 0; src 170 String fn = "f(N) = [answer]"; . (default package) 171 String On = "O(N) = (answer]"; > A2Driver.java 172 //BEGIN op Counts > D A2Work.java 94173 long sum = 0; 174 for(int i = 1; i JRE System Library [jdk-1 211 * - If it is not used anywhere else, place it into the position and move forward src 212 # (default package) 213 return new Object[] {arr, new String[] {fn, On, op Count+""}}; > A2Driver.java 214 } 2150 > D A2Work.java 216 * Grading: 217 * Correctly follow the described algorithm to complete the method - 1.5pt 218 * Add operation counts 0.5pt 219 * f(N) formula (show your work) - 0.5pt * O(N) reduction 0.5pt */ 2220 public static Object[] algorithm2(int N) { 224 //DO NOT COUNT IN opCount 225 long opCount = 0; 226 String fn = "f(N) = (answer]"; 227 String On = "O(N) = (answer]"; 228 //BEGIN opCounts 229 int[] arr = new int[N]; 94230 boolean[] used = new boolean[N]; 94231 Random randGen = new Random( 123456789); 232 233 * Use the following method to fill the array 234 * For each position in the array, generate a random number between zero and N 235 * - If N = 10, random numbers should be 0-9 236 * Check if that used[random] is true * - If it is, generate a new number and try again 238 * - If it is not, place it into the position, set used[random] = true, and move forward 239 */ return new Object[] {arr, new String[] {fn, On, opCount+""}}; 2420 243 * Grading: 244 * Correctly follow the described algorithm to complete the method - 1.5pt 245 * Add operation counts - 0.5pt 246 * f(N) formula (show your work) - 0.5pt 247 * O(N) reduction 0.5pt 248 */ 2490 public static Object[] algorithm3 (int n) 250 { //DO NOT COUNT TN oncount Outline X 237 9 A2Work * sumo(int): String[] sum1(int): String[] sum2 (int) : String ssum 3(int) : String[] S sum4(int): String[] S sum5(int) : String[] sum 6(int): String] S algorithm1(int) : Object[] e algorithm2(int) : Object[] algorithm3 (int) : Object[] 240 241 . 251 Problems @ Javadoc X @ Declaration Console A A2Work Task List X 228 Find Activate... ? 2.230 4231 /* 233 eclipse-workspace - assignmentTwo/src/A2Work.java - Eclipse IDE File Edit Source Refactor Navigate Search Project Run Window Help TE D1- Package Expl.. X A2Work.java X D A2Driver.java 224 //DO NOT COUNT IN op Count 225 long opCount = 0; assignment Two 226 String fn = "f(N) = [ answer]"; > JRE System Library [jdk-1 227 String On = "0(N) = (answer]"; src //BEGIN op Counts 229 . (default package) int[] arr = new int[N]; > A2Driver.java boolean[] used = new boolean[N]; Random randGen = new Random( 123456789); > D A2Work.java 232 * Use the following method to fill the array 234 * For each position in the array, generate a random number between zero and N 235 * - If N = 10, random numbers should be 0-9 236 * Check if that used[random] is true 237 - If it is, generate a new number and try again 238 * - If it is not, place it into the position, set used[random] = true, and move forward 239 */ 240 return new Object[] {arr, new String[] {fn, On, opCount+""}}; 241 2420 243 * Grading: 244 * Correctly follow the described algorithm to complete the method - 1.5pt 245 * Add operation counts - 0.5pt 246 * f(N) formula (show your work) - 0.5pt 247 * O(N) reduction 0.5pt 248 public static Object[] algorithm3 (int N) 250 { 251 //DO NOT COUNT IN op Count long op Count = 0; String fn = "f(N) = (answer]"; String On - "O(N) - [answer]"; 255 //BEGIN opCounts 256 int[] arr - new int[N]; 94257 Random randGen = new Random( 123456789); 258 /* 259 * Use the following method to fill the array 260 * Fill the arr with zero to N-1 in order 261 * Run a loop through each position 262 * - For each position, swap that position and a randomly chosen position 263 */ 264 return new Object[] {arr, new String[] {fn, On, op Count+""}}; 265 } Outline X 249 252 253 254 9 A2Work * sumo(int): String[] sum1(int): String[] sum2 (int) : String ssum 3(int) : String[] S sum4(int): String[] S sum5(int) : String[] sum 6(int): String] S algorithm1(int) : Object[] e algorithm2(int) : Object[] algorithm3 (int) : Object[] . 266 ) 267 Problems @ Javadoc X @ Declaration & Console A A2Work A Task List X Find Activate... ? 6 7 8 13 14 18 eclipse-workspace - assignmentTwo/src/A2Driver.java - Eclipse IDE Eile Edit Source Refactor Navigate Search Project Run Window Help 19 Package Expl... x A2Work.java A2Driver.java X 1 import java.util. Arrays; assignmentTwo 3 public class A2Driver { > JRE System Library [jdk-1 src 50 public static void main(String[] args) { # (default package) int N = 10; > DA2Driver.java System.out.println("N = "+N); > D A2Work.java String[] ans = A2Work. sumo(N); 9 System.out.println("Sumo:"); 10 System.out.println((ans[0].equals("f(N) = 5N+4"))?"f(N) Correct (0.5pts)":ans[@]+" : f(N) = 5N+4"); 11 System.out.printiniansi].equals("O(N) = N"))?"(N) correct (0.5pts)": ans[1]+" : O(N) ='N"); 12 long count = Long.parselong(ans[2]); long correct = 54; double accuracy - Math.abs(correct-count)/(double) correct*100;//allow up to 5% off 15 System.out.println((accuracy Package Exp... X D A2Work.java A2Driver.java X 17 System.out.println("Sumo:"+Arrays.toString(A2Work. SON))); 18 System.out.println("Sum1:"+Arrays.toString(A2Work.s(N))); assignment Two 19 System.out.println("Sum2:"+Arrays.toString(A2Work. s.2(N))); > JRE System Library [jdk-1 20 System.out.println("Sum3:"+Arrays.toString(A2Work.s3(N))); src 21 System.out.println("Sum4 :"+Arrays.toString(A2Work. Sw4(N))); 22 & (default package) System.out.println("Sum5:"+Arrays.toString(A2Work.sum (N))); 23 > DA2Driver.java System.out.println("Sum6:"+Arrays.tostring(A2Work. sum6(N))); 24 System.out.println(); > A2Work.java System.out.println("N = "+N); System.out.println("Alg 1"); Object[] answer = A2Work.atgorithmi (N); System.out.println("Array Data Check:"+checkArray( (int[])answer[0])); 29 System.out.println(Arrays.toString((String[])answer [1])); 30 System.out.println("Alg 2"); 31 answer = A2Work.odgoritm2(N); 32 System.out.println("Array Data Check:"+checkArray( (int[])answer[0])); 33 System.out.println(Arrays.toString((String[])answer [1])); 34 System.out.println("Alg 3"); 35 answer = A2Work.atgorithm3(N); 36 System.out.println("Array Data Check:"+checkArray( (int[])answer[0])); 37 System.out.println(Arrays.toString((String[])answer [1])); 38 System.out.println(); 39 40 public boolean checkArray(int[] arr) 42 { 43 Arrays. sort(arr); 44 int size arr.length; 45 for(int i = 1; i = size)/o value larger than the size, use zero to N-1 { return false; } } Outline X 6 12 R v. A2Driver .main(String[]); void ScheckArray(int[]): boolean return true; 59} 60 Problems @ Javadoc X @ Declaration & Console A2Driver A Task List X Find Activate... ? 6 7 8 9 eclipse-workspace - assignmentTwo/src/A2Work.java - Eclipse IDE File Edit Source Refactor Navigate Search Project Run Window Help PRO 12-16 Package Expl.. X A2Work.java X DA2Driver.java 1 import java.util. Random; assignmentTwo 3 public class A2Work { > JRE System Library [jdk-1 /* src 5 * NOTES: # (default package) * Include notes about f(n) for partial credit, similar to what I put in sumo() > A2Driver.java * your f(n) does not need to produce the exact answer as your op count for all sums, but it should be close > D A2Work.java * use estimates based on rules we discussed to determine f(N) * For algorithm 1-3, assume random number generator never produces the same value twice in a given loop, but that it does produce the worst possible order of values 10 11 * 12 130 14 Grading: 15 * THIS IS AN EXAMPLE 16 170 public static String[] sumo(int N) 18 19 //DO NOT COUNT IN op Count long opCount = 0; 21 String fn = "f(N) = 5N+4";//sum assignment, loop, and return combined 22 String On = "O(N) = N";//Growth rate of function as value of N changes - Linear //BEGIN opCounts long sum = 0; op Count++;//assignment of sum /* Outline X op Count++;//assignment of i - happens as loop starts opCount++;//comparison - happens as loop starts for(int i = 0; i JRE System Library [jdk-1 43 return new String[] {fn, On, opCount+""}; src 44 . (default package) 450 /* > A2Driver.java 46 * Grading: 47 > D A2Work.java * Add operation counts - 0.5pt 48 * f(N) formula (show your work) - 0.5pt 49 * O(N) reduction 0.5pt 50 510 public static String[] suml(int N) 52 { 53 //DO NOT COUNT IN opCount 54 long op Count = 0; 55 String fn = "f(N) = (answer]"; 56 String On = "O(N) = (answer]"; 57 //BEGIN opCounts 26 58 long sum = 0; 59 for(int i = 0; i JRE System Library [jdk-1 85 v src 86 return new String[] {fn, On, op Count+""}; . (default package) 87 > A2Driver.java 89 * Grading: > D A2Work.java 90 * Add operation counts - 0.5pt 91 * f(N) formula (show your work) - 0.5pt 92 * O(N) reduction 0.5pt 93 940 public static String[] sum3 (int n) 95 { 96 //DO NOT COUNT IN opCount 97 long opCount = 0; 98 String fn = "f(N) = (answer]"; 99 String On - "O(N) = [answer]"; 100 //BEGIN opCounts long sum = 0; 102 for(int i = 0; i JRE System Library [jdk-1 127 for(int j = 0; j A2Driver.java 130 } 131 > D A2Work.java 132 return new String[] {fn, On, opCount+""}; 133 } 1340 135 * Grading: 136 * Add operation counts - 0.5pt 137 * f(N) formula (show your work) - 0.5pt 138 * O(N) reduction 0.5pt 139 */ 1400 public static String[] sum(int N) 141 { 142 //DO NOT COUNT IN opCount 143 long op Count = 0; 144 String fn = "f(N) = (answer]"; 145 String On = "O(N) = (answer]"; 146 //BEGIN opCounts 9.147 long sum = 0; 148 for(int i = 0; i JRE System Library [jdk-1 169 long opCount = 0; src 170 String fn = "f(N) = [answer]"; . (default package) 171 String On = "O(N) = (answer]"; > A2Driver.java 172 //BEGIN op Counts > D A2Work.java 94173 long sum = 0; 174 for(int i = 1; i JRE System Library [jdk-1 211 * - If it is not used anywhere else, place it into the position and move forward src 212 # (default package) 213 return new Object[] {arr, new String[] {fn, On, op Count+""}}; > A2Driver.java 214 } 2150 > D A2Work.java 216 * Grading: 217 * Correctly follow the described algorithm to complete the method - 1.5pt 218 * Add operation counts 0.5pt 219 * f(N) formula (show your work) - 0.5pt * O(N) reduction 0.5pt */ 2220 public static Object[] algorithm2(int N) { 224 //DO NOT COUNT IN opCount 225 long opCount = 0; 226 String fn = "f(N) = (answer]"; 227 String On = "O(N) = (answer]"; 228 //BEGIN opCounts 229 int[] arr = new int[N]; 94230 boolean[] used = new boolean[N]; 94231 Random randGen = new Random( 123456789); 232 233 * Use the following method to fill the array 234 * For each position in the array, generate a random number between zero and N 235 * - If N = 10, random numbers should be 0-9 236 * Check if that used[random] is true * - If it is, generate a new number and try again 238 * - If it is not, place it into the position, set used[random] = true, and move forward 239 */ return new Object[] {arr, new String[] {fn, On, opCount+""}}; 2420 243 * Grading: 244 * Correctly follow the described algorithm to complete the method - 1.5pt 245 * Add operation counts - 0.5pt 246 * f(N) formula (show your work) - 0.5pt 247 * O(N) reduction 0.5pt 248 */ 2490 public static Object[] algorithm3 (int n) 250 { //DO NOT COUNT TN oncount Outline X 237 9 A2Work * sumo(int): String[] sum1(int): String[] sum2 (int) : String ssum 3(int) : String[] S sum4(int): String[] S sum5(int) : String[] sum 6(int): String] S algorithm1(int) : Object[] e algorithm2(int) : Object[] algorithm3 (int) : Object[] 240 241 . 251 Problems @ Javadoc X @ Declaration Console A A2Work Task List X 228 Find Activate... ? 2.230 4231 /* 233 eclipse-workspace - assignmentTwo/src/A2Work.java - Eclipse IDE File Edit Source Refactor Navigate Search Project Run Window Help TE D1- Package Expl.. X A2Work.java X D A2Driver.java 224 //DO NOT COUNT IN op Count 225 long opCount = 0; assignment Two 226 String fn = "f(N) = [ answer]"; > JRE System Library [jdk-1 227 String On = "0(N) = (answer]"; src //BEGIN op Counts 229 . (default package) int[] arr = new int[N]; > A2Driver.java boolean[] used = new boolean[N]; Random randGen = new Random( 123456789); > D A2Work.java 232 * Use the following method to fill the array 234 * For each position in the array, generate a random number between zero and N 235 * - If N = 10, random numbers should be 0-9 236 * Check if that used[random] is true 237 - If it is, generate a new number and try again 238 * - If it is not, place it into the position, set used[random] = true, and move forward 239 */ 240 return new Object[] {arr, new String[] {fn, On, opCount+""}}; 241 2420 243 * Grading: 244 * Correctly follow the described algorithm to complete the method - 1.5pt 245 * Add operation counts - 0.5pt 246 * f(N) formula (show your work) - 0.5pt 247 * O(N) reduction 0.5pt 248 public static Object[] algorithm3 (int N) 250 { 251 //DO NOT COUNT IN op Count long op Count = 0; String fn = "f(N) = (answer]"; String On - "O(N) - [answer]"; 255 //BEGIN opCounts 256 int[] arr - new int[N]; 94257 Random randGen = new Random( 123456789); 258 /* 259 * Use the following method to fill the array 260 * Fill the arr with zero to N-1 in order 261 * Run a loop through each position 262 * - For each position, swap that position and a randomly chosen position 263 */ 264 return new Object[] {arr, new String[] {fn, On, op Count+""}}; 265 } Outline X 249 252 253 254 9 A2Work * sumo(int): String[] sum1(int): String[] sum2 (int) : String ssum 3(int) : String[] S sum4(int): String[] S sum5(int) : String[] sum 6(int): String] S algorithm1(int) : Object[] e algorithm2(int) : Object[] algorithm3 (int) : Object[] . 266 ) 267 Problems @ Javadoc X @ Declaration & Console A A2Work A Task List X Find Activate... ? 6 7 8 13 14 18 eclipse-workspace - assignmentTwo/src/A2Driver.java - Eclipse IDE Eile Edit Source Refactor Navigate Search Project Run Window Help 19 Package Expl... x A2Work.java A2Driver.java X 1 import java.util. Arrays; assignmentTwo 3 public class A2Driver { > JRE System Library [jdk-1 src 50 public static void main(String[] args) { # (default package) int N = 10; > DA2Driver.java System.out.println("N = "+N); > D A2Work.java String[] ans = A2Work. sumo(N); 9 System.out.println("Sumo:"); 10 System.out.println((ans[0].equals("f(N) = 5N+4"))?"f(N) Correct (0.5pts)":ans[@]+" : f(N) = 5N+4"); 11 System.out.printiniansi].equals("O(N) = N"))?"(N) correct (0.5pts)": ans[1]+" : O(N) ='N"); 12 long count = Long.parselong(ans[2]); long correct = 54; double accuracy - Math.abs(correct-count)/(double) correct*100;//allow up to 5% off 15 System.out.println((accuracy Package Exp... X D A2Work.java A2Driver.java X 17 System.out.println("Sumo:"+Arrays.toString(A2Work. SON))); 18 System.out.println("Sum1:"+Arrays.toString(A2Work.s(N))); assignment Two 19 System.out.println("Sum2:"+Arrays.toString(A2Work. s.2(N))); > JRE System Library [jdk-1 20 System.out.println("Sum3:"+Arrays.toString(A2Work.s3(N))); src 21 System.out.println("Sum4 :"+Arrays.toString(A2Work. Sw4(N))); 22 & (default package) System.out.println("Sum5:"+Arrays.toString(A2Work.sum (N))); 23 > DA2Driver.java System.out.println("Sum6:"+Arrays.tostring(A2Work. sum6(N))); 24 System.out.println(); > A2Work.java System.out.println("N = "+N); System.out.println("Alg 1"); Object[] answer = A2Work.atgorithmi (N); System.out.println("Array Data Check:"+checkArray( (int[])answer[0])); 29 System.out.println(Arrays.toString((String[])answer [1])); 30 System.out.println("Alg 2"); 31 answer = A2Work.odgoritm2(N); 32 System.out.println("Array Data Check:"+checkArray( (int[])answer[0])); 33 System.out.println(Arrays.toString((String[])answer [1])); 34 System.out.println("Alg 3"); 35 answer = A2Work.atgorithm3(N); 36 System.out.println("Array Data Check:"+checkArray( (int[])answer[0])); 37 System.out.println(Arrays.toString((String[])answer [1])); 38 System.out.println(); 39 40 public boolean checkArray(int[] arr) 42 { 43 Arrays. sort(arr); 44 int size arr.length; 45 for(int i = 1; i = size)/o value larger than the size, use zero to N-1 { return false; } } Outline X 6 12 R v. A2Driver .main(String[]); void ScheckArray(int[]): boolean return true; 59} 60 Problems @ Javadoc X @ Declaration & Console A2Driver

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

Differentiate between logical and physical storage and records

Answered: 1 week ago