Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this assignment, you will be writing code to generate test data and benchmark sorting algorithms on it ( edited from Sedgewick and Wayne: 2
For this assignment, you will be writing code to generate test data and benchmark sorting algorithms on
it edited from Sedgewick and Wayne: Already provided for you is CompletedBenchmarkTool.java
which contains the sorting algorithms: insertion sort and shellsort. As usual, it's not complete just yet.
This class extends an interface called BenchmarkTool which denes all of the methods that you need to
create. You may create additional private helper methods. Before writing any code, you should write
up your hypotheses per algorithm to describe what you think the running time will look like on each
algorithminput combination see Writeup below Your rst step to benchmarking the algorithms will be
to write a series of methods to generate test data that is nonuniform:
Implement the method public Integer generateTestDataBinaryint size Half the data is s half s
For example, an input of length might look like See the interface. points
Implement the method public Integer generateTestDataHalfsint size Half the data is s half the
remainder is s half the reminder is s half the reminder is s and so forth. For example, an input of
length might look like See the interface. points
Implement the method public Integer generateTestDataHalfRandomint size Half the data is s
half random int values use nextInt from Java's Random package, and use Integer.MAXVALUE as
its argument to ensure the values are positive For example, an input of length might look like
See the interface. points
Each of these three techniques should be implemented as a method that takes an int representing the size of
a dataset, and returns an Integer array containing that number of elements generated with the corresponding
rule. Do not randomize shue the contents of the generated arrays. You may assume that only arrays
with a power length will need to be created.
For each of the sorting algorithms, your program should run them on the three types of test data. Test
them with datasets size of and If your system is so fast that you don't get good results, you
may increase the dataset size. If your system continues to generate strange values even with a large dataset
size, try turning o compiler optimizations. Time each of the tests with the Stopwatch class discussed in
class. The program needs to compute the result of the doubling formula on the run times from the sample
data generated to get the power b for that algorithm on that type of input, and then display it Six
dierent values should be shown if you have properly implemented all of the benchmarks.
Implement the method public double computeDoublingFormuladouble t double t See the interface
for more information. points
Implement the method public double benchmarkInsertionSortInteger small, Integer large See the
interface for more information. points
Implement the method public double benchmarkShellsortInteger small, Integer large See the interface for more information. points
Implement the method public void runBenchmarksint size Whitespace is exible any number of
tabs or spaces but you must show three decimal places. See the interface for more information. Hint:
should call the two benchmark methods above. The output should look like b
Step 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