1 / 61

Priority Queues

Priority Queues. Ed. 2. and 3.: Chapter 7 – Ed. 4.: Chapter 8 -. Priority Queues (Chapter 7) Priority Queue ADT - Keys, Priorities, and Total order Relations - Sorting with a Priority Queue Priority Queue implementation - Implementation with an unsorted sequence

carr
Download Presentation

Priority Queues

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Priority Queues • Ed. 2. and 3.: Chapter 7 – • Ed. 4.: Chapter 8 -

  2. Priority Queues • (Chapter 7) • Priority Queue ADT • - Keys, Priorities, and Total order Relations • - Sorting with a Priority Queue • Priority Queue implementation • - Implementation with an unsorted sequence • - Implementation with a sorted sequence

  3. The Priority Queue Abstract Data Type

  4. We want a comparison rule that will never contradict itself. • This requires that the rule define a total order relation. • total order relation: • Reflexive property: k  k. • Antisymmetric property: if k1 k2 and k2 k1 , then k1= k2. • Transitive property: if k1 k2 and k2 k3 , then k1 k3. • Examples: • Integers, real numbers, lexicographic order of character sequence.

  5. v1  v2 if x2 - x1 = = x4 - x3 Then we have 4 - 1 = 7 - 4 Therefore, (1, 4)  (4, 7) and (4, 7)  (1, 4). But (1,4)  (7, 4), namely, the relation does not satisfy the antisymmetric property.

  6. If a comparison rule defines a total order relation, it will never lead to a comparison contradiction. the smallest key: If we have a finite number of elements with a total order relation, then the smallest key, denoted by kmin, is well-defined: kmin is the key that satisfies kmin k for any other key k. Being able to find the smallest key is very important because in many cases, we want to have the element with the smallest key.

  7. Sorting with a Priority Queue

  8. Methods of a Priority Queue

  9. Items in a Priority Queue

  10. The Comparator Abstract Data Type

  11. Class Lexicographic

  12. Data Structure Exercises 14.1

  13. Implementing a Priority Queue with a Sequence

  14. O(n) O(n)

  15. Class SortedSequencePriorityQueue

  16. Selection Sort and Insertion Sort

  17. O(n) O(n2) O(n) O(n2) O(n2) O(n2)

  18. Data Structure Exercises 15.1

  19. Implementing a Priority Queue with a Sequence

More Related