Implement your own simple algorithm

Assignment Help JAVA Programming
Reference no: EM131598080

She has a large file of students she would like to sort. It would be helpful to her to have the students sorted by the school they are attending and students attending the same school sorted by ID in ascending order. For example:
Joe Paarmann, 3, UCB
Otha Baloy, 5, UCB
...
Alton Hamblet,1,UCD
Jessie Merle,7,UCD
Lawanda Doell,9,UCD
...
Alva Zajicek, 4, UCI
...
Chester Kemfort,2,UCLA
Alice Mines,6,UCLA
...
She tried sorting the students herself but when she sorts by school the students are no longer sorted by ID within each school, and vice-versa. Having learned of stable sorting you agree to take on this simple task.

Part 1:
You plan to use the Java library stable sort to do the sorting. Since the sort is stable, you can do two consecutive sorts and end up with the needed result (note that which sort you do first matters).

To sort a list by some criteria in Java 7, you use the Collections.sort() method like below. The second argument is an implementation of the Comparator interface, which determines how two elements are compared.
Collections.sort(myList, myComparator);

Part 2:
It occurs to you that you don't need two separate sorts. You plan to write a single comparator that sorts by school and breaks ties by ID and use that to sort only once to get the desired result.

Part 3:
Both parts 1 and 2 were simple and fast enough, but you have a hunch you could probably make this a tiny bit faster. You decide to implement your own simple algorithm for the problem based on bucket sort. The idea is very simple:

- You create one bucket (a list) for each school.
- You do one pass through the input list and place each student you encounter into its corresponding bucket.
- You sort each of the buckets (by which field?) by using a comparator like in Part 1.
- You go through each bucket in order and put the students one by one into the original list.Hints:

A lot of the code has been given. All you need to do is fill out the empty bodied methods.

Make sure you are comfortable using the ArrayList class(we have seen most methods you will use in the lists lecture) and doing a simple sort using a comparator. You may want to try that with a list of strings first, just for some quick practice.

Reference no: EM131598080

Questions Cloud

Shadow banking system same as traditional banking system : How is the shadow banking system the same as the traditional banking system?
Was the scientific method followed : Was the Scientific method followed? How? What pieces were or were not part of it? (Randomization, study type, placebos, etc.)
Currency markets that have flexible exchange rates : Discuss how exchange rates are determined in currency markets that have flexible exchange rates. Provide an industry example to illustrate your explanation.
Make an oligopoly market : In 1 to 2 pages, please describe the key characteristics which make this an oligopoly market. State your case whether you believe the firms are cooperating.
Implement your own simple algorithm : You plan to use the Java library stable sort to do the sorting. Since the sort is stable, you can do two consecutive sorts and end up with the needed result
Discuss any legal issues : Discuss any legal issues regarding the grading of your student's essay and whether you could display the student's work.
Define the pegasus department heads : Determine the first 5 interventions you would recommend to begin the change-management reorganization and your rationale for why you would use.
Prepare the current balance sheet reflecting the changes : Prepare the current balance sheet reflecting the changes that occurred at the company during the year.
Observed trend in personal consumption expenditure : Visit this Economic Time Series page and explain how the observed trend in personal consumption expenditure since 2000 affected the Keynesian C + I + G + X.

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