Java's library contains a.
Priority Queues and Heapsort in Java . This chapter is from the book . Often, we. collect a set of records, then process the one with the largest key, then. An appropriate data structure in such an environment supports the. Such a. data structure is called a priority queue. Using priority queues is. The priority queue is the. Stack and queue applications. Stacks and queues have numerous. When it comes time to update t. ADT that we discussed in Section. In fact, the priority queue is a proper generalization of the stack and the. Exercises 9. 3 and 9. Definition 9. 1 A priority queue is a data structure of items. Applications of priority queues include simulation systems, where the keys. We can use any priority queue as the basis for a sorting algorithm by. Later on in this book, we shall see how to use. In Part 5, we. shall see how priority queues are an appropriate abstraction for helping us. Part 6, we shall develop a file- compression algorithm using. These are but a few examples of the important role. In practice, priority queues are more complex than the simple definition just. We want to build. Construct a priority queue from N given items. Insert a new item. Remove the maximum item. Change the priority of an arbitrary specified item. Remove an arbitrary specified item. Join two priority queues into one large one. If records can have duplicate keys, we take . For example, certain clients may need. Or, we might have an operation to replace the. We could implement operations such as these. Find the maximum could. We normally get more. Precise specification is not always as. For example, the two options just given for. Similarly, the change priority operation could be. For some applications, it might be slightly more convenient to switch around. We stick. primarily with priority queues that are oriented toward accessing the maximum. When we do need the other kind, we shall refer to it (a priority queue that. The priority queue is a prototypical abstract data type (ADT) (see. Chapter 4): It represents a well- defined set of operations on data, and it. The interface given in Program 9. Section 9. 5. Strictly speaking, different subsets of the various operations that. Program 9. 1 Basic priority- queue ADTThis interface defines operations for the simplest type of priority queue. Elementary. implementations of these methods using arrays and linked lists can require. The constructor's parameter. PQ // ADT interface. This situation leads to cost. In this chapter, we consider a variety of ways of approaching these. First, in Section 9. Next, in Sections. In Section 9. 4, we also look at an important sorting algorithm that. In Sections 9. 5 and 9. ADTs. Finally, in Section 9. During our study of all these various data structures, we shall bear in mind. Chapter 3) and the problems involved with making packages. In particular, some of the advanced algorithms. Exercises. 9. 1 A letter means insert and an asterisk means. P R I O * R * * I * T * Y * * * Q U E * * * U * E: Give the sequence of values returned by the remove the maximum. Add to the conventions of Exercise 9. Give the contents of the priority queue after the. P R I O *) + ( R * I T * Y * ) ) * * * ) + ( Q U E * * * U * E ): 9. Explain how to use a priority queue ADT to implement a. ADT. 9. 4 Explain how to use a priority queue ADT to implement a. ADT. 9. 1 Elementary Implementations. The basic data structures that we discussed in Chapter 3 provide us with. Program 9. 2 is an. Figure 9. 1 shows the contents of the array for a. This basic implementation corresponds to similar. Chapter 4 for stacks and queues (see Programs 4. The significant difference has to do. For stacks and queues, we were able to develop implementations. Figure 9. 1 Priority- queue example (unordered array representation)This. Each line displays the operation, the letter removed for the. Program 9. 2 Array implementation of a priority. This implementation, which may be compared with the array implementations for. Chapter 4 (see Programs 4. Items are added to and removed from the. PQ. . The basic tradeoff between leaving the items unordered and keeping them. The unordered sequence is. We. can use an array or linked- list representation in either case, with the basic. The worst- case costs of the various operations (within a constant factor) on. N for various implementations are summarized in. Table 9. 1. Developing a full implementation requires paying careful attention to the. These. issues are discussed in Sections 9. Table 9. 1 Worst- case costs of priority- queue operations Implementations of the priority queue ADT have widely varying performance. N) for various methods. Elementary methods. It. is wise to keep in mind the simple implementations because they often can. For example. the unordered- list implementation might be appropriate in an application where. Exercises 9. 5 Criticize the following idea: To implement find the. Give the contents of the array after the execution of the. Figure 9. 1. 9. 7 Provide an implementation for the basic priority- queue interface. Provide an implementation for the basic priority- queue interface. Hint. See Program 3. Consider a lazy implementation where the list is ordered. Insertions since the previous sort are kept on a separate list, then. Discuss advantages of such an. Write a performance driver client program that uses. Write a performance driver client program that uses. Use your client program from Exercise 9. Program 9. 2 with your unordered- list. Exercise 9. 8. 9. Use your client program from Exercise 9. Exercises 9. 7 and 9. Write an exercise driver client program that uses the. Program 9. 1 on difficult or pathological. Simple examples include keys. This exercise is 2. Justify the. worst- case bounds for the four elementary implementations that are given in. Table 9. 1, by reference to the implementation in Program 9. Exercises 9. 7 through 9. For remove, change priority, and join, assume.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2018
Categories |