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

  Use javascript to write the onmouseenter event handler

Use JavaScript to write the onmouseenter event handler for the mouse enter event of the img tags (similar to the onclick event handler of the img tags in the ImageSwap/SlideShow applications). This handler should change the src attribute of the im..

  Write a program that can be used to gather statistical data

Write a program that can be used to gather statistical data about the number of movies college students see in a month. The program should ask the user how many students were surveyed and dynamically allocate an array of that size

  The burn and distance traveled

The Burn and distance traveled and the "meters to go" should appear on two lines as shown in the sample output. Note that this print should be done within the while loop.

  Discuss factors that affect sorting in sediment

Discuss factors that affect sorting in sediment. How could one tell the latitude at which a sediment was originally deposited? Compare and contrast phosphate and manganese nodules.

  Write a method called alldigitsodds

Write a method called AllDigitsOdds that returns whether every digit of a positive integer is odd.

  Java program should be divided in at least 3 classes

This Java program should be divided in at least 3 classes like Display.java, Input.java and ErrorHandling.java

  Scanning and parsingimplement the lexical and syntactic

scanning and parsingimplement the lexical and syntactic analysis of minifun programming language. the scanner splits up

  Java swing components and file processing

Java Swing Components and File Processing, Write a program named GuessGame.java that plays the game "guess the number" as follows. Your program chooses the number to be guessed by selecting an integer at random in the range 1-1000. The program then..

  Make a row with different string names

How do you make a row with different string names and put a certain amount of space between each one?

  Insert uml design diagrams, use case, classes

Insert UML design diagrams here (use case, class, and sequence diagram).

  Create a java class named headphone

Create a TestHeadPhone class that constructs at least 3 HeadPhone objects. For each of the objects constructed, demonstrate the use of each of the methods.

  The objective is to implement a menu-based system

The objective is to implement a menu-based system for Bank Accounts in order to simulate a very simple banking system. Many structures have to be declared to manage bank accounts.

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