SlideShare a Scribd company logo
DATA STRUCTURES
UNIT-2
SELVA KUMAR S
ASSISTANT PROFESSOR
B.M.S. COLLEGE OF ENGINEERING
QUEUE -ADT
• Queue: A list or a collection with the restrictions
that insertion can be performed at one end (the
rear or tail of the queue) and deletion can be
performed at other end (the front or head of the
queue).
• A queue is a FIFO(first in, first out) data structure
– Any waiting line is a queue:
– The check-out line at a grocery store
– The cars at a stop light
– Ticket counter
Conceptual view of a Queue
Uses of Queue in computing
• For any kind of problem involving FIFO Data.
• Printer Queue
• Keyboard Input buffer
• GUI Event Queue
• Web browser request Queue
Uses of Queues in computing
• In simulation studies, where the goal is to
reduce waiting times:
– Optimize the flow of traffic at a traffic light
– Determine the number of cashiers to have on duty
at a grocery store at different times of day
• Process Scheduling
• Printer Queues in Network
Queue Operations
• Enqueue(x) or push(x): add an element to the tail
of a queue.
• Dequeue() or pop(): remove an element from the
head of a queue.
• Front() or peek(): examine the element at the
head of the queue.
• QEmpty() or IsEmpty()
• QFull() or IsFull()
• It is not legal to access the elements in the
middle of the queue!
Implementation of Queues
• Array
• Linked List
Array Implementation
C Code
C code
Circular Queue
• Why we need a circular queue, when we
already have linear queue data structure.
Circular Queue
• Circular Queue is also a linear data structure, which follows
the principle of FIFO(First In First Out), but instead of ending
the queue at the last position, it again starts from the first
position after the last, hence making the queue behave like a
circular data structure.
Circular Queue
• In a circular queue, data is not actually removed from the queue. Only
the head pointer is incremented by one position when dequeue is
executed. As the queue data is only the data between head and tail, hence
the data left outside is not a part of the queue anymore, hence removed.
Circular Queue
• The head and the tail pointer will get reinitialised to 0 every
time they reach the end of the queue.
• Current Position = i
• Next Position = (i+1)% N
• Previous Position = (i+N-1)%N
Application of Circular Queue
• Below we have some common real-world
examples where circular queues are used:
• Computer controlled Traffic Signal
System uses circular queue.
• CPU scheduling and Memory management.
Implementation of Circular Queue
Implementation of Circular Queue
C Code – Circular Queue
Double ended Queue
• Deque or Double Ended Queue is a type of queue in which insertion
and removal of elements can be performed from either from the
front or rear. Thus, it does not follow FIFO rule (First In First Out).
• Types of Deque
• Input Restricted Deque
– In this deque, input is restricted at a single end but allows deletion at both
the ends.
• Output Restricted Deque
– In this deque, output is restricted at a single end but allows insertion at
both the ends.
Applications
Algorithm
C Code
Priority Queue
• Priority Queue is an extension of queue with
following properties.
– Every item has a priority associated with it.
– An element with high priority is dequeued before
an element with low priority.
– If two elements have the same priority, they are
served according to their order in the queue.
Priority Queue
• In a queue, the first-in-first-out rule is implemented whereas,
in a priority queue, the values are removed on the basis of
priority. The element with the highest priority is removed
first.
Types of Priority Queue
• Min Priority Queue: In min priority Queue
minimum number of value gets the highest
priority and lowest number of element gets
the highest priority.
• Max Priority Queue: Max priority Queue is
the opposite of min priority Queue in it
maximum number value gets the highest
priority and minimum number of value gets
the minimum priority.
Solution
C Code
C Code
C Code
Priority Queue (Circular Q concept)
UNIT-2.pptx
UNIT-2.pptx

More Related Content

Similar to UNIT-2.pptx

Fundamentals of Data Structure and Queues
Fundamentals of Data Structure and QueuesFundamentals of Data Structure and Queues
Fundamentals of Data Structure and Queues
Bogiri Nagaraju
 
QUEUE
QUEUEQUEUE
QUEUEPTCL
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
mayankKatiyar17
 
Data Structures
Data StructuresData Structures
Data Structures
Dr.Umadevi V
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
Ddushb
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
SnehilKeshari
 
linked list in c++
linked list in c++linked list in c++
linked list in c++
YaminiLakshmi Meduri
 
Queue
QueueQueue
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
LECO9
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
SKUP1
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
Muhammad Hammad Waseem
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
Ds
DsDs
QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)
Mehedi Hasan
 
Implementation of queue using singly and doubly linked list.
Implementation of queue using singly and doubly linked list.Implementation of queue using singly and doubly linked list.
Implementation of queue using singly and doubly linked list.
central university of bihar
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
Dabbal Singh Mahara
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Lovely Professional University
 
