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

  Depicts a model for recording flight and passenger

This assignment requires you to design, implement and test a program using Java features from the first half of the subject content. You are required to implement in Java all the classes presented in the conceptual model according the specificatio..

  Write complete java program to read from keyboard

Write complete Java program to read, from keyboard, a student's first and last name and six grades. It will display on screen last name then first letter of first name with a period.

  Design and develop a console application

Required to design and develop a console (text-based) application for a small car servicing company -

  Computer network and data communication

What are the question for computer network and data communication

  Program to mimic a student information management system

Write a Java program to mimic a student information management system. The main entry page should have at least following options:

  Display at least the waiting at each floor

From the 1st floor, the elevator can only go in one direction - up. And from the 12th floor the elevator can only go in one direction - down.

  Test plan for both unit testing and integration testing

Do a test plan for both unit testing and integration testing, justification why you need this test creating the test case for each individual test must use java language in netbeans IDE to perform each test, screen capture one example to run the ..

  Define inventory program assignment from java class

This is part 6 of the inventory program assignment from Java class IT 215 from UOP and all the codes are written well and includes everything all the functionality from the previous parts and there's absolutely no errors.

  Document the current application describing major classes

Add to the Project Management tool the different planned activities needed to implement the changes to the solution and document the current application describing the major classes used by the application.

  Determine the java application on web

Determine the Java application on Web and explain how program structure functions. Explain the application in as much detail as possible.

  Write program that uses top five countries national wealth

Write a program that uses the top five countries' National Wealth to calculate the average of those five countries.

  Develop java applet that will help elementary school student

Develop a Java applet that will help an elementary school student learn multiplication. Use the Math.random method or a Random object to produce two positive one-digit integers.

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