Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP!! UPVOTE GUaRANTEED! package a7; import java.util.Arrays; import java.util.Random; /** * This class has methods to compare the performance of sequential search and *

PLEASE HELP!! UPVOTE GUaRANTEED!

image text in transcribed

package a7; import java.util.Arrays; import java.util.Random; /** * This class has methods to compare the performance of sequential search and * binary search. * */ public class SearchTest { /** * Call the test method with an array size and repetition count and output * results. This method has been fully implemented for you. You should change * values in it for your investigation. * * @param args */ public static void main(String[] args) { int testArraySize = 1_000; // This is the size of the array to be searched. int numberOfRepetitions = 100; // This is the number of times the array is searched. int[] testData = randomSortedFill(testArraySize); int binaryCount = 0, sequentialCount = 0; Random generator = new Random(); for (int rep = 0; rep  key) is the only case left, so we don't need to check it. hi = mid - 1; } return -1; } /** * Search vals for the key using binary search. Assumes vals is sorted in * ascending order. * * @param vals * @param key * @return the number of == tests performed during the search. */ public static int binarySearchForKeyWithCount(int[] vals, int key) { return 0; // change this code } /** * Search vals for the key using sequential search. This code is provided as a * reminder of how sequential search works. You do not need to run it or modify * it. * * @param vals * @param key * @return the index where val is found, or -1 otherwise. */ public static int sequentialSearchForKey(int[] vals, int key) { for (int index = 0; index   Start with this code: SearchTest.java Search Experiment The basic idea of the search is to make an array of random values, sort them, and then compare the performance of binary search and sequential search. There are many ways to compare performance. For example, the amount of time spent getting an answer is one way. However, even this simple measure has complications. For example, if part of the experiment is run while playing a game on the same computer, this can distort results. Another issue is that code can run so fast on a computer that it is difficult to capture meaningful timings. Instead, you will use a simple measure the number of times a value in the array is tested to see if it is equal to the key. One reason to choose this cost is that getting the value can often be a bottleneck - maybe the value needs to be computed or retrieved from some large database Example binary search and sequential search are implemented in the experiment file. Your job is to modify those so they do not return an index value, but instead the number of times the array value was tested for equality with the key There is a main method that builds an array of test data, picks a random key, and searches for that key Since the randomness makes it possible for a particular search to find the key the first time it looks, the experiment code repeats the process of picking a random key and counting the search tests for a number of times. Finally, the results are averaged for binary search and for sequential search and the results are summarized. Modify this code to run experiments for different sized arrays. Use the good code style practices used in prior assignments. Decide what different sizes of arrays will provide insight into the relative performance of the search techniques. The bigger the repetitions value, the more accurate the average will be- something like a 100 repetitions is probably fine for this experiment. Record the average for each method in a table with the size of the array and average search count Write up a short document in a word processing system (Google docs, MS Word, laTEX) showing a neatly formatted chart or table. Then discuss why you chose the array sizes you tested and what trends you see in the experimental data. Add a graph, for example, using the plot.ly website to make a graph on the counts vs. array size or the chart wizards in Excel or Google Sheets. If you make a graph, insert it into the document and discuss it, do not make it a distinct document. A paragraph is likely a reasonable length for discussion. Add your name(s), assignment, and class to the document. Create a pdf (usually a "Save as" or Print to" pdf is a mechanism to do that) called SearchReport.pdf Testing Add a JUnit test for the search code (in the Package Explorer, right-click on the SearchTest.java file name, add New->Junit Test Case, pick JUnit 4). This should make a SearchTestTest.java file that you can modify. Add test methods that test the counting binary search and the counting sequential search methods. In those methods you should setup a small array, call the methods, then compare the count that is returned with the count you expect (by working through the search by hand, for example). Make sure the tests cover different scenarios the search can run into. I would expect something like 4 test methods in the SearchTestTes above since you want to be confident the code is working correctly ava file. You should probably build these tests before you gather a lot of experimental data  Start with this code: SearchTest.java Search Experiment The basic idea of the search is to make an array of random values, sort them, and then compare the performance of binary search and sequential search. There are many ways to compare performance. For example, the amount of time spent getting an answer is one way. However, even this simple measure has complications. For example, if part of the experiment is run while playing a game on the same computer, this can distort results. Another issue is that code can run so fast on a computer that it is difficult to capture meaningful timings. Instead, you will use a simple measure the number of times a value in the array is tested to see if it is equal to the key. One reason to choose this cost is that getting the value can often be a bottleneck - maybe the value needs to be computed or retrieved from some large database Example binary search and sequential search are implemented in the experiment file. Your job is to modify those so they do not return an index value, but instead the number of times the array value was tested for equality with the key There is a main method that builds an array of test data, picks a random key, and searches for that key Since the randomness makes it possible for a particular search to find the key the first time it looks, the experiment code repeats the process of picking a random key and counting the search tests for a number of times. Finally, the results are averaged for binary search and for sequential search and the results are summarized. Modify this code to run experiments for different sized arrays. Use the good code style practices used in prior assignments. Decide what different sizes of arrays will provide insight into the relative performance of the search techniques. The bigger the repetitions value, the more accurate the average will be- something like a 100 repetitions is probably fine for this experiment. Record the average for each method in a table with the size of the array and average search count Write up a short document in a word processing system (Google docs, MS Word, laTEX) showing a neatly formatted chart or table. Then discuss why you chose the array sizes you tested and what trends you see in the experimental data. Add a graph, for example, using the plot.ly website to make a graph on the counts vs. array size or the chart wizards in Excel or Google Sheets. If you make a graph, insert it into the document and discuss it, do not make it a distinct document. A paragraph is likely a reasonable length for discussion. Add your name(s), assignment, and class to the document. Create a pdf (usually a "Save as" or Print to" pdf is a mechanism to do that) called SearchReport.pdf Testing Add a JUnit test for the search code (in the Package Explorer, right-click on the SearchTest.java file name, add New->Junit Test Case, pick JUnit 4). This should make a SearchTestTest.java file that you can modify. Add test methods that test the counting binary search and the counting sequential search methods. In those methods you should setup a small array, call the methods, then compare the count that is returned with the count you expect (by working through the search by hand, for example). Make sure the tests cover different scenarios the search can run into. I would expect something like 4 test methods in the SearchTestTes above since you want to be confident the code is working correctly ava file. You should probably build these tests before you gather a lot of experimental data

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions