Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In java, thanks a lot! Tasks: Part of code for each: Must match the test: Task 1 (30 points). Complete the sequentialSearch(float[] a, float x
In java, thanks a lot!
Tasks:
Part of code for each:
Must match the test:
Task 1 (30 points). Complete the "sequentialSearch(float[] a, float 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(float[] a, float x )" method based only on your understanding of the algorithm. 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 in the slides. You can use the code from the slides (but some slight changes may be needed). Your code also needs to pass the unit test named "test20" in "UnitTests.java". Task 2. Copy your sort code (any of the three) from Lab 5 into this lab. You will need to sort the arrays before you can binary search them. Task 3 (30 points). Complete the "binarySearchRecursive(float[] a, int lower, int upper, float 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(float[] a, int lower, int upper, float x )" method based only on your understanding of the algorithm. Please understand that, given a portion of the array "a[lower..upper]", binary search compares 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 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, compare your implementation with the Java code in the slides. Your code also needs to pass the unit test named "test30" in "UnitTests.java". Task 4 (40 points). Complete the "binarySearchlterative(float[] a, float 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(float[] a, float x)" method based only on your understanding of the algorithm. 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]". This 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., " x " is smaller than "a[middle]"), then the method needs to set "upper" to "middle-1" 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 in the slides. Your code also needs to pass the unit test named "test4()" in "UnitTests.java". public static int sequentialSearch(float [] a, float x){ // TODO: add some code here return -1; public static int binarySearchRecursive(float [] a, float lower, float upper, 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