II B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptxII B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptx
sabithabanu83
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
PLC
PLCPLC

Similar to UNIT-2.pptx (20)

Fundamentals of Data Structure and Queues
Fundamentals of Data Structure and QueuesFundamentals of Data Structure and Queues
Fundamentals of Data Structure and Queues
 
QUEUE
QUEUEQUEUE
QUEUE
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
Data Structures
Data StructuresData Structures
Data Structures
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
linked list in c++
linked list in c++linked list in c++
linked list in c++
 
Queue
QueueQueue
Queue
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
Ds
DsDs
Ds
 
QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)
 
Implementation of queue using singly and doubly linked list.
Implementation of queue using singly and doubly linked list.Implementation of queue using singly and doubly linked list.
Implementation of queue using singly and doubly linked list.
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
II B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptxII B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptx
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
PLC
PLCPLC
PLC
 

More from ChiragSuresh

wepik-mastering-the-art-of-entrepreneurship-20240313164953QR4t.pptx
wepik-mastering-the-art-of-entrepreneurship-20240313164953QR4t.pptxwepik-mastering-the-art-of-entrepreneurship-20240313164953QR4t.pptx
wepik-mastering-the-art-of-entrepreneurship-20240313164953QR4t.pptx
ChiragSuresh
 
PorterchitwetyujbzxcbbnmlkhggfdPorter.ppt
PorterchitwetyujbzxcbbnmlkhggfdPorter.pptPorterchitwetyujbzxcbbnmlkhggfdPorter.ppt
PorterchitwetyujbzxcbbnmlkhggfdPorter.ppt
ChiragSuresh
 
Unit-4- Process oveunit5and6forview.pptx
Unit-4- Process oveunit5and6forview.pptxUnit-4- Process oveunit5and6forview.pptx
Unit-4- Process oveunit5and6forview.pptx
ChiragSuresh
 
osama-quantum-computingoftge quantum.ppt
osama-quantum-computingoftge quantum.pptosama-quantum-computingoftge quantum.ppt
osama-quantum-computingoftge quantum.ppt
ChiragSuresh
 
Luo_SC_mc_butorqwertyuiomabsvsbsbsjC.ppt
Luo_SC_mc_butorqwertyuiomabsvsbsbsjC.pptLuo_SC_mc_butorqwertyuiomabsvsbsbsjC.ppt
Luo_SC_mc_butorqwertyuiomabsvsbsbsjC.ppt
ChiragSuresh
 
Bharti Airtel_ Connectivity Empowering Millions.pptx
Bharti Airtel_ Connectivity Empowering Millions.pptxBharti Airtel_ Connectivity Empowering Millions.pptx
Bharti Airtel_ Connectivity Empowering Millions.pptx
ChiragSuresh
 
509404501-Online-Shopping-System-Mini-Project-Ppt (1).pptx
509404501-Online-Shopping-System-Mini-Project-Ppt (1).pptx509404501-Online-Shopping-System-Mini-Project-Ppt (1).pptx
509404501-Online-Shopping-System-Mini-Project-Ppt (1).pptx
ChiragSuresh
 
Student repository System.pptx
Student repository System.pptxStudent repository System.pptx
Student repository System.pptx
ChiragSuresh
 
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.pptUnit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
ChiragSuresh
 

More from ChiragSuresh (9)

wepik-mastering-the-art-of-entrepreneurship-20240313164953QR4t.pptx
wepik-mastering-the-art-of-entrepreneurship-20240313164953QR4t.pptxwepik-mastering-the-art-of-entrepreneurship-20240313164953QR4t.pptx
wepik-mastering-the-art-of-entrepreneurship-20240313164953QR4t.pptx
 
PorterchitwetyujbzxcbbnmlkhggfdPorter.ppt
PorterchitwetyujbzxcbbnmlkhggfdPorter.pptPorterchitwetyujbzxcbbnmlkhggfdPorter.ppt
PorterchitwetyujbzxcbbnmlkhggfdPorter.ppt
 
Unit-4- Process oveunit5and6forview.pptx
Unit-4- Process oveunit5and6forview.pptxUnit-4- Process oveunit5and6forview.pptx
Unit-4- Process oveunit5and6forview.pptx
 
osama-quantum-computingoftge quantum.ppt
osama-quantum-computingoftge quantum.pptosama-quantum-computingoftge quantum.ppt
osama-quantum-computingoftge quantum.ppt
 
Luo_SC_mc_butorqwertyuiomabsvsbsbsjC.ppt
Luo_SC_mc_butorqwertyuiomabsvsbsbsjC.pptLuo_SC_mc_butorqwertyuiomabsvsbsbsjC.ppt
Luo_SC_mc_butorqwertyuiomabsvsbsbsjC.ppt
 
