Benchmarking sorting algorithms

Assignment Help JAVA Programming
Reference no: EM132430677

Part 1: Benchmarking Sorting Algorithms

The same task can take vastly different amounts of time, depending on the algorithm that is used to perform the task. You are familiar with simple sorting algorithms such as insertion sort and selection sort. (See Section 7.4 in the textbook.) While these methods work fine for small arrays, for larger arrays they can take an unreasonable amount of time. The question is whether we can do any better.

Java has some built-in sorting methods. They can be found in the class named Arrays in the package java.util. The one that you will use in this lab is Arrays.sort(A), which sorts the entire array A into increasing order. (Actually, there are different methods for different array base types, but all the methods have the same name and are used in the same way. You will be using an array of ints in this lab.)

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.

Reference no: EM132430677

Questions Cloud

Deter information theft : "Deter Information Theft. Describe the Computer Fraud and Abuse Act and how it influenced businesses.
Describe the variables used in the analysis : Describe the variables used in the analysis, along with the level of measurement (i.e., nominal, ordinal, interval, or ratio) for each variable.
Developing erm plan for organization : Decide which key policies and procedures one should consider as the starting point when developing an ERM plan for an organization.
How you plan to create a productive learning environment : Imagine that you have been contacted by your school principal to deliver a presentation at "Back to School Night" for your sixth grade class, their parents.
Benchmarking sorting algorithms : The same task can take vastly different amounts of time, depending on the algorithm that is used to perform the task. You are familiar with simple sorting
Design a program that reads and displays all of the numbers : Design a program that reads and displays all of the numbers stored in the file and calculates their total.
What are the causes of depression debate preparation : Causes of Depression Debate Preparation and Summary. Apply psychological principles to topics in psychology. State a position on the causes of depression.
Why is an array like a list : Why is an array like a list? How do you identify and find elements in an array? Explain the purpose of a try-catch block and give an example.
Input-output-validation-functions-loops and decisions : Input, Output, Validation, Functions, Loops and Decisions You will need to have 1 functions, one or more arrays, one or more loops.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd