Download presentation

Presentation is loading. Please wait.

Published bySelina Urch Modified over 2 years ago

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

7
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 k 1 k 2 and k 2 k 1, then k 1 = k 2. Transitive property: if k 1 k 2 and k 2 k 3, then k 1 k 3. Examples: Integers, real numbers, lexicographic order of character sequence.

8
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.

9
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 k min, is well-defined: k min is the key that satisfies k min 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.

12
Sorting with a Priority Queue

18
Methods of a Priority Queue

21
Items in a Priority Queue

23
The Comparator Abstract Data Type

25
Class Lexicographic

31
Data Structure Exercises 14.1

32
Implementing a Priority Queue with a Sequence

38
O(n)

39
Class SortedSequencePriorityQueue

42
Selection Sort and Insertion Sort

45
O(n)O(n 2 ) O(n)

46
Data Structure Exercises 15.1

47
Implementing a Priority Queue with a Sequence

54
Class SortedSequencePriorityQueue

57
Selection Sort and Insertion Sort

61
Data Structure Exercises 15.1

Similar presentations

OK

12/23/2015 2:18 AMPriority Queues1 Sell100IBM$122 Sell300IBM$120 Buy500IBM$119 Buy400IBM$118.

12/23/2015 2:18 AMPriority Queues1 Sell100IBM$122 Sell300IBM$120 Buy500IBM$119 Buy400IBM$118.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on producers consumers and decomposers in the forest Ppt on management by objectives Ppt on grease lubrication hose Ppt on useful and harmful insects Ppt on kinetic molecular theory Ppt on cost leadership strategy Ppt on polynomials of 98 Ppt on art of war lyrics Ppt on object oriented programming language Ppt on spinal cord diseases