Docsity

Double-Ended Priority Queues - Advanced Data Structures - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Double-Ended Priority Queues - Advanced Data Structures - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Double-Ended Priority Queues

• Primary operations

ƒ Insert

ƒ Remove Max

ƒ Remove Min

• Note that a single-ended priority queue

supports just one of the above remove

operations.

General Methods

• Dual min and max single-ended priority

queues.

• Correspondence based min and max single-

ended priority queues.

Specialized Structures

• Symmetric min-max heaps (see

text).

• Min-max heaps.

• Deaps.

WInterval heaps.

Dual Single-Ended Priority Queues

• Each element is in both a min and a max

single-ended priority queue.

• Single-ended priority queue also must

support an arbitrary remove.

• Each node in a priority queue has a pointer

to the node in the other priority queue that

has the same element.

Total Correspondence

• Each element of the min priority queue is

paired with a different and >= element in

the max priority queue.

Total Correspondence Example

Min Heap

Max Heap Buffer = 12

Insert

• Buffer empty => place in buffer.

• Else, insert smaller of new and buffer elements into

min priority queue and larger into max priority queue;

establish correspondence between the 2 elements.

Min Heap

Max Heap Buffer = 12

Remove Min

• Buffer is min => empty buffer.

• Else, remove min from min PQ as well as

corresponding element from max PQ; reinsert

corresponding element.

Min Heap

Max Heap Buffer = 12

Leaf Correspondence Example

Min Heap

Max Heap Buffer = 12

Insert

Min Heap

Max Heap Buffer = 12

• Buffer empty => place in buffer.

• Else, insert smaller of new and buffer elements

into min priority queue; insert larger into max

priority queue only if smaller one is a leaf.

Insert

Min Heap

Max Heap Buffer = 12

• Case when min and/or max heap originally have an

even number of elements is more involved, because a

nonleaf may become a leaf. See reference.

Remove Min

• Buffer is min => empty buffer.

• Else, remove min from min PQ as well as

corresponding leaf element (if any) from max PQ;

reinsert removed corresponding element (see

reference for details).

Min Heap

Max Heap Buffer = 12