Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Assignment: Your goal is to determine an empirical estimate of the efficiency of two algorithms. To do this you need to be able to

JAVA image text in transcribed

image text in transcribed

Assignment: Your goal is to determine an empirical estimate of the efficiency of two algorithms. To do this you need to be able to calculate the execution time of a method. This can be done by using a system method to query the current system time before and after executing the method the time elapsed is the difference between the two. In Java, you can use the method call System.currentTimeMillis() to get the time in milliseconds as a long. If the execution times are very small you can also use System.nanoTime (). This method is not as accurate, but you can use it to get greater precision if you are consistently seeing millisecond times of 0. Main task: Implement two search algorithms, linear and binary, that work on an array of doubles. Java files: Search.java should contain two search techniques: (1) a linear search to search in an array of doubles, (2) a binary search method to search in an ordered array Other requirements: Search.java must have (and you must use it) a method that implements linear search and binary search algorithms. Each method must return the location of the element searched for in an array, or return -1 if the element is not in the array More requirements: To get an accurate estimate of the time taken, you will need to generate a number of test cases and average the resulting times. Suppose first that we aim to estimate the time taken for a list of 10000 numbers. Here are the steps to perform: a. Generate a new aray with 10000 elements, and initialize the elements to random values using Math.random0. b. Sort the array using Arrays.sort0. Remember that binary search works on ordered arrays only c. Select the value to search for by selecting a random index between 0 and 9999 and using that value (so you can be sure the value is in the array) Select the random index using Math.randomO d. Run linear and binary search for the same element on the sorted array, and

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

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago