Programming sorting algorithms

Assignment Help JAVA Programming
Reference no: EM13709852

Programming Sorting Algorithms:

a. Describe an approach to modifying the Sorts.java program so that after calling a sorting method the program prints out the number of swaps needed by the sorting method.

b. Implement your approach.

c. Test your new program by running the selectionSort method.

Your program should report 49 swaps.

d. Now, modify your program to also output the number of comparisons (compares) needed.

You must include one or more statements to increment your counter within the sorting methods themselves.

For each of the listed methods, make and test the changes needed, and list both the number of swaps and the number of compares needed by the Sorts program to sort an array of 50 random integers.

selectionSort swaps:____

compares:____

bubbleSort swaps:____

compares:____

shortBubble swaps:____

compares:____

insertionSort swaps:____

compares:____

//---------------------------------------------------------------------------- //Sorts.java //

// Test harness used to run sorting algorithms.

//---------------------------------------------------------------------------- import java.util.*; import java.text.DecimalFormat; public class Sorts

{

static final int SIZE = 50;

// size of array to be sorted static int[] values = new int[SIZE];

// values to be sorted static void initValues()

// Initializes the values array with random integers from 0 to 99.

{ Random rand = new Random(); for (int index = 0; index < SIZE; index++) values[index] = Math.abs(rand.nextInt()) % 100; }

static public boolean isSorted() // Returns true if the array values are sorted and false otherwise.

{ boolean sorted = true; for (int index = 0; index < (SIZE - 1); index++) if (values[index] > values[index + 1]) sorted = false; return sorted; }

Reference no: EM13709852

Questions Cloud

How fast is each one going, when they are far apart : Two positive point charges, qa and qb (masses ma and mb) are at rest, half together by mass less string of length a. How fast is each one going, when they are far apart
Find the work done during the expansion : A piston cylinder with a set of stops contains 10 kg of R-134a refrigerant. Initially, 8kg of the R-134a is liquid and the rest a gas. At -8C. Find the work done during the expansion
Explain the process to finding information for research : We are often asked about things we don't have knowledge of, let's say you have been asked to determine how hospitals prepare and train volunteers.
Determine the magnitude of the lift force : A jet airplane is in level flight. The mass of the airplane is m = 8850 kg. What is the magnitude of the lift force acting on the plane
Programming sorting algorithms : Describe an approach to modifying the Sorts.java program so that after calling a sorting method the program prints out the number of swaps needed by the sorting method.
What is its closest approach to the surface of the nucleus : A proton is fired from far away toward the nucleus of a mercury atom. Mercury is element number 80, and the diameter of the nucleus is 14.0 fm. what is its closest approach to the surface of the nucleus
Explain the effective warehouse design : Why is it important for businesses to utilize their warehouse space effectively? Be sure to define "effective" and make a good argument for your position.
How much work is done by the object in sliding : A 2.0-kg object is at rest at the top of an inclined plane that makes an angle of 30° with the horizontal and which has a rise of 0.40 m. How much work is done by the object in sliding
How many grams of sucrose would have to be added : How many grams of sucrose would have to be added to 0.250 kg of water to elevate the boiling point by 5.0 Celcius

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