Problem

Writing programs to solve the Programming Projects helps to solidify your understanding of...

Writing programs to solve the Programming Projects helps to solidify your understanding of the material and demonstrates how the chapter’s concepts are applied. (As noted in the Introduction, qualified instructors may obtain completed solutions to the Programming Projects on the publisher’s Web site.)

One problem with implementing a priority queue with an array-based heap is the fixed size of the array. If your data outgrows the array, you’ll need to expand the array, as we did for hash tables in Programming Project 11.4 in Chapter 11, “Hash Tables.” You can avoid this problem by implementing a priority queue with an ordinary binary search tree rather than a heap. A tree can grow as large as it wants (except for system-memory constraints).

Start with the Tree class from the tree, java program (Listing 8.1). Modify this class so it supports priority queues by adding a removeMax() method that removes the largest item. In a heap this is easy, but in a tree it’s slightly harder. How do you find the largest item in a tree? Do you need to worry about both its children when you delete it? Implementing change() is optional. It’s easily handled in a binary search tree by deleting the old item and inserting a new one with a different key.

The application should relate to a PriorityQ class; the Tree class should be invisible to main() (except perhaps for displaying the tree while you’re debugging). Insertion and removeMax() will operate in O(logN) time.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 12
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT