subject

In this assignment you will practice predicting and verifying the impact of data "nature" on the run-time of sorting algorithms. As we have seen with algorithms like insertion sort, the runtime (even worse case like Big-Oh) can be impacted by the nature of the input.

To do this, we will create three different types of input data, that may give different results when sorted. Two sorting algorithms(selection sort and insertion sort) will then be benchmarked on these three types of data. Each algorithm will be run twice, for different dataset sizes, in order to get times that we can use to apply the doubling formula. (See slide 23 (Modeling Small Datasets) in the Analysis of Algorithms slide deck for details on the doubling

formula.) The doubling formula is lg > T(N).If we compute the formula, then we will be able to figure out the algorithm's Big-Oh for a particular type of input data, since they will be O(nb).

Requirements

For this assignment you will be writing code to generate test data, as well as benchmark sorting algorithms on it (edited from Sedgewick and Wayne: 2.1.36). First, write a series of methods that generate test data that is "non-uniform":

Half the data is 0s, half 1s.

Half the data is 0s, half the remainder is 1s, half the reminder is 2s, and so forth.

Half the data is 0s, half random int values (can use nextInt() from Java's Random package) .

Each of these three techniques should be implemented as a static method that takes an integer representing the size of a dataset and returns an integer array containing that number of elements generated with the corresponding rule. Randomize (shuffl­e) the contents of the array after you populate it.

Using the three methods you implement, develop and test hypotheses about the effect of input on the performance of two of the algorithms (your choice) we have covered. (Get their source code from BlackBoard.)

The program should contain your hypotheses (3 per algorithm) as comments: describe what you think the running time will look like (O(n)? O(n2)? O(n3)?) on each data set and explain briefly why you think that. As long as your ideas make sense, you will receive full credit on the hypotheses

For each of the two sorting algorithms, you should run them on the three types of test data. Test them with datasets size of 2048 and 4096. Time each of these twelve tests with the Stopwatch class given in class. (If your system is so fast you don't get good results, you may increase the dataset size.)

Display the result of applying the doubling formula to the run times from the 2048 and 4096 test pairs to get the power ("b") for that algorithm on that type of input.

Testing

The main functionality to test is the methods that generate test data. You will want to run them multiple times, on different sizes, and display their output. Check that the output matches the patterns required above. There isn't much else to test for this homework. The algorithms you are benchmarking have already been tested for correctness. Optionally, you may want to try giving an input that is pure random numbers to each of the algorithms and checking if your doubling formula code gives the algorithms expected Big-Oh.

The Stopwatch Class is given:

public class Stopwatch {

private final long start;

public Stopwatch() {

start = System. currentTimeMillis();

}

public double elapsedTime() {

long now = System. currentTimeMillis();

return (now - start) / 1000.0;

}

}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 19:00
Jill wants to become a network professional. which certification would be useful for her? a. mcse b. pmp c. comptia a+ d. ccie
Answers: 2
question
Computers and Technology, 22.06.2019 11:00
Which action is good business etiquette? a. switching your cell phone off before you enter a meeting b. keeping your cell phone on low volume before you enter a meeting c. setting a pleasant ring tone on your cell phone before you enter a meeting d. setting a standard ringtone on your cell phone before you enter a meeting
Answers: 1
question
Computers and Technology, 22.06.2019 12:10
1. package newton’s method for approximating square roots (case study 3.6) in a function named newton. this function expects the input number as an argument and returns the estimate of its square root. the script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2. convert newton’s method for approximating square roots in project 1 to a recursive function named newton. (hint: the estimate of the square root should be passed as a second argument to the function.) 3. elena complains that the recursive newton function in project 2 includes an extra argument for the estimate. the function’s users should not have to provide this value, which is always the same, when they call this function. modify the definition of the function so that it uses a keyword parameter with the appropriate default value for this argument, and call the function without a second argument to demonstrate that it solves this problem. 4. restructure newton’s method (case study 3.6) by decomposing it into three cooperating functions. the newton function can use either the recursive strategy of project 1 or the iterative strategy of case study 3.6. the task of testing for the limit is assigned to a function named limitreached, whereas the task of computing a new approximation is assigned to a function named improveestimate. each function expects the relevant arguments and returns an appropriate value. 5. a list is sorted in ascending order if it is empty or each item except the last one is less than or equal to its successor. define a predicate issorted that expects a list as an argument and returns true if the list is sorted, or returns false otherwise. (hint: for a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return false if the first item in a pair is greater.)
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Spoons are designed to be used for: spring hammering. applying body filler. identifying high and low spots. sanding highly formed areas.
Answers: 3
You know the right answer?
In this assignment you will practice predicting and verifying the impact of data "nature" on the run...
Questions
question
Mathematics, 22.11.2019 23:31
question
History, 22.11.2019 23:31
question
Mathematics, 22.11.2019 23:31