Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M92253318
  • Price:- $80

Priced at Now at $80, Verified Solution

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As