4
Most read
8
Most read
13
Most read
Queue
DATA STRUCTURE
Introduction
 A queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the
principal (or only) operations on the collection are the addition (insertion) of entities to the rear terminal position, known
as enqueue, and removal (deletion) of entities from the front terminal position, known as dequeue.
 This makes the queue a First-In-First-Out (FIFO) or a First-Come-First-Served (FCFS) data structure. In a FIFO data structure, the
first element added to the queue will be the first one to be removed.
Examples
 A checkout line at supermarket cash counter, cashier counter in a bank, ticket counter for fare, etc. The first person in the line is
(usually) the first to be checked out.
 Another example is of printing documents. The document given first for printing will be printed first & other documents will
follow the sequence.
Representation of Queue
 When queue is empty
FRONT = -1 and REAR = -1
 Adding an element in queue will increased value of REAR by 1
REAR = REAR + 1
 Removing an element from queue will increased value of FRONT by 1
FRONT = FRONT + 1
 The vector is assumed to consist of a large number of elements, enough to be sufficient to handle the variable length
property of queue.
 The vector representation of a queue requires pointers F & R which denote the positions of its front & rear elements
respectively.
Operations of Queue
Types of Queue
 Linear (Simple) Queue
 Circular Queue
 Double-ended Queue (Deque)
 Priority Queue
1. Linear (Simple) Queue
 Insert Operation
 Function: LQINSERT (Q,F,R,N,Y). Given F & R, pointers
to the front and rear elements of a queue, a vector Q
consisting of N elements and an element Y, this
procedure inserts Y at the rear of the queue.
 Set F=R=-1, when queue is empty.
Algorithm
Step-1: [Check overflow?]
if R>=N-1
then Write (‘Overflow’)
Return
Step-2: [Increment rear pointer R]
R  R + 1
Step-3: [Insert element]
Q[R]  Y
Step-4: [Set front pointer F]
if F=-1
then F  0
Return
 Delete Operation
 Function: LQDELETE (Q,F,R). Given F & R, pointers to the front and
rear elements of a queue, a queue Q consisting to which they
correspond, this function deletes and returns the last element of the
queue. Y is a temporary variable.
Algorithm
Step-1: [Check underflow?]
if F=-1
then Write (‘Underflow’)
Return
Step-2: [Delete element]
Y  Q[F]
Step-3: [Check for queue empty or has an element?]
if F=R
then F=R=-1
else
F  F + 1
Step-4: [Return element]
Return(Y)
Example
2. Circular Queue
 In circular queue, all the elements are arranged in a circular form.
 Here, the left spaces can be reutilized to insert new variables which was not the case with linear queue.
 Insert Operation
 Function: CQINSERT (Q,F,R,N,Y). Given F & R, pointers
to the front and rear elements of a queue, a vector Q
consisting of N elements and an element Y, this
procedure inserts Y at the rear of the queue.
 Set F=R=-1, when queue is empty.
Algorithm
Step-1: [Reset rear pointer R]
if R>=N-1
then R  0
else R  R + 1
Step-2: [Check overflow?]
if F=R
then Write (‘Overflow’)
Return
Step-3: [Insert element]
Q[R]  Y
Step-4: [Set front pointer F]
if F=-1, then F  0
Return
 Delete Operation
 Function: CQDELETE (Q,F,R). Given F & R, pointers to the front and
rear elements of a queue, a queue Q consisting to which they
correspond, this function deletes and returns the last element of the
queue. Y is a temporary variable.
Algorithm
Step-1: [Check underflow?]
if F=-1
then Write (‘Underflow’)
Step-2: [Delete element]
Y  Q[F]
Step-3: [Check for queue empty or has an element?]
if F=R
then F=R=-1
Return(Y)
Step-4: [Increment front pointer F]
if F=N-1
then F  0,
else F  F + 1
Return(Y)
Example
3. Double-ended Queue (Deque)
 A deque (double-ended queue) is a linear list in which insertions and deletions are made to or from either
end of the structure.
 It is clear that deque is more general than a stack or a queue.
 There are two variations of a deque, namely, the input-restricted deque and the output-restricted deque.
 The input-restricted deque allows insertions at only one end, while an output-restricted deque permits
deletions from only one end.
 Input-restricted Deque
 Output-restricted Deque
4. Priority Queue
 A priority queue is collection of elements where elements are stored according to the their priority levels.
 Inserting and removing of elements from queue is decided by the priority of the elements.
 In a priority queue, an element with high priority is served before an element with low priority.
 If two elements have the same priority, they are served according to their order in the queue.
 The two fundamental methods of a priority queue P:
insertItem(k,e): Insert an element e with key k into P.
removeMin(): Return and remove from P an element with the smallest key.
Queue-Data Structure

More Related Content

