Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Java, Thanks!!! Tasks: Part of the code that must be used: PART 2: Completing IntArrays.java Task 1. Complete the quickSort(int[] a, int start, int
In Java, Thanks!!!
Tasks:
Part of the code that must be used:
PART 2: Completing IntArrays.java Task 1. Complete the "quickSort(int[] a, int start, int end, PrintStream out)" method and the "partition(int[] a, int start, int end)" method according to the Quicksort algorithm. "quickSort(int[] a, int start, int end, PrintStream out)" method is to show the "a" at the end of each partitioning using the PrintStream "out": First, for a certain time limit that you choose (e.g., 15 minutes), try to implement the methods mentioned above based only on your understanding of the Quicksort algorithm (without looking at pages 82 and 97 in 07 sorting.pdf). Once you finish these methods (or after the time limit), compare your implementation with the Java code on pages 82 and 97 in 07_sorting.pdf. It is fine to use the code in 07_sorting.pdf, but please do your best to understand that code When you complete this task, the following code in IntArrays.java\#main(String[) int []a={5,3,1,2,4} will output: [4,3,1,2,5] [2,3,1,4,5] [1,2,3,4,5] (Arrays.copyOf(a, a.length), System.out) The above result shows the content of the array "a" at the end of each partitioning while Quicksort is applied to that array. Task 2. Complete the "sequentialSearch(int[] a, int x )" method so that it can find the location of the specified value " x " in the specified array "a" using the sequential search algorithm (this method needs to return 1 if " x " is not contained in "a"). For a certain time limit that you choose (e.g., 5 minutes), try to implement the "sequentialSearch(int] a, int x)" method Please understand that, during each pass, sequential search examines only one element. If that element is equal to " x ", then it needs to return the location of that element in the array. If all of the passes fail to find " x " (i.e., " x " is not in array "a"), then the method needs to return 1. Once you finish the method (or after the time limit), compare your implementation with the Java code on page 3 in 08_searching.pdf. You can use the code on page 3 (but some slight changes may be needed to fix minor compile errors) When you complete this task, the following code in IntArrays.java\#main(String[]) a=new int []{1,2,3,4,5} int []={1,3,5,7,9,11,13} System.out.println(sequentialSearch (a,2)) System.out.println(sequentialSearch (a,7) ) System.out.println(sequentialSearch (b,2))i, System.out.println(; will output The above result shows that: 2 is in "a" at index 1 7 is NOT in "a", 7 is in " b " at index 3. Task 3. Complete the "binarySearchRecursive(int[] a, int lower, int upper, int x )" method so that it can find the location of the specified value " x " in the specified array "a" in the portion bounded by "lower" and "upper" using the RECURSIVE binary search algorithm (this method needs to return 1 if " x " is not contained in "a") For a certain time limit that you choose (e.g., 15 minutes), try to implement the "binarySearchRecursive(int[] a, int lower, int (without looking at page 6 in 08 searching.pdf) Please understand that, given a portion of the array "a[lower..upper]", binary search compares the element in the midd If " a[middle]" is equal to " x ", then the method returns "middle" (i.e., the location of "a[middle]" which is equal to "x"). If "a[middle]" is smaller than " x " (i.e., "x" is greater than "a[middle]"), then the method must apply itself to "a[middle +1..upper]" and then return the result If "a[middle]" is greater than " x " (i.e., "x" is smaller than "a[middle]"), then the method must apply itself to "a [lower..middle-1]" and then return the result. Once you finish the method (or after the time limit), compare your implementation with the Java code on page 6 in 08_searching.pdf You can use the code on page 6 , but please do your best to understand the code. When you complete this task, the following code in IntArrays.java\#main(String[): System.out.println(binarySearchRecursive (a,0, a.length - 1, 2)) System.out.println(binarySearchRecursive (a,0, a.length 1,7)) System.out.println(binarySearchRecursive (b,0, b.length 1,2)) System.out.println(binarySearchRecursive(b, 0, b.length - 1, 7)); System.out.println(; will output: The above result shows that 2 is in "a" at index 1 , 7 is NOT in "a" 2 is NOT in "b", and 7 is in "b" at index 3. Task 4. Complete the "binarySearchlterative(int[] a, int x )" method so that it can find the location of the specified value " x " in the specified array "a" using the ITERATIVE binary search algorithm (this method needs to return 1 if " x " is not contained in "a"). For a certain time limit that you choose (e.g., 15 minutes), try to implement the "binarySearchlterative(int[] a, int x)n " method based only on your understanding of the algorithm (without looking at page 7 in 08_searching.pdf). Please understand that this method needs to maintain two variables "lower" and "upper" in order to focus on a portion of the array "a[lower..upper] method needs to compare the element in the middle (i.e. "a[middle]" where "middle =( lower +upper)/2") with "x". If "a[middle]" is equal to " x ", then the method returns "middle" (i.e., the location of "a[middle]" which is equal to " x "). If "a[middle]" is smaller than " x " (i.e., " x " is greater than "a[middle]"), then the method needs to set "lower" to "middle +1 to focus only on "a[middle +1.. upper]" If "a[middle]" is greater than " x " (i.e., " to focus only on "a[lower..middle-1]" Once you finish the method (or after the time limit), compare your implementation with the Java code on page 7 in 08 searching.pdf. You can use the code on page 7 , but please do your best to understand the code When you complete this task, the following code in IntArrays.java\#main(String[) System.out.println(binarySearchlterative (a,2) ); System.out.println(binarySearchlterative (a,7))i System.out.println(binarySearchlterative (b,2) ); System.out.println(; will output: The above result shows that 2 is in "a" at index 1 , 7 is NOT in "a" public static float sequentialSearch(float [] a, float x){ // TODO: add some code here return -1; public static float binarySearchRecursive(float [] a, float lower, float upper, float x){ // TODO: add some code here return -1; public static float binarySearchIterative(float [] a, float x){ TODO: add some code here ? return - 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started