Lecture 05 - Priority Queue, Heap
Lecture 05 - Priority Queue, Heap
CSE 4303
Data Structure
Asaduzzaman Herok
Lecturer | CSE | IUT
[email protected]
Priority Queue
With queues
❖ The order may be summarized by first in, first
out
A Priority Queue is a particular type of data structure in which every element is assigned a priority.
Elements with higher priorities are dequeued before those with lower ones. In the event of similar
priorities, elements are dequeued based on their existing order in the queue.
❖ Popping from a priority queue removes the current highest priority object:
❖ For example, (5, 19), (13, 1), (13, 24), and (15, 0) all have higher priority
than (15, 7)
❖ Array Implementation
❖ Linked List Implementation
❖ Heap Implementation
➢ Array based
➢ Linked List based
One implementation:
Only O(1) (constant) pointer changes required, but it takes O(N) pointer traversals to find the location
for insertion.
Wanted: a data structure for PQs that can be both searched and updated in better than O(N) time.
This implies that elements at every node will be either greater(max heap) / less(min heap) than or
equal to the element at its left and right child.
Rafsanjany Kushol
PhD Student, Dept. of Computing Science,
University of Alberta
Sabbir Ahmed
Assistant Professor
Department of CSE, IUT