PPTX
PPTX
Ppt on Linked list,stack,queue
PPTX
Queues in C++
PPTX
Deque and its applications
PPT
Queue Data Structure
PPTX
Double Linked List (Algorithm)
PPTX
Queue
PDF
Quick Sort , Merge Sort , Heap Sort
Ppt on Linked list,stack,queue
Queues in C++
Deque and its applications
Queue Data Structure
Double Linked List (Algorithm)
Queue
Quick Sort , Merge Sort , Heap Sort

What's hot (20)

PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
PPTX
PPSX
Data Structure (Queue)
PPTX
Unit 3 stack
PPTX
Queue in Data Structure
PPTX
Stack of Data structure
PPTX
The Stack And Recursion
PPTX
queue & its applications
PPT
Queue data structure
PPTX
Linked list
PPT
Abstract data types (adt) intro to data structure part 2
PPTX
Insertion sort
PPTX
Stacks in DATA STRUCTURE
PPT
Stack Data Structure & It's Application
PPTX
Stack and its applications
PPTX
Doubly linked list (animated)
PPTX
sorting and its types
PPT
Queue in Data Structure
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Data Structure (Queue)
Unit 3 stack
Queue in Data Structure
Stack of Data structure
The Stack And Recursion
queue & its applications
Queue data structure
Linked list
Abstract data types (adt) intro to data structure part 2
Insertion sort
Stacks in DATA STRUCTURE
Stack Data Structure & It's Application
Stack and its applications
Doubly linked list (animated)
sorting and its types
Queue in Data Structure
Ad

Similar to Queue-Data Structure (20)

PPTX
Queue Data Structures Intro and Types of Queue
PPTX
PPT
PPTX
Data Structures: Stacks (Part 1)
PPTX
Data strutcure and annalysis topic stack
PPTX
Stack and Queue.pptx university exam preparation
PPTX
Data Structures Stack and Queue Data Structures
PPT
Data Structures by Maneesh Boddu
PDF
Stacks,queues,linked-list
PPT
Lecture three of datat structures ,.The Queue-ds.ppt
PPTX
Queues presentation
PPT
queue (1).ppt queue notes and ppt in Data Structures
PPTX
UNIT II LINEAR DATA STRUCTURES – STACKS.pptx
PDF
Polynomialmotilalanehrunationalinstitute.pdf
PDF
05 queues
DOCX
Stack q ll algo
PPTX
Stack and its operations, Queue and its operations
DOCX
CDS artificial intelligence and Machine.docx
PPTX
Stack.pptx
PPTX
Queue - Data Structure - Notes
Queue Data Structures Intro and Types of Queue
Data Structures: Stacks (Part 1)
Data strutcure and annalysis topic stack
Stack and Queue.pptx university exam preparation
Data Structures Stack and Queue Data Structures
Data Structures by Maneesh Boddu
Stacks,queues,linked-list
Lecture three of datat structures ,.The Queue-ds.ppt
Queues presentation
queue (1).ppt queue notes and ppt in Data Structures
UNIT II LINEAR DATA STRUCTURES – STACKS.pptx
Polynomialmotilalanehrunationalinstitute.pdf
05 queues
Stack q ll algo
Stack and its operations, Queue and its operations
CDS artificial intelligence and Machine.docx
Stack.pptx
Queue - Data Structure - Notes
Ad

More from Paurav Shah (11)

PPTX
Scheduling algorithms
PPTX
Cost and Cost Concepts
PPTX
3 D (3-Dimensional) Glasses
PPTX
Design issues with constraints of E-R model
PPTX
Android and iOS Mobile OS
PPTX
Decoders-Digital Electronics
PPTX
File Management in C
PPTX
Contributor Career Strategies
PPTX
Semiconductor and It's Importance
PPTX
Earthing
PPTX
Builiding A Good Personality
Scheduling algorithms
Cost and Cost Concepts
3 D (3-Dimensional) Glasses
Design issues with constraints of E-R model
Android and iOS Mobile OS
Decoders-Digital Electronics
File Management in C
Contributor Career Strategies
Semiconductor and It's Importance
Earthing
Builiding A Good Personality

Recently uploaded (20)

PDF
Applications of Equal_Area_Criterion.pdf
PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PPTX
mechattonicsand iotwith sensor and actuator
PPTX
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
PPTX
Principal presentation for NAAC (1).pptx
PDF
20250617 - IR - Global Guide for HR - 51 pages.pdf
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
Prof. Dr. KAYIHURA A. SILAS MUNYANEZA, PhD..pdf
PPTX
ai_satellite_crop_management_20250815030350.pptx
PDF
Unit1 - AIML Chapter 1 concept and ethics
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPT
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
PDF
Implantable Drug Delivery System_NDDS_BPHARMACY__SEM VII_PCI .pdf
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PDF
Abrasive, erosive and cavitation wear.pdf
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
Applications of Equal_Area_Criterion.pdf
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
Soil Improvement Techniques Note - Rabbi
mechattonicsand iotwith sensor and actuator
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
Principal presentation for NAAC (1).pptx
20250617 - IR - Global Guide for HR - 51 pages.pdf
Management Information system : MIS-e-Business Systems.pptx
Prof. Dr. KAYIHURA A. SILAS MUNYANEZA, PhD..pdf
ai_satellite_crop_management_20250815030350.pptx
Unit1 - AIML Chapter 1 concept and ethics
Exploratory_Data_Analysis_Fundamentals.pdf
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
Implantable Drug Delivery System_NDDS_BPHARMACY__SEM VII_PCI .pdf
MLpara ingenieira CIVIL, meca Y AMBIENTAL
August 2025 - Top 10 Read Articles in Network Security & Its Applications
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
Abrasive, erosive and cavitation wear.pdf
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx

