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

What's hot

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
eShikshak
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
pinakspatel
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
Srajan Shukla
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Lovely Professional University
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
Circular queue
Circular queueCircular queue
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
NUPOORAWSARMOL
 
Quick sort
Quick sortQuick sort
Quick sort
Jehat Hassan
 
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
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Poojith Chowdhary
 
Queues
QueuesQueues
Shell sorting
Shell sortingShell sorting
Shell sorting
TUC
 

What's hot (20)

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Circular queue
Circular queueCircular queue
Circular queue
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
 
Quick sort
Quick sortQuick sort
Quick sort
 
Link list
Link listLink list
Link list
 
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
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Queues
QueuesQueues
Queues
 
Shell sorting
Shell sortingShell sorting
Shell sorting
 

Similar to Queue-Data Structure

Queue
QueueQueue
Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Ramachandra Adiga G
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
RAtna29
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
Vineeta Garg
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
maneesh boddu
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
Toseef Hasan
 
05 queues
05 queues05 queues
05 queues
Rajan Gautam
 
Stack q ll algo
Stack q ll algoStack q ll algo
Stack q ll algo
parthpatel9694
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
poongothai11
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
SherinRappai
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
maamir farooq
 
Queues and Stacks
Queues and StacksQueues and Stacks
Queues and Stacks
Prof Ansari
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
Mandeep Singh
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
NuraMohamed9
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
Hasan Mahadi Riaz
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
surya pandian
 
Data structure day4
Data structure day4Data structure day4
Data structure day4
Mohammed Elsdody
 

Similar to Queue-Data Structure (20)

Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
05 queues
05 queues05 queues
05 queues
 
Stack q ll algo
Stack q ll algoStack q ll algo
Stack q ll algo
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Lect 17-18 Zaheer Abbas
Lect 17-18 Zaheer AbbasLect 17-18 Zaheer Abbas
Lect 17-18 Zaheer Abbas
 
Queues and Stacks
Queues and StacksQueues and Stacks
Queues and Stacks
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
 
Data structure day4
Data structure day4Data structure day4
Data structure day4
 

More from Paurav Shah

Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
Paurav Shah
 
Cost and Cost Concepts
Cost and Cost ConceptsCost and Cost Concepts
Cost and Cost Concepts
Paurav Shah
 
3 D (3-Dimensional) Glasses
3 D (3-Dimensional) Glasses3 D (3-Dimensional) Glasses
3 D (3-Dimensional) Glasses
Paurav Shah
 
Design issues with constraints of E-R model
Design issues with constraints of E-R modelDesign issues with constraints of E-R model
Design issues with constraints of E-R model
Paurav Shah
 
Android and iOS Mobile OS
Android and iOS Mobile OSAndroid and iOS Mobile OS
Android and iOS Mobile OS
Paurav Shah
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital Electronics
Paurav Shah
 
File Management in C
File Management in CFile Management in C
File Management in C
Paurav Shah
 
Contributor Career Strategies
Contributor Career StrategiesContributor Career Strategies
Contributor Career Strategies
Paurav Shah
 
Semiconductor and It's Importance
Semiconductor and It's ImportanceSemiconductor and It's Importance
Semiconductor and It's Importance
Paurav Shah
 
Earthing
EarthingEarthing
Earthing
Paurav Shah
 
Builiding A Good Personality
Builiding A Good PersonalityBuiliding A Good Personality
Builiding A Good Personality
Paurav Shah
 

More from Paurav Shah (11)

Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
Cost and Cost Concepts
Cost and Cost ConceptsCost and Cost Concepts
Cost and Cost Concepts
 
3 D (3-Dimensional) Glasses
3 D (3-Dimensional) Glasses3 D (3-Dimensional) Glasses
3 D (3-Dimensional) Glasses
 
Design issues with constraints of E-R model
Design issues with constraints of E-R modelDesign issues with constraints of E-R model
Design issues with constraints of E-R model
 
Android and iOS Mobile OS
Android and iOS Mobile OSAndroid and iOS Mobile OS
Android and iOS Mobile OS
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital Electronics
 
File Management in C
File Management in CFile Management in C
File Management in C
 
Contributor Career Strategies
Contributor Career StrategiesContributor Career Strategies
Contributor Career Strategies
 
Semiconductor and It's Importance
Semiconductor and It's ImportanceSemiconductor and It's Importance
Semiconductor and It's Importance
 
Earthing
EarthingEarthing
Earthing
 
Builiding A Good Personality
Builiding A Good PersonalityBuiliding A Good Personality
Builiding A Good Personality
 

Recently uploaded

Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
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
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 

Recently uploaded (20)

Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
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
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.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.