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

QUEUE
QUEUEQUEUE
QUEUE
PTCL
 
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
 

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
 

Recently uploaded

Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
MaherOthman7
 

Recently uploaded (20)

Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentation
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUUNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & Modernization
 
Intro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney UniIntro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney Uni
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptx
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Students
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdf
 

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