Priority Queues Presentation
Priority Queues Presentation
PresentedBY:
WARDA BUTT
TAYYABA FATIMA
RABIA MUJAHID
1
PRIORITY QUEUES
Definition
Characteristics
FIFO Principle in priority queue
DQUEUE and ENQUEUE
Types
Which is best data structure for priority
queues?
Representation of priority queues
2
DEFINITION:
A priority queue is a special type of queue in
which each element is associated with a
priority value.
3
CHARACTERISTICS:
Every element in a priority queue has a
priority value associated with it.
The element with the higher priority will be
moved to the top and removed first.
If two elements in a priority queue have the
same priority value, they’ll be arranged
using the FIFO principle.
4
FIFO PRINCIPLE IN PRIORITY QUEUE:
If two elements share the same priority value,
then the priority queue follows the first-in-first-
out for de queue operation.
Each customer is assigned a priority, and the
customer with the highest priority goes first,
regardless of the order of arrival.
In programming terms, putting items in the queue
is called en queue, and removing items from the
queue is called de queue.
5
6
TYPES:
7
ASCENDING ORDER:
An ascending order priority queue gives the
highest priority to the lower number in that
queue.
8
• The new list is as follows: 4, 8, 12, 20. 35, 45. In
this list, 4 is the smallest number.
4 8 12 20 35 45
9
DESENDING ORDER:
A descending order priority queue gives
the highest priority to the highest
number in that queue.
For example, you have six numbers in
the priority queue that are 4, 8, 12, 45,
35, 20. Firstly, you will arrange these
numbers in ascending order.
10
• The new list is as follows: 45, 35, 20,
12, 8, 4. In this list, 45 is the highest
number.
• Hence, the descending order priority
queue treats number 45 as the
highest priority.
45 35 20 12 8 4
11
BEST DATA STRUCTURE FOR PRIORITY
QUEUES:
The binary heap is the most efficient method for
implementing the priority queue in the data
structure.
BINARY HEAP:
A Binary Heap is a complete Binary Tree
which is used to store data efficiently to
get the max or min element based on its
structure.
12
13
REPRESENTATION OF PRIORITY QUEUE:
Now, we will see how to represent the priority
queue through a one-way list.
14
In the case of priority queue, lower priority number
is considered the higher priority, i.e., lower priority
number = higher priority.
15
• Step 1: In the list, lower priority number is 1, whose data
value is 300, so it will be inserted in the list as shown in the
below diagram:
• Step 2: After inserting 300, priority number 2 is having a
higher priority, and data values associated with this priority
are 200 and 100. So, this data will be inserted based on the
FIFO principle; therefore 200will be added first and then
100.
• Step 3: After inserting the elements of priority 2, the next
higher priority number is 4 and data elements associated
with 4 priority numbers are 400, 500, 700. In this case,
elements would be inserted based on the FIFO principle;
therefore, 400 will be added first, then 500, and then 700.
• Step 4: After inserting the elements of priority 4, the next
higher priority number is 5, and the value associated with
priority 5 is 600, so it will be inserted at the end of the
queue.
16
4
17
18