Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using java You should write a program that does the following: Create two arrays of type int[]. Both arrays should be the same size, and

using java You should write a program that does the following:

Create two arrays of type int[]. Both arrays should be the same size, and the size should be given by a constant in the program so that you can change it easily.

Fill the arrays with random integers. The arrays should have identical contents, with the same random numbers in both arrays. To generate random integers with a wide range of sizes, you could use (int)(Integer.MAX_VALUE * Math.random()).

Sort the first array using either Selection Sort or Insertion Sort. You should add the sorting method to your program; you can copy it from Section 7.4, if you want. (It is a good idea to check that you got the sorting method correct by using it to sort a short array and printing out the result.)

Time how long it takes to sort the array, and print out the time.

Now, sort the second (identical) array using Arrays.sort(). Again, time how long it takes, and print out the time.

You should run your program using array sizes of 1,000, 10,000, and 100,000. Record the sort times. Add a comment to the top of the program that reports the times. (You might be interested in applying Arrays.sort() to a million-element array, but don't try that with Selection Sort or Insertion Sort!) Note: The general method for getting the run time of a code segment is: long startTime = System.currentTimeMillis(); doSomething(); long runTime = System.currentTimeMillis() - startTime; This gives the run time in milliseconds. If you want the time in seconds, you can use runTime/1000.0.

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_2

Step: 3

blur-text-image_3

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

Calculate the percentage for each item. LO.1

Answered: 1 week ago