Bharti Airtel_ Connectivity Empowering Millions.pptx
Bharti Airtel_ Connectivity Empowering Millions.pptxBharti Airtel_ Connectivity Empowering Millions.pptx
Bharti Airtel_ Connectivity Empowering Millions.pptx
 
509404501-Online-Shopping-System-Mini-Project-Ppt (1).pptx
509404501-Online-Shopping-System-Mini-Project-Ppt (1).pptx509404501-Online-Shopping-System-Mini-Project-Ppt (1).pptx
509404501-Online-Shopping-System-Mini-Project-Ppt (1).pptx
 
Student repository System.pptx
Student repository System.pptxStudent repository System.pptx
Student repository System.pptx
 
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.pptUnit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
 

Recently uploaded

Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
itech2017
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 

Recently uploaded (20)

Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 

UNIT-2.pptx

  • 1. DATA STRUCTURES UNIT-2 SELVA KUMAR S ASSISTANT PROFESSOR B.M.S. COLLEGE OF ENGINEERING
  • 2. QUEUE -ADT • Queue: A list or a collection with the restrictions that insertion can be performed at one end (the rear or tail of the queue) and deletion can be performed at other end (the front or head of the queue). • A queue is a FIFO(first in, first out) data structure – Any waiting line is a queue: – The check-out line at a grocery store – The cars at a stop light – Ticket counter
  • 4. Uses of Queue in computing • For any kind of problem involving FIFO Data. • Printer Queue • Keyboard Input buffer • GUI Event Queue • Web browser request Queue
  • 5. Uses of Queues in computing • In simulation studies, where the goal is to reduce waiting times: – Optimize the flow of traffic at a traffic light – Determine the number of cashiers to have on duty at a grocery store at different times of day • Process Scheduling • Printer Queues in Network
  • 6. Queue Operations • Enqueue(x) or push(x): add an element to the tail of a queue. • Dequeue() or pop(): remove an element from the head of a queue. • Front() or peek(): examine the element at the head of the queue. • QEmpty() or IsEmpty() • QFull() or IsFull() • It is not legal to access the elements in the middle of the queue!
  • 7. Implementation of Queues • Array • Linked List
  • 11. Circular Queue • Why we need a circular queue, when we already have linear queue data structure.
  • 12. Circular Queue • Circular Queue is also a linear data structure, which follows the principle of FIFO(First In First Out), but instead of ending the queue at the last position, it again starts from the first position after the last, hence making the queue behave like a circular data structure.
  • 13. Circular Queue • In a circular queue, data is not actually removed from the queue. Only the head pointer is incremented by one position when dequeue is executed. As the queue data is only the data between head and tail, hence the data left outside is not a part of the queue anymore, hence removed.
  • 14. Circular Queue • The head and the tail pointer will get reinitialised to 0 every time they reach the end of the queue. • Current Position = i • Next Position = (i+1)% N • Previous Position = (i+N-1)%N
  • 15. Application of Circular Queue • Below we have some common real-world examples where circular queues are used: • Computer controlled Traffic Signal System uses circular queue. • CPU scheduling and Memory management.
  • 18.
  • 19. C Code – Circular Queue
  • 20.
  • 21. Double ended Queue • Deque or Double Ended Queue is a type of queue in which insertion and removal of elements can be performed from either from the front or rear. Thus, it does not follow FIFO rule (First In First Out). • Types of Deque • Input Restricted Deque – In this deque, input is restricted at a single end but allows deletion at both the ends. • Output Restricted Deque – In this deque, output is restricted at a single end but allows insertion at both the ends.
  • 24.
  • 26.
  • 27.
  • 28. Priority Queue • Priority Queue is an extension of queue with following properties. – Every item has a priority associated with it. – An element with high priority is dequeued before an element with low priority. – If two elements have the same priority, they are served according to their order in the queue.
  • 29. Priority Queue • In a queue, the first-in-first-out rule is implemented whereas, in a priority queue, the values are removed on the basis of priority. The element with the highest priority is removed first.
  • 30. Types of Priority Queue • Min Priority Queue: In min priority Queue minimum number of value gets the highest priority and lowest number of element gets the highest priority. • Max Priority Queue: Max priority Queue is the opposite of min priority Queue in it maximum number value gets the highest priority and minimum number of value gets the minimum priority.
  • 32.
  • 33.

Editor's Notes

  1. In a Linear queue, once the queue is completely full, it's not possible to insert more elements. Even if we dequeue the queue to remove some of the elements, until the queue is reset, no new elements can be inserted. You must be wondering why?
  2. Undo-redo in software application Multi processor scheduling