Queue-Data Structure

  • 2. Introduction  A queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition (insertion) of entities to the rear terminal position, known as enqueue, and removal (deletion) of entities from the front terminal position, known as dequeue.  This makes the queue a First-In-First-Out (FIFO) or a First-Come-First-Served (FCFS) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. Examples  A checkout line at supermarket cash counter, cashier counter in a bank, ticket counter for fare, etc. The first person in the line is (usually) the first to be checked out.  Another example is of printing documents. The document given first for printing will be printed first & other documents will follow the sequence.
  • 3. Representation of Queue  When queue is empty FRONT = -1 and REAR = -1  Adding an element in queue will increased value of REAR by 1 REAR = REAR + 1  Removing an element from queue will increased value of FRONT by 1 FRONT = FRONT + 1  The vector is assumed to consist of a large number of elements, enough to be sufficient to handle the variable length property of queue.  The vector representation of a queue requires pointers F & R which denote the positions of its front & rear elements respectively. Operations of Queue
  • 4. Types of Queue  Linear (Simple) Queue  Circular Queue  Double-ended Queue (Deque)  Priority Queue 1. Linear (Simple) Queue
  • 5.  Insert Operation  Function: LQINSERT (Q,F,R,N,Y). Given F & R, pointers to the front and rear elements of a queue, a vector Q consisting of N elements and an element Y, this procedure inserts Y at the rear of the queue.  Set F=R=-1, when queue is empty. Algorithm Step-1: [Check overflow?] if R>=N-1 then Write (‘Overflow’) Return Step-2: [Increment rear pointer R] R  R + 1 Step-3: [Insert element] Q[R]  Y Step-4: [Set front pointer F] if F=-1 then F  0 Return  Delete Operation  Function: LQDELETE (Q,F,R). Given F & R, pointers to the front and rear elements of a queue, a queue Q consisting to which they correspond, this function deletes and returns the last element of the queue. Y is a temporary variable. Algorithm Step-1: [Check underflow?] if F=-1 then Write (‘Underflow’) Return Step-2: [Delete element] Y  Q[F] Step-3: [Check for queue empty or has an element?] if F=R then F=R=-1 else F  F + 1 Step-4: [Return element] Return(Y)
  • 7. 2. Circular Queue  In circular queue, all the elements are arranged in a circular form.  Here, the left spaces can be reutilized to insert new variables which was not the case with linear queue.
  • 8.  Insert Operation  Function: CQINSERT (Q,F,R,N,Y). Given F & R, pointers to the front and rear elements of a queue, a vector Q consisting of N elements and an element Y, this procedure inserts Y at the rear of the queue.  Set F=R=-1, when queue is empty. Algorithm Step-1: [Reset rear pointer R] if R>=N-1 then R  0 else R  R + 1 Step-2: [Check overflow?] if F=R then Write (‘Overflow’) Return Step-3: [Insert element] Q[R]  Y Step-4: [Set front pointer F] if F=-1, then F  0 Return  Delete Operation  Function: CQDELETE (Q,F,R). Given F & R, pointers to the front and rear elements of a queue, a queue Q consisting to which they correspond, this function deletes and returns the last element of the queue. Y is a temporary variable. Algorithm Step-1: [Check underflow?] if F=-1 then Write (‘Underflow’) Step-2: [Delete element] Y  Q[F] Step-3: [Check for queue empty or has an element?] if F=R then F=R=-1 Return(Y) Step-4: [Increment front pointer F] if F=N-1 then F  0, else F  F + 1 Return(Y)
  • 10. 3. Double-ended Queue (Deque)  A deque (double-ended queue) is a linear list in which insertions and deletions are made to or from either end of the structure.  It is clear that deque is more general than a stack or a queue.  There are two variations of a deque, namely, the input-restricted deque and the output-restricted deque.  The input-restricted deque allows insertions at only one end, while an output-restricted deque permits deletions from only one end.
  • 11.  Input-restricted Deque  Output-restricted Deque
  • 12. 4. Priority Queue  A priority queue is collection of elements where elements are stored according to the their priority levels.  Inserting and removing of elements from queue is decided by the priority of the elements.  In a priority queue, an element with high priority is served before an element with low priority.  If two elements have the same priority, they are served according to their order in the queue.  The two fundamental methods of a priority queue P: insertItem(k,e): Insert an element e with key k into P. removeMin(): Return and remove from P an element with the smallest key.