SlideShare a Scribd company logo
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

Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
Nisha Soms
 
File handling in Python
File handling in PythonFile handling in Python
introduction to python
 introduction to python introduction to python
introduction to python
Jincy Nelson
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
Vineeta Garg
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
Trupti Agrawal
 
Python list
Python listPython list
Python list
ArchanaBhumkar
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
Fahd Allebdi
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 

What's hot (20)

Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Linked List
Linked ListLinked List
Linked List
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
introduction to python
 introduction to python introduction to python
introduction to python
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Python list
Python listPython list
Python list
 
Linked list
Linked listLinked list
Linked list
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Python list
Python listPython list
Python list
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 

Similar to GAC DS Priority Queue Presentation 2022.ppt

Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
junnubabu
 
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
Rai University
 
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
Rai University
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
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
Rai University
 
2.1 Queue.pptx
2.1 Queue.pptx2.1 Queue.pptx
2.1 Queue.pptx
MuhammadShajid1
 
Queues
Queues Queues
Queues
nidhisatija1
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Afaq Mansoor Khan
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
VeerannaKotagi1
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2
Dr.Umadevi V
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
DrkhanchanaR
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
MeghaKulkarni27
 
Queue
QueueQueue
Data Structures
Data StructuresData Structures
Data Structures
Dr.Umadevi V
 
Queue
QueueQueue
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
abinathsabi
 

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

Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
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
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
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
 

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 tool
CUO 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.ppt
CUO VEERANAN VEERANAN
 
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
CUO 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 SCHEDULING
CUO VEERANAN VEERANAN
 
Python Unit I MCQ.ppt
Python Unit I MCQ.pptPython Unit I MCQ.ppt
Python Unit I MCQ.ppt
CUO 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.ppt
CUO 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.pdf
CUO 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.pdf
CUO VEERANAN VEERANAN
 
MULTIPROCESSOR AND REAL TIME SCHEDULING.ppt
MULTIPROCESSOR AND REAL TIME SCHEDULING.pptMULTIPROCESSOR AND REAL TIME SCHEDULING.ppt
MULTIPROCESSOR AND REAL TIME SCHEDULING.ppt
CUO VEERANAN VEERANAN
 
Relational Algebra.ppt
Relational Algebra.pptRelational Algebra.ppt
Relational Algebra.ppt
CUO VEERANAN VEERANAN
 
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
CUO VEERANAN VEERANAN
 
Acharya Vinoba Bhave.ppt
Acharya Vinoba Bhave.pptAcharya Vinoba Bhave.ppt
Acharya Vinoba Bhave.ppt
CUO 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 Computer
CUO VEERANAN VEERANAN
 
1.1.6 Characteristics of Computer
1.1.6 Characteristics of Computer1.1.6 Characteristics of Computer
1.1.6 Characteristics of Computer
CUO 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 Industry
CUO 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.ppt
CUO 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

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 

Recently uploaded (20)

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 

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