Abstract Priority Queues
Abstract Priority Queues
Douglas
Douglas Wilhelm
Wilhelm Harder,
Harder, M.Math.
M.Math. LEL
LEL
Department
Department of of Electrical
Electrical and
and Computer
Computer Engineering
Engineering
University
University of
of Waterloo
Waterloo
Waterloo,
Waterloo, Ontario,
Ontario, Canada
Canada
ece.uwaterloo.ca
ece.uwaterloo.ca
[email protected]
[email protected]
©
© 2006-2013
2006-2013 by
by Douglas
Douglas Wilhelm
Wilhelm Harder.
Harder. Some
Some rights
rights reserved.
reserved.
Abstract Priority Queues
2
Outline
With queues
– The order may be summarized by first in, first out
For example,
– (5, 19), (13, 1), (13, 24), and (15, 0) all have higher priority than (15, 7)
Abstract Priority Queues
7
7.1.4 Process Priority in Unix
The priority of
processes in
Windows may be
set in the
Windows Task
Manager
Abstract Priority Queues
9
7.1.5 Implementations
Our goal is to make the run time of each operation as close to Q(1)
as possible
The next topic will be a more appropriate data structure: the heap
Abstract Priority Queues
10
7.1.5.1 Multiple Queues
Unfortunately:
– It restricts the range of priorities
– The memory requirement is Q(M + n)
Abstract Priority Queues
14
7.1.5.2 AVL Trees
We could simply insert the objects into an AVL tree where the order
is given by the stated priority:
– Insertion is Q(ln(n)) void insert( Type const & );
– Top is Q(ln(n)) Type front();
– Remove is Q(ln(n)) bool remove( front() );
There is significant overhead for maintaining both the tree and the
corresponding balance
Abstract Priority Queues
15
7.1.5.3 Heaps
Can we do better?
– That is, can we reduce some (or all) of the operations down to Q(1)?
Summary
This topic:
– Introduced priority queues
– Considered two obvious implementations:
• Arrays of queues
• AVL trees
– Discussed the run times and claimed that a variation of a tree, a heap,
can do better
Abstract Priority Queues
17
References
Mark A. Weiss,
Data Structures and Algorithm Analysis in C++, 3rd Ed., Addison Wesley, 2006, Ch.6, p.213.
These slides are provided for the ECE 250 Algorithms and Data Structures course. The
material in it reflects Douglas W. Harder’s best judgment in light of the information available to
him at the time of preparation. Any reliance on these course slides by any party for any other
purpose are the responsibility of such parties. Douglas W. Harder accepts no responsibility for
damages, if any, suffered by any party as a result of decisions made or actions based on these
course slides for any other purpose than that for which it was intended.