Implement two priority queues that provided priorityqueue

Assignment Help JAVA Programming
Reference no: EM131444571

Computer Science Assignment

The main task is to implement two priority queues. All two implementations should implement the provided PriorityQueue interface (include implements PriorityQueue in your Java code), which means they should work with priorities that have type double and there are no corresponding items attached to the priorities. Your implementations should be as follows:

• A class BinaryHeap that implements a binary min-heap as we discussed in class, using an array to store the conceptual complete tree.
• A class ThreeHeap that implements a min-heap where each non-leaf node has 3 children.

You should still use a contiguous portion of an array to store the conceptual complete tree. We suggest you make a copy of your BinaryHeap class and make changes as necessary.

Put your two implementations in two separate Java files, BinaryHeap.java and ThreeHeap.java.

Assignment

1. Purpose

The purpose of this assignment is to implement priority queues.

2. Description

Implementation (30 points for BinaryHeap.java, 45 for ThreeHeap.java)

Your main task is to implement two priority queues. All two implementations should implement the provided PriorityQueue interface (include implements PriorityQueue in your Java code), which means they should work with priorities that have type double and there are no corresponding items attached to the priorities. Your implementations should be as follows:

• A class BinaryHeap that implements a binary min-heap as we discussed in class, using an array to store the conceptual complete tree.
• A class ThreeHeap that implements a min-heap where each non-leaf node has 3 children. You should still use a contiguous portion of an array to store the conceptual complete tree. We suggest you make a copy of your BinaryHeap class and make changes as necessary.

Put your two implementations in two separate Java files, BinaryHeap.java and ThreeHeap.java.

Your priority queues should allow duplicates. That is, two or more copies of the same value should be allowed to exist in the heap at the same time. For example, if you call deleteMin and you have {3.0, 3.0, 6.0, 7.0} in the heap, it would just return one of the 3.0 values, then on the next deleteMin it would return the other 3.0. It does not matter "which" 3.0 is returned first.

According to our definition of priority queue, what must be guaranteed is that both 3.0 values will be returned before a 6.0 or 7.0 is returned, and that the 6.0 would be returned before the 7.0.

Your implementations should automatically grow as necessary. (If interested, you may also have them shrink when appropriate; this is optional.) For any arrays, you should start with a small array (say, 10 elements) and resize to use an array twice as large whenever the array becomes full, copying over the elements in the smaller array. Do the copying with a for loop rather than any Java library methods (even though using the library is how one would normally do it). You may use the length field of an array as needed.

Be sure to test your solutions thoroughly and to turn in your testing code. For instance, you may generate 1000 random numbers, insert them into a priority queue, and keep deleteMin() as long as the priority queue is not empty. Part of the grading will involve thorough testing including any difficult cases. For this assignment, we will be grading more strictly for things like style and efficiency.

Questions

The questions include comparing the actual run-time of your implementations. We would expect the reports to be at least a couple of pages long, quite possibly longer to have room for relevant graphs or tables.

Submit a report.pdf file, answering the questions in this template report.docx file:

1. What is the worst case asymptotic running time of isEmpty, size, insert, findMin, and deleteMin operations on all your heap implementations? For this analysis you should ignore the cost of growing the array. That is, assume that you have enough space when you are inserting a value.

2. Which of your two implementations would you recommend to someone who needs to use a heap? Why is that one preferred? Are there any conditions under which you might suggest using your other implementations?

3. Briefly discuss how you went about testing your two heap implementations. Feel free to refer to your testing files, which you should submit.

4. You implemented a binary-heap and a three-heap. Now think if you can implement a four-heap, a five-heap, etc.

a. In a short table, indicate for a binary heap, a three-heap, a four-heap and a five- heap, where the children for the node at array index i are. For example, the first row of the table would indicate that for a binary heap, the two children would be at i*2 and i*2+1.

b. For a d-heap where d is a variable representing the number of children (like two, three, four, five, ...), give an arithmetic formula for calculating where the left- most child for the node at array index i are. For example, a wrong answer in the right format would be i*d+14. Naturally, your formula should produce the right answer for all the rows in your table from part (a).

The following suggestion is meant for you to try if you finish the requirements early.

1. Implement a d-heap where d is the number of children for non-leaf nodes. Your class should implement the same priority queue interface and it should use a contiguous array portion as in your first two implementations. It should include an empty constructor and additional constructor that takes d as an argument, work correctly for any d greater than or equal to 2, and use d as the number of children for nodes.

2. Implement a binary heap that works for any type (not just doubles). It should use Java generic types to allow any priority type that implements an appropriate interface for comparing two priorities and your heap should allow items of a second generic type that are "attached" to each priority. That is, each node contains a key-value pair, where key is the priority. Note this implementation will not implement the provided interface, so provide any additional comments necessary to explain how your class should be used.

Attachment:- Code.rar

Reference no: EM131444571

Questions Cloud

Compute the mean number of flips until the pattern : (a) Compute the mean number of flips until the pattern HHTHHTT appears. (b) Which pattern requires a larger expected time to occur: HHTT or HTHT?
Premium movie channel : Suppose that, when we survey 20 randomly selected dish owners, we fi nd that 4 of the dish owners actually subscribe to at least one premium movie channel. Using a probability you found in this exercise as the basis for your answer, do you believe..
Is the granger causality f-statistic significant : Let Rt denote the interest rate for three-month treasury bills. Estimate an ADL(1,4) model for ?Yt using lags of ?Rt, as additional predictors. Comparing the ADL(1,4) model to the AR(1) model, by how much has the 2 changed?
How much will you pay for the policy : The Maybe Pay Life Insurance Co. is trying to sell you an investment policy that will pay you and your heirs $37,000 per year forever. If the required return on this investment is 6.3 percent, how much will you pay for the policy?
Implement two priority queues that provided priorityqueue : CPS 350: The main task is to implement two priority queues. All two implementations should implement the provided PriorityQueue interface (include implements PriorityQueue in your Java code).
Poisson approximation to the binomial : What is the probability that of today's 1,400 callers at least 5 received a busy signal? Use the poisson approximation to the binomial. (Round your answer to 4 decimal places.)
Balance sheet and sales information using financial data : Complete the balance sheet and sales information using the following financial data: Total assets turnover: 1.3x Days sales outstanding: 42 daysa Inventory turnover ratio: 4x Fixed assets turnover: 2.5x Current ratio: 1.5x Gross profit margin on sale..
Discuss the reforms done or needed in that industry : HI5003  Economics for Business Assignment. Micro economics - Choose any industry and discuss the reforms done or needed in that industry. Demand and supply of a product of your choice and factors that affect the demand and supply sides of the market
Why did we use nodular cast iron in this application : We are designing a camshaft for a direct acting mechanical bucket (DAMB) valvetrain - assume a single cylinder and a single valve for this analysis.The material is nodular cast iron. At max lift on the camshaft lobe, the valve is to open 10mm. T..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java program to simulate a die

Write a Java program to simulate a die. A die has values of either 1, 2, 3, 4, 5 or 6 on the face. You should use the Math.Random() or the java.util.Random() class to generate the values on the die. The program should prompt the user to enter how ..

  Populate a one-dimensional array

Populate a one-dimensional array with the following grades in this order: 93, 61, 72, 45, 84, 51, 70, 83, 96, and 66. Use a loop to call a method from main() that adds

  Compute the temperature in centigrade

Compute the temperature in Centigrade - Display the temperatures in both Centrigrade and Fahrenheit with appropriate labels, using the + operator to concatenate the labels with the variables

  Develop and re-wrap the trivial console application

COS30016/HIT3037 Programming in Java - Develop and re-wrap the trivial console application into a GUI Application which allows the users to perform similar operations as indicated in assignment 1 handout.

  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.

  Create two house object using constructor with two parameter

Create two House objects using the constructor with two parameters, plug in the data below as the actual parameters of the constructor. Each line below contains the two actual parameters for one object.

  Sorted list adt and the binary search tree adt

Explain the differences between our specifications of the Sorted List ADT and the Binary Search Tree ADT.

  Create java application to add a contact into contact table

Develop a Java application to add a contact into the contact table, and display all contacts in the contact table. The contact table contains two columns, FullName, and PhoneNumber. Both values are text data.

  Design a program that will gather a group of floating point

Design and implement a Java program that will gather a group of floating point numbers and determine the sum and average of the data entered.

  Create a console program that prompts the user

Create a console program that prompts the user to enter the name and address of their employer and position they hold or the name and address of their favorite restaurant and their favorite meal

  Implement simple java program to input syllabus grades

To implement simple Java program to input (hypothetical) syllabus grades, computing and displaying both normal Mean and Harmonic Mean.

  Design and implement a java program to determine the sum

Design and implement a Java program that will gather a group of floating point numbers and determine the sum and average of the data entered. The program should use separate methods for inputting the data, calculating the sum, calculating the aver..

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