0% found this document useful (0 votes)
255 views18 pages

Priority Queues Presentation

This document summarizes priority queues. It defines a priority queue as a special type of queue where each element has an associated priority value and higher priority elements are removed first. It describes the characteristics of priority queues, including that elements with the same priority follow FIFO order. The document discusses dequeuing and enqueueing elements and different types of priority queues like ascending and descending order. It states that a binary heap is the most efficient data structure for implementing priority queues and provides an example of how to represent a priority queue using a one-way list.

Uploaded by

Hoor Hoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
255 views18 pages

Priority Queues Presentation

This document summarizes priority queues. It defines a priority queue as a special type of queue where each element has an associated priority value and higher priority elements are removed first. It describes the characteristics of priority queues, including that elements with the same priority follow FIFO order. The document discusses dequeuing and enqueueing elements and different types of priority queues like ascending and descending order. It states that a binary heap is the most efficient data structure for implementing priority queues and provides an example of how to represent a priority queue using a one-way list.

Uploaded by

Hoor Hoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

TOPIC: PRIORITY QUEUE

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

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

8
• The new list is as follows: 4, 8, 12, 20. 35, 45. In
this list, 4 is the smallest number.

• Hence, the ascending order priority queue treats


number 4 as the highest priority.

4 8 12 20 35 45

 In the above table, 4 has the highest priority,


and 45 has the lowest priority.

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

 In the above table, 4 has the lowest priority,


and 45 has the highest priority.

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.

 We will create the priority queue by using the list


given below in which INFO list contains the data
elements, PNR list contains the priority numbers
of each data element available in the INFO list,
and LINK basically contains the address of the next
node.

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

You might also like