SlideShare a Scribd company logo
1 of 25
GOVERNMENT ARTS COLLEGE
Melur, Madurai
By
Mr. V. VEERANAN
Roll No: P22PCS123
I M.Sc. Computer Science
PG. Department of Computer Science
Topic: Priority Queue
DATA STRUTURES AND ALGORITHMS
Queue
Simple Priority
Circular Deque
Enqueue-rear
Dequeue-Front
FIFO
Ex. Pipes
Last Member is
linked to the
first
Ex. Week
Predefined
Priority of
Service
Ex. high priority
Enqueue and
Dequeue
both the ends
and can remove
an item from
both the ends
Types of
Priority Queue
Implementation
of Priority Queue
Ascending
Descending
Array
Linked
List
Heap
Binary
Search
Tree
Priority
Ascending
Descending
Highest Priority to Lowest Number
Highest Priority to Highest Number
Implementation of Priority Queue
Array Linked List Heap
Binary Search
Tree
enqueue()
dequeue()
peek() / top()
push()
pop(0
peek() / top ()
insert()
extract Max()
remove(i)
get Max()
change
priority()
peek()
insert()
delete()
Any Doubt’s
Mutiple Choice Questions
Three Groups
C C++ Java
Table of the Content
S.No. Topic
1 Queue & Types of Queue
2 Simple Queue
3 Circular Queue
4 Priority Queue
5 Double Ended Queue (Deque)
6 Types of Priority Queue
7 Ascending Order Priority Queue
8 Descending Order Priority Queue
9 Implementation of Priority Queue
10 Implement Priority Queue Using Array
11 Implement Priority Queue Using Linked List
12 Implement Priority Queue Using Heap
13 Implement Priority Queue Using Binary Search Tree
14 Priority Queue Applications
Queues
 In computer science, a queue is a collection of entities that
are maintained in a sequence and can be modified by the
addition of entities at one end of the sequence and the
removal of entities from the other end of the sequence
 In this article, we’ll learn four types of queues with their
applications. Understand them one-by-one with an
illustration.
Types of Queues
 Simple Queue
 Circular Queue
 Priority Queue
 Double Ended Queue (Deque)
Queue Example
Simple Queue
• A simple queue is the most basic queue. In this queue, the
enqueue operation takes place at the rear, while the dequeue
operation takes place at the front.
• Its applications are process scheduling, disk scheduling,
memory management, IO buffer, pipes, call center phone
systems and interrupt handling.
Circular Queue
A circular queue is a special case of a simple queue in
which the last member is linked to the first. As a result, a circle-
like structure is formed.
 The last node is connected to the first node.
 Also known as a Ring Buffer as the nodes are connected end
to end.
 Insertion takes place at the front of the queue and deletion at
the end of the queue.
 Application of circular queue: Insertion of days in a week.
Priority Queue
• A priority queue is a special kind of queue in which each
item has a predefined priority of service.
• In this queue, the enqueue operation takes place at the rear in
the order of arrival of the items, while the dequeue operation
takes place at the front based on the priority of the items.
• That is to say that an item with a high priority will be
dequeued before an item with a low priority.
Priority Queue (Continue)
 In the case, when two or more items have the same priority,
then they’ll be dequeued in the order of their arrival. Hence,
it may or may not strictly follow the FIFO rule:
 It’s used in interrupt handling, Prim’s algorithm, Dijkstra’s
algorithm, A* search algorithm, heap sort, and Huffman
code generation.
Double-Ended Queue (Deque)
 A deque is also a special type of queue. In this queue, the
enqueue and dequeue operations take place at both front
and rear. That means, we can insert an item at both the ends
and can remove an item from both the ends. Thus, it may or
may not adhere to the FIFO order:
Types of Priority Queue
A priority queue is of two types:
 Ascending Order Priority Queue
 Descending Order Priority Queue
Ascending Order Priority Queue
 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.
 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.
Ascending Order Priority Queue
Example
 In the above table, 4 has the highest priority, and 45 has the
lowest priority.
4 8 12 20 35 45
Descending Order Priority Queue
 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.
 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.
Descending Order Priority Queue
 In the above table, 4 has the lowest priority, and 45 has the
highest priority.
45 35 20 12 8 4
Implement Priority Queue
Priority queue can be implemented using the following data
structures:
 Arrays
 Linked list
 Heap data structure
 Binary search tree
Implement Priority Queue Using Array
A simple implementation is to use an array of the following
structure.
struct item
{
int item;
int priority;
}
Implement Priority Queue Using Array
• enqueue(): This function is used to insert new data into the
queue.
• dequeue(): This function removes the element with the
highest priority from the queue.
• peek()/top(): This function is used to get the highest priority
element in the queue without removing it from the queue.
Link: https://www.geeksforgeeks.org/priority-queue-using-
array-in-c/
Arrays enqueue() dequeue() peek()
Time
Complexity
O(1) O(n) O(n)
Implement Priority Queue Using Linked List
 push(): This function is used to insert new data into the
queue.
 pop(): This function removes the element with the highest
priority from the queue.
 peek() / top(): This function is used to get the highest priority
element in the queue without removing it from the queue.
Linked List push() pop() peek()
Time
Complexity
O(n) O(1) O(1)
Implement Priority Queue Using Heaps
 insert(p): Inserts a new element with priority p.
 extractMax(): Extracts an element with maximum priority.
 remove(i): Removes an element pointed by an iterator i.
 getMax(): Returns an element with maximum priority.
 changePriority(i, p): Changes the priority of an element
pointed by i to p.
Binary Heap insert() remove() peek()
Time
Complexity
O(log n) O(log n) O(1)
Implement Priority Queue Using
Binary Search Tree
 A Self-Balancing Binary Search Tree like AVL Tree, Red-
Black Tree, etc. can also be used to implement a priority
queue.
 Operations like peek(), insert() and delete() can be performed
using BST.
Binary Search
Tree
peek() insert() delete()
Time
Complexity
O(1) O(log n) O(log n)
Priority Queue Applications
 CPU Scheduling
 Graph algorithms like Dijkstra’s shortest path algorithm,
Prim’s Minimum Spanning Tree, etc.
 Stack Implementation
 All queue applications where priority is involved.
 Data compression in Huffman code
 Event-driven simulation such as customers waiting in a
queue.
 Finding Kth largest/smallest element.
Mr. V.Veeranan, M.Sc. Computer Science, Dip. in Yoga

More Related Content

What's hot (20)

queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Splay Tree
Splay TreeSplay Tree
Splay Tree
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Linked list
Linked listLinked list
Linked list
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Binary search
Binary searchBinary search
Binary search
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Hashing
HashingHashing
Hashing
 
Trees
TreesTrees
Trees
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Priority queues
Priority queuesPriority queues
Priority queues
 

Similar to GAC DS Priority Queue Presentation 2022.ppt

Similar to GAC DS Priority Queue Presentation 2022.ppt (20)

Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
2.1 Queue.pptx
2.1 Queue.pptx2.1 Queue.pptx
2.1 Queue.pptx
 
Queues
Queues Queues
Queues
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
Queue
QueueQueue
Queue
 
Data Structures
Data StructuresData Structures
Data Structures
 
Queue
QueueQueue
Queue
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
 
Queue
QueueQueue
Queue
 
basics of queues
basics of queuesbasics of queues
basics of queues
 

More from CUO VEERANAN VEERANAN

Big Data - large Scale data (Amazon, FB)
Big Data - large Scale data (Amazon, FB)Big Data - large Scale data (Amazon, FB)
Big Data - large Scale data (Amazon, FB)CUO VEERANAN VEERANAN
 
Fourier Transforms are indispensable tool
Fourier Transforms are indispensable toolFourier Transforms are indispensable tool
Fourier Transforms are indispensable toolCUO VEERANAN VEERANAN
 
ENHANCING BIOLOGICAL RESEARCH THROUGH DIGITAL TECHNOLOGIES AND COMPUTATIONAL.ppt
ENHANCING BIOLOGICAL RESEARCH THROUGH DIGITAL TECHNOLOGIES AND COMPUTATIONAL.pptENHANCING BIOLOGICAL RESEARCH THROUGH DIGITAL TECHNOLOGIES AND COMPUTATIONAL.ppt
ENHANCING BIOLOGICAL RESEARCH THROUGH DIGITAL TECHNOLOGIES AND COMPUTATIONAL.pptCUO VEERANAN VEERANAN
 
CS 23 Operating System Design Principles_MULTIPROCESSOR AND REAL TIME SCHEDULING
CS 23 Operating System Design Principles_MULTIPROCESSOR AND REAL TIME SCHEDULINGCS 23 Operating System Design Principles_MULTIPROCESSOR AND REAL TIME SCHEDULING
CS 23 Operating System Design Principles_MULTIPROCESSOR AND REAL TIME SCHEDULINGCUO VEERANAN VEERANAN
 
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.pptGAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.pptCUO VEERANAN VEERANAN
 
Lab 3 Python Programming Lab 8-15 MKU.pdf
Lab 3 Python Programming Lab 8-15 MKU.pdfLab 3 Python Programming Lab 8-15 MKU.pdf
Lab 3 Python Programming Lab 8-15 MKU.pdfCUO VEERANAN VEERANAN
 
Lab 3 Python Programming Lab 1-8 MKU.pdf
Lab 3 Python Programming Lab 1-8 MKU.pdfLab 3 Python Programming Lab 1-8 MKU.pdf
Lab 3 Python Programming Lab 1-8 MKU.pdfCUO VEERANAN VEERANAN
 
MULTIPROCESSOR AND REAL TIME SCHEDULING.ppt
MULTIPROCESSOR AND REAL TIME SCHEDULING.pptMULTIPROCESSOR AND REAL TIME SCHEDULING.ppt
MULTIPROCESSOR AND REAL TIME SCHEDULING.pptCUO VEERANAN VEERANAN
 
1.1.8 Types of computer & 1.1.8.3 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.3 Classification of Computers on the basis of...1.1.8 Types of computer & 1.1.8.3 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.3 Classification of Computers on the basis of...CUO VEERANAN VEERANAN
 
1.1.8 Types of computer & 1.1.8.2 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.2 Classification of Computers on the basis of...1.1.8 Types of computer & 1.1.8.2 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.2 Classification of Computers on the basis of...CUO VEERANAN VEERANAN
 
1.1.8 Types of computer & 1.1.8.1 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.1 Classification of Computers on the basis of...1.1.8 Types of computer & 1.1.8.1 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.1 Classification of Computers on the basis of...CUO VEERANAN VEERANAN
 
1.1.7 Block diagram and Working Principle of Computer
1.1.7 Block diagram and Working Principle of Computer1.1.7 Block diagram and Working Principle of Computer
1.1.7 Block diagram and Working Principle of ComputerCUO VEERANAN VEERANAN
 
1.1.5 Terms related to Computer & 1.1.5.3 Technical Industry
1.1.5 Terms related to Computer & 1.1.5.3 Technical Industry1.1.5 Terms related to Computer & 1.1.5.3 Technical Industry
1.1.5 Terms related to Computer & 1.1.5.3 Technical IndustryCUO VEERANAN VEERANAN
 
1.1.5 Terms related to Computer & 1.1.5.2 Software.ppt
1.1.5 Terms related to Computer & 1.1.5.2 Software.ppt1.1.5 Terms related to Computer & 1.1.5.2 Software.ppt
1.1.5 Terms related to Computer & 1.1.5.2 Software.pptCUO VEERANAN VEERANAN
 

More from CUO VEERANAN VEERANAN (20)

Big Data - large Scale data (Amazon, FB)
Big Data - large Scale data (Amazon, FB)Big Data - large Scale data (Amazon, FB)
Big Data - large Scale data (Amazon, FB)
 
Fourier Transforms are indispensable tool
Fourier Transforms are indispensable toolFourier Transforms are indispensable tool
Fourier Transforms are indispensable tool
 
ENHANCING BIOLOGICAL RESEARCH THROUGH DIGITAL TECHNOLOGIES AND COMPUTATIONAL.ppt
ENHANCING BIOLOGICAL RESEARCH THROUGH DIGITAL TECHNOLOGIES AND COMPUTATIONAL.pptENHANCING BIOLOGICAL RESEARCH THROUGH DIGITAL TECHNOLOGIES AND COMPUTATIONAL.ppt
ENHANCING BIOLOGICAL RESEARCH THROUGH DIGITAL TECHNOLOGIES AND COMPUTATIONAL.ppt
 
ADS_Unit I_Route Map 2023.pdf
ADS_Unit I_Route Map 2023.pdfADS_Unit I_Route Map 2023.pdf
ADS_Unit I_Route Map 2023.pdf
 
CS 23 Operating System Design Principles_MULTIPROCESSOR AND REAL TIME SCHEDULING
CS 23 Operating System Design Principles_MULTIPROCESSOR AND REAL TIME SCHEDULINGCS 23 Operating System Design Principles_MULTIPROCESSOR AND REAL TIME SCHEDULING
CS 23 Operating System Design Principles_MULTIPROCESSOR AND REAL TIME SCHEDULING
 
Python Unit I MCQ.ppt
Python Unit I MCQ.pptPython Unit I MCQ.ppt
Python Unit I MCQ.ppt
 
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.pptGAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
 
Lab 3 Python Programming Lab 8-15 MKU.pdf
Lab 3 Python Programming Lab 8-15 MKU.pdfLab 3 Python Programming Lab 8-15 MKU.pdf
Lab 3 Python Programming Lab 8-15 MKU.pdf
 
Lab 3 Python Programming Lab 1-8 MKU.pdf
Lab 3 Python Programming Lab 1-8 MKU.pdfLab 3 Python Programming Lab 1-8 MKU.pdf
Lab 3 Python Programming Lab 1-8 MKU.pdf
 
MULTIPROCESSOR AND REAL TIME SCHEDULING.ppt
MULTIPROCESSOR AND REAL TIME SCHEDULING.pptMULTIPROCESSOR AND REAL TIME SCHEDULING.ppt
MULTIPROCESSOR AND REAL TIME SCHEDULING.ppt
 
Relational Algebra.ppt
Relational Algebra.pptRelational Algebra.ppt
Relational Algebra.ppt
 
DS Unit I to III MKU Questions.pdf
DS Unit I to III MKU Questions.pdfDS Unit I to III MKU Questions.pdf
DS Unit I to III MKU Questions.pdf
 
Acharya Vinoba Bhave.ppt
Acharya Vinoba Bhave.pptAcharya Vinoba Bhave.ppt
Acharya Vinoba Bhave.ppt
 
1.1.8 Types of computer & 1.1.8.3 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.3 Classification of Computers on the basis of...1.1.8 Types of computer & 1.1.8.3 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.3 Classification of Computers on the basis of...
 
1.1.8 Types of computer & 1.1.8.2 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.2 Classification of Computers on the basis of...1.1.8 Types of computer & 1.1.8.2 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.2 Classification of Computers on the basis of...
 
1.1.8 Types of computer & 1.1.8.1 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.1 Classification of Computers on the basis of...1.1.8 Types of computer & 1.1.8.1 Classification of Computers on the basis of...
1.1.8 Types of computer & 1.1.8.1 Classification of Computers on the basis of...
 
1.1.7 Block diagram and Working Principle of Computer
1.1.7 Block diagram and Working Principle of Computer1.1.7 Block diagram and Working Principle of Computer
1.1.7 Block diagram and Working Principle of Computer
 
1.1.6 Characteristics of Computer
1.1.6 Characteristics of Computer1.1.6 Characteristics of Computer
1.1.6 Characteristics of Computer
 
1.1.5 Terms related to Computer & 1.1.5.3 Technical Industry
1.1.5 Terms related to Computer & 1.1.5.3 Technical Industry1.1.5 Terms related to Computer & 1.1.5.3 Technical Industry
1.1.5 Terms related to Computer & 1.1.5.3 Technical Industry
 
1.1.5 Terms related to Computer & 1.1.5.2 Software.ppt
1.1.5 Terms related to Computer & 1.1.5.2 Software.ppt1.1.5 Terms related to Computer & 1.1.5.2 Software.ppt
1.1.5 Terms related to Computer & 1.1.5.2 Software.ppt
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

GAC DS Priority Queue Presentation 2022.ppt

  • 1. GOVERNMENT ARTS COLLEGE Melur, Madurai By Mr. V. VEERANAN Roll No: P22PCS123 I M.Sc. Computer Science PG. Department of Computer Science Topic: Priority Queue DATA STRUTURES AND ALGORITHMS
  • 2. Queue Simple Priority Circular Deque Enqueue-rear Dequeue-Front FIFO Ex. Pipes Last Member is linked to the first Ex. Week Predefined Priority of Service Ex. high priority Enqueue and Dequeue both the ends and can remove an item from both the ends Types of Priority Queue Implementation of Priority Queue Ascending Descending Array Linked List Heap Binary Search Tree
  • 3. Priority Ascending Descending Highest Priority to Lowest Number Highest Priority to Highest Number Implementation of Priority Queue Array Linked List Heap Binary Search Tree enqueue() dequeue() peek() / top() push() pop(0 peek() / top () insert() extract Max() remove(i) get Max() change priority() peek() insert() delete()
  • 4. Any Doubt’s Mutiple Choice Questions Three Groups C C++ Java
  • 5. Table of the Content S.No. Topic 1 Queue & Types of Queue 2 Simple Queue 3 Circular Queue 4 Priority Queue 5 Double Ended Queue (Deque) 6 Types of Priority Queue 7 Ascending Order Priority Queue 8 Descending Order Priority Queue 9 Implementation of Priority Queue 10 Implement Priority Queue Using Array 11 Implement Priority Queue Using Linked List 12 Implement Priority Queue Using Heap 13 Implement Priority Queue Using Binary Search Tree 14 Priority Queue Applications
  • 6. Queues  In computer science, a queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence  In this article, we’ll learn four types of queues with their applications. Understand them one-by-one with an illustration. Types of Queues  Simple Queue  Circular Queue  Priority Queue  Double Ended Queue (Deque)
  • 8. Simple Queue • A simple queue is the most basic queue. In this queue, the enqueue operation takes place at the rear, while the dequeue operation takes place at the front. • Its applications are process scheduling, disk scheduling, memory management, IO buffer, pipes, call center phone systems and interrupt handling.
  • 9. Circular Queue A circular queue is a special case of a simple queue in which the last member is linked to the first. As a result, a circle- like structure is formed.  The last node is connected to the first node.  Also known as a Ring Buffer as the nodes are connected end to end.  Insertion takes place at the front of the queue and deletion at the end of the queue.  Application of circular queue: Insertion of days in a week.
  • 10. Priority Queue • A priority queue is a special kind of queue in which each item has a predefined priority of service. • In this queue, the enqueue operation takes place at the rear in the order of arrival of the items, while the dequeue operation takes place at the front based on the priority of the items. • That is to say that an item with a high priority will be dequeued before an item with a low priority.
  • 11. Priority Queue (Continue)  In the case, when two or more items have the same priority, then they’ll be dequeued in the order of their arrival. Hence, it may or may not strictly follow the FIFO rule:  It’s used in interrupt handling, Prim’s algorithm, Dijkstra’s algorithm, A* search algorithm, heap sort, and Huffman code generation.
  • 12. Double-Ended Queue (Deque)  A deque is also a special type of queue. In this queue, the enqueue and dequeue operations take place at both front and rear. That means, we can insert an item at both the ends and can remove an item from both the ends. Thus, it may or may not adhere to the FIFO order:
  • 13. Types of Priority Queue A priority queue is of two types:  Ascending Order Priority Queue  Descending Order Priority Queue
  • 14. Ascending Order Priority Queue  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.  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.
  • 15. Ascending Order Priority Queue Example  In the above table, 4 has the highest priority, and 45 has the lowest priority. 4 8 12 20 35 45
  • 16. Descending Order Priority Queue  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.  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.
  • 17. Descending Order Priority Queue  In the above table, 4 has the lowest priority, and 45 has the highest priority. 45 35 20 12 8 4
  • 18. Implement Priority Queue Priority queue can be implemented using the following data structures:  Arrays  Linked list  Heap data structure  Binary search tree
  • 19. Implement Priority Queue Using Array A simple implementation is to use an array of the following structure. struct item { int item; int priority; }
  • 20. Implement Priority Queue Using Array • enqueue(): This function is used to insert new data into the queue. • dequeue(): This function removes the element with the highest priority from the queue. • peek()/top(): This function is used to get the highest priority element in the queue without removing it from the queue. Link: https://www.geeksforgeeks.org/priority-queue-using- array-in-c/ Arrays enqueue() dequeue() peek() Time Complexity O(1) O(n) O(n)
  • 21. Implement Priority Queue Using Linked List  push(): This function is used to insert new data into the queue.  pop(): This function removes the element with the highest priority from the queue.  peek() / top(): This function is used to get the highest priority element in the queue without removing it from the queue. Linked List push() pop() peek() Time Complexity O(n) O(1) O(1)
  • 22. Implement Priority Queue Using Heaps  insert(p): Inserts a new element with priority p.  extractMax(): Extracts an element with maximum priority.  remove(i): Removes an element pointed by an iterator i.  getMax(): Returns an element with maximum priority.  changePriority(i, p): Changes the priority of an element pointed by i to p. Binary Heap insert() remove() peek() Time Complexity O(log n) O(log n) O(1)
  • 23. Implement Priority Queue Using Binary Search Tree  A Self-Balancing Binary Search Tree like AVL Tree, Red- Black Tree, etc. can also be used to implement a priority queue.  Operations like peek(), insert() and delete() can be performed using BST. Binary Search Tree peek() insert() delete() Time Complexity O(1) O(log n) O(log n)
  • 24. Priority Queue Applications  CPU Scheduling  Graph algorithms like Dijkstra’s shortest path algorithm, Prim’s Minimum Spanning Tree, etc.  Stack Implementation  All queue applications where priority is involved.  Data compression in Huffman code  Event-driven simulation such as customers waiting in a queue.  Finding Kth largest/smallest element.
  • 25. Mr. V.Veeranan, M.Sc. Computer Science, Dip. in Yoga