SlideShare a Scribd company logo
QUEUE
INTRODUCTION 
• It is linear data structure 
• It is collection of items – List 
• Queue means line of items waiting for their turn 
• Queue has two ends 
• Elements are added at one end. 
• Elements are removed from the other end.
QUEUE 
• Removal of data item is restricted at one end known as FRONT 
• Insertion of data item is restricted at other end known as REAR 
• The FRONT and REAR are used in describing a linear list, 
when queue is implemented 
• First element inserted in list, will be the first to be removed - 
FIFO
QUEUE AS FIFO 
• The element inserted first will be removed first from the Queue 
• Thus, Queue is known as FIFO (First In-First Out) or FCFS (First 
Come First Serve) 
• Examples of Queue 
○ People waiting in Queue to purchase tickets at railway station or cinema 
hall, where the first person in the queue will be served first
REPRESENTATION OF QUEUE 
• It has two pointer variables 
• ○ FRONT : Containing the location of the front element of the 
queue 
• ○ REAR : Containing the location of the rear element of the queue 
• When queue is empty 
• FRONT = -1 and REAR = -1
OPERATIONS OF QUEUE 
• Insertion 
• Adding an element in queue will increased 
• value of REAR by 1 
• REAR = REAR + 1 
• Removal 
• Removing an element from queue will increased value of FRONT by 1 
• FRONT = FRONT + 1
TYPES OF QUEUE 
• Simple queue 
• Circular Queue 
• Priority Queue 
• Dqueue
SIMPLE QUEUE 
• A simple queue is a list of item which are arranged in a line i.e. 
queue. 
• So we can do insertion only at rear end and the deleteion can be 
done at the front end only. 
• This way the insertion and deletion of the simple queue 
functions
SIMPLE QUEUE :-INSERTION 
INSERTION(QUEUE, F, R, N, item) 
Step 1. if (R >= N) 
print “Stack is full” 
return 0; 
Step 2. R = R + 1; /* Increment R*/ 
Step 3. QUEUE [R] =item; /*Insert Element*/ 
Step 4. if (F=-1) 
F=0; 
return f;
SIMPLE QUEUE :-DELETION 
PROCEDURE DELETE(QUEUE, F, R, item) 
[Deletes ‘item’ from the ‘stack’, ‘F’ is the Front end pointer and ‘R’ is the rare end pointer] 
Step 1. if (F == -1) /* Underflow*/ 
print “Stack is empty.” 
end; 
2. item = QUEUE[F]; /* Deleting Element*/ 
3. F = F + 1; /*Incrementing F*/ 
Step 4. if (F > R) 
then F = R = -1; 
end;
CIRCULAR QUEUE 
• To solve this problem, queues implement wrapping around. 
• Such queues are called Circular Queues. 
• Both the front and the rear pointers wrap around to the beginning of the 
array. 
• It is also called as “Ring buffer”. 
• Items can inserted and deleted from a queue in O(1) time.
CIRCULAR QUEUE 
• When a new item is inserted at the rear, the pointer to rear moves 
upwards. 
• Similarly, when an item is deleted from the queue the front arrow moves 
downwards. 
• After a few insert and delete operations the rear might reach the end of 
the queue and no more items can be inserted although the items from the 
front of the queue have been deleted and there is space in the queue.
CIRCULAR QUEUE :- INSERTION 
• Insert CQueue ( ) 
• Step 1. If (FRONT == 0 and REAR == N-1) or (FRONT == REAR + 1) Then 
• Step 2. Print: Overflow 
• Step 3. Else 
• Step 4. If (REAR == -1) Then [Check if QUEUE is empty] 
• (a) Set FRONT = 0 
• (b) Set REAR = 0 
• Step 5. Else If (REAR == N-1) Then [If REAR reaches end if QUEUE] 
• Step 6. Set REAR = 0 
• Step 7. Else 
• Step 8. Set REAR = REAR + 1 [Increment REAR by 1] [End of Step 4 If] 
• Step 9. Set QUEUE[REAR] = ITEM 
• Step 10. Print: ITEM inserted 
• [End of Step 1 If] 
• Step11. Exit
CIRCULAR QUEUE :-DELETION 
• Delete CircularQueue ( ) 
• Step 1. If (FRONT == -1) Then [Check for Underflow] 
• Step 2. Print: Underflow 
• Step 3. Else 
• Step 4. ITEM = QUEUE[FRONT] 
• Step 5. If (FRONT == REAR) Then [If only element is left] 
• (a) Set FRONT = -1 
• (b) Set REAR = -1 
• Step 6. Else If (FRONT == N-1) Then [If FRONT reaches end if QUEUE] 
• Step 7. Set FRONT = 0 
• Step 8. Else 
• Step 9. Set FRONT = FRONT + 1 [Increment FRONT by 1] 
• [End of Step 5 If] 
• Step 10. Print: ITEM deleted 
• [End of Step 1 If] 
• Step 11. Exit
PRIORITY QUEUE 
Suppose you have to work o few assignment then on which 
assignment will you work first ? So here we have decided the priority 
of the work to be done 
You have set priority on basis of days . And this is known as keys.
PRIORITY QUEUE 
• It 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 
• 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.
PRIORITY QUEUE 
• When you want to determine the priority for your assignments, 
you need a value for each assignment, that you can compare 
with each other. 
• key: An object that is assigned to an element as a specific 
attribute for that element, which can be used to identify , rank , 
or weight that element.
• Example: Student records 
• Any of the attributes, Student Name, Student Number, or Final Score 
can be used as keys. 
• Note: Keys may not be unique (Final Score).
RULES TO MAINTAIN A PRIORITY QUEUE 
• The elements with the higher priority will be processed before any 
element of lower priority 
• If there are elements with the same priority, then the element 
added first in the queue would get processed
PRIORITY QUEUE :- INSERTION 
• Step 1:q insert(q,val,prno) 
• Step 2:if (q->rear[prno]=Max-1 and q->front[prno]=0) or (q->rear[prno]+1=q->front[prno]) 
• Step 3:print “overflow” 
• Step 4:if q->rear[prno-1]=Max-1 
• Step 5:set q->rear[prno-1]=0; 
• Step 6:else 
• Step 7:set q->rear[prno-1]=q->rear[prno-1]+1; 
• Step 8:end if 
• Step 8:set q->cqueue(prno-1)[q->rear[prno-1]]=val 
• Step 9:if q->front[prno-1]=0; 
• Step 10:End if 
• Step 11:end
PRIORITY QUEUE :- DELETION 
• Step 1:Qdelete(q) 
• Step 2:set flag=0,i=0; 
• Step 3:while i<=Max-1 
• Step 4:If not(q->front[prno])=-1 
• Step 5:set flag=1; 
• Step 6:set del_val=q->cqueue[i][q->front[i]] 
• Step 7:if q->front[i]=q->rear[i] 
• Step 8:set q->front[i]=q->rear[i]=-1; 
• Step 9:Else if q->front[i]=Max-1 
• Step 10:set q->front=0
PRIORITY QUEUE :- DELETION 
• Step 11:else 
• Step 12 :set q->front[i]=q->front[i]+1; 
• Step 13:End if 
• Step 14:End if 
• Step 15:Break 
• Step 16:End if 
• Step 17:Set i=i+1 
• Step 18:End while 
• Step 19:If flag=0 
• Step 20:Print “underflow” 
• Step 21:Return 0 and go to step 4 
• Step 22:Else 
• Step 23:Return del_val 
• Step 24:End if 
• Step 25:end
DEQUE 
• Deque stands for double-end queue 
• A data structure in which elements can be added or deleted at either the 
front or rear 
• But no changes can be made in the list 
• Deque is generalization of both stack and queue
DEQUE :- INSERT AND DELETE 
• There are two variations of a deque. 
• These are 
• Input Restricted Deque 
• An input restricted deque restricts the insertion of elements at one 
end only, but the deletion of elements can perform at both the 
ends. 
• Output Restricted Deque 
• An output restricted queue, restricts the deletion of elements at 
one end only, and allows insertion to be done at both the ends of 
deque
POSSIBILITIES 
• The two possibilities that must be considered while inserting or 
deleting elements into the queue are : 
• When an attempt is made to insert a element into a deque which is 
already full, an overflow occurs. 
• When an attempt is made to delete an element from a deque which is 
empty , underflow occurs.
REPRESENTATION OF DEQUE
INSERTING ELEMENT IN DEQUE
REMOVING ELEMENT FROM DEQUE
INPUT RESTRICTED QUEUE : INSERT ELEMENT 
• Step 1: start 
• Step 2:[check condition for overflow] 
• If(rear==N-1 && front==0 or front=rear+1) 
• Print “over flow” 
• else 
• goto step 3 
• Step 3: [check condition] 
• If(front==null) 
• front = 0 and rear=-1
INPUT RESTRICTED QUEUE : INSERT ELEMENT 
• else 
• goto step 4 
• Step 4: [check condition and value] 
• If (rear== N -1) 
• rear=0 
• Else 
• rear=rear+1 
• Step 5: [Add value] 
• dq[rear]=value 
• Step 6:end
INPUT RESTRICTED QUEUE : 
DELETE BEGINNING 
• Step 1: start 
• Step 2: [check condition for underflow] 
• If(rear==null & front==null) 
• Print”underflow” 
• else 
• goto step 3 
• Step 3: [delete] 
• dq[rear]=null 
• Step 4: [check condition] 
• If(rear==front) 
• front=rear=null 
• else 
• rear--; 
• Step 5: end
INPUT RESTRICTED QUEUE : 
• Step 1: start DELETE END 
• Step2 : [check condition for under flow) 
• If(rear==null & front==null) 
• Print “under flow” 
• else 
• goto step 3 
• Step 3: [delete] 
• dq[front]=null 
• Step 4: [check condition] 
• If(rear==front) 
• rear=-1 and front=null 
• else 
• front=front+1 
• Step 5: end
Detalied information of queue

More Related Content

What's hot

Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
btechsmartclass
 
Priority queues
Priority queuesPriority queues
Priority queues
Priyanka Rana
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
Vineeta Garg
 
Queue-Data Structure
Queue-Data StructureQueue-Data Structure
Queue-Data Structure
Paurav Shah
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
Roman Rodomansky
 
Team 6
Team 6Team 6
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
Farhanum Aziera
 
Queues
QueuesQueues
Queues
Sadaf Ismail
 
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
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
Queue
QueueQueue
Queue
Raj Sarode
 
Queue
QueueQueue
Queue data structure
Queue data structureQueue data structure
Queue data structure
Mekk Mhmd
 
Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)
Adam Mukharil Bachtiar
 
Queue
QueueQueue
Dsa circular queue
Dsa circular queueDsa circular queue
Dsa circular queue
zzzubair
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
Mandeep Singh
 

What's hot (20)

Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Queue-Data Structure
Queue-Data StructureQueue-Data Structure
Queue-Data Structure
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Team 6
Team 6Team 6
Team 6
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
Queues
QueuesQueues
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)
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)
 
Queue
QueueQueue
Queue
 
Dsa circular queue
Dsa circular queueDsa circular queue
Dsa circular queue
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 

Similar to Detalied information of queue

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
 
Queue
QueueQueue
08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex
SadiaSharmin40
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
Ddushb
 
Queue
QueueQueue
Data structures
Data structuresData structures
Data structures
Sneha Chopra
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
MattFlordeliza1
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
shaik faroq
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
SherinRappai
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
MeghaKulkarni27
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
Soumen Santra
 
QUEUES
QUEUESQUEUES
stack and queue array implementation, java.
stack and queue array implementation, java.stack and queue array implementation, java.
stack and queue array implementation, java.
CIIT Atd.
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
CIIT Atd.
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
MeghaKulkarni27
 
Queues
Queues Queues
Queues
nidhisatija1
 
Lecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsLecture 7 data structures and algorithms
Lecture 7 data structures and algorithms
Aakash deep Singhal
 
6.queue
6.queue6.queue
6.queue
Chandan Singh
 

Similar to Detalied information of queue (20)

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
 
Queue
QueueQueue
Queue
 
08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
Queue
QueueQueue
Queue
 
Data structures
Data structuresData structures
Data structures
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 
QUEUES
QUEUESQUEUES
QUEUES
 
stack and queue array implementation, java.
stack and queue array implementation, java.stack and queue array implementation, java.
stack and queue array implementation, java.
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
 
Queues
Queues Queues
Queues
 
Lecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsLecture 7 data structures and algorithms
Lecture 7 data structures and algorithms
 
6.queue
6.queue6.queue
6.queue
 

Recently uploaded

Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 

Recently uploaded (20)

Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 

Detalied information of queue

  • 2. INTRODUCTION • It is linear data structure • It is collection of items – List • Queue means line of items waiting for their turn • Queue has two ends • Elements are added at one end. • Elements are removed from the other end.
  • 3. QUEUE • Removal of data item is restricted at one end known as FRONT • Insertion of data item is restricted at other end known as REAR • The FRONT and REAR are used in describing a linear list, when queue is implemented • First element inserted in list, will be the first to be removed - FIFO
  • 4. QUEUE AS FIFO • The element inserted first will be removed first from the Queue • Thus, Queue is known as FIFO (First In-First Out) or FCFS (First Come First Serve) • Examples of Queue ○ People waiting in Queue to purchase tickets at railway station or cinema hall, where the first person in the queue will be served first
  • 5. REPRESENTATION OF QUEUE • It has two pointer variables • ○ FRONT : Containing the location of the front element of the queue • ○ REAR : Containing the location of the rear element of the queue • When queue is empty • FRONT = -1 and REAR = -1
  • 6. OPERATIONS OF QUEUE • Insertion • Adding an element in queue will increased • value of REAR by 1 • REAR = REAR + 1 • Removal • Removing an element from queue will increased value of FRONT by 1 • FRONT = FRONT + 1
  • 7.
  • 8. TYPES OF QUEUE • Simple queue • Circular Queue • Priority Queue • Dqueue
  • 9. SIMPLE QUEUE • A simple queue is a list of item which are arranged in a line i.e. queue. • So we can do insertion only at rear end and the deleteion can be done at the front end only. • This way the insertion and deletion of the simple queue functions
  • 10. SIMPLE QUEUE :-INSERTION INSERTION(QUEUE, F, R, N, item) Step 1. if (R >= N) print “Stack is full” return 0; Step 2. R = R + 1; /* Increment R*/ Step 3. QUEUE [R] =item; /*Insert Element*/ Step 4. if (F=-1) F=0; return f;
  • 11. SIMPLE QUEUE :-DELETION PROCEDURE DELETE(QUEUE, F, R, item) [Deletes ‘item’ from the ‘stack’, ‘F’ is the Front end pointer and ‘R’ is the rare end pointer] Step 1. if (F == -1) /* Underflow*/ print “Stack is empty.” end; 2. item = QUEUE[F]; /* Deleting Element*/ 3. F = F + 1; /*Incrementing F*/ Step 4. if (F > R) then F = R = -1; end;
  • 12. CIRCULAR QUEUE • To solve this problem, queues implement wrapping around. • Such queues are called Circular Queues. • Both the front and the rear pointers wrap around to the beginning of the array. • It is also called as “Ring buffer”. • Items can inserted and deleted from a queue in O(1) time.
  • 13. CIRCULAR QUEUE • When a new item is inserted at the rear, the pointer to rear moves upwards. • Similarly, when an item is deleted from the queue the front arrow moves downwards. • After a few insert and delete operations the rear might reach the end of the queue and no more items can be inserted although the items from the front of the queue have been deleted and there is space in the queue.
  • 14. CIRCULAR QUEUE :- INSERTION • Insert CQueue ( ) • Step 1. If (FRONT == 0 and REAR == N-1) or (FRONT == REAR + 1) Then • Step 2. Print: Overflow • Step 3. Else • Step 4. If (REAR == -1) Then [Check if QUEUE is empty] • (a) Set FRONT = 0 • (b) Set REAR = 0 • Step 5. Else If (REAR == N-1) Then [If REAR reaches end if QUEUE] • Step 6. Set REAR = 0 • Step 7. Else • Step 8. Set REAR = REAR + 1 [Increment REAR by 1] [End of Step 4 If] • Step 9. Set QUEUE[REAR] = ITEM • Step 10. Print: ITEM inserted • [End of Step 1 If] • Step11. Exit
  • 15. CIRCULAR QUEUE :-DELETION • Delete CircularQueue ( ) • Step 1. If (FRONT == -1) Then [Check for Underflow] • Step 2. Print: Underflow • Step 3. Else • Step 4. ITEM = QUEUE[FRONT] • Step 5. If (FRONT == REAR) Then [If only element is left] • (a) Set FRONT = -1 • (b) Set REAR = -1 • Step 6. Else If (FRONT == N-1) Then [If FRONT reaches end if QUEUE] • Step 7. Set FRONT = 0 • Step 8. Else • Step 9. Set FRONT = FRONT + 1 [Increment FRONT by 1] • [End of Step 5 If] • Step 10. Print: ITEM deleted • [End of Step 1 If] • Step 11. Exit
  • 16. PRIORITY QUEUE Suppose you have to work o few assignment then on which assignment will you work first ? So here we have decided the priority of the work to be done You have set priority on basis of days . And this is known as keys.
  • 17. PRIORITY QUEUE • It 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 • 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.
  • 18. PRIORITY QUEUE • When you want to determine the priority for your assignments, you need a value for each assignment, that you can compare with each other. • key: An object that is assigned to an element as a specific attribute for that element, which can be used to identify , rank , or weight that element.
  • 19. • Example: Student records • Any of the attributes, Student Name, Student Number, or Final Score can be used as keys. • Note: Keys may not be unique (Final Score).
  • 20. RULES TO MAINTAIN A PRIORITY QUEUE • The elements with the higher priority will be processed before any element of lower priority • If there are elements with the same priority, then the element added first in the queue would get processed
  • 21. PRIORITY QUEUE :- INSERTION • Step 1:q insert(q,val,prno) • Step 2:if (q->rear[prno]=Max-1 and q->front[prno]=0) or (q->rear[prno]+1=q->front[prno]) • Step 3:print “overflow” • Step 4:if q->rear[prno-1]=Max-1 • Step 5:set q->rear[prno-1]=0; • Step 6:else • Step 7:set q->rear[prno-1]=q->rear[prno-1]+1; • Step 8:end if • Step 8:set q->cqueue(prno-1)[q->rear[prno-1]]=val • Step 9:if q->front[prno-1]=0; • Step 10:End if • Step 11:end
  • 22. PRIORITY QUEUE :- DELETION • Step 1:Qdelete(q) • Step 2:set flag=0,i=0; • Step 3:while i<=Max-1 • Step 4:If not(q->front[prno])=-1 • Step 5:set flag=1; • Step 6:set del_val=q->cqueue[i][q->front[i]] • Step 7:if q->front[i]=q->rear[i] • Step 8:set q->front[i]=q->rear[i]=-1; • Step 9:Else if q->front[i]=Max-1 • Step 10:set q->front=0
  • 23. PRIORITY QUEUE :- DELETION • Step 11:else • Step 12 :set q->front[i]=q->front[i]+1; • Step 13:End if • Step 14:End if • Step 15:Break • Step 16:End if • Step 17:Set i=i+1 • Step 18:End while • Step 19:If flag=0 • Step 20:Print “underflow” • Step 21:Return 0 and go to step 4 • Step 22:Else • Step 23:Return del_val • Step 24:End if • Step 25:end
  • 24. DEQUE • Deque stands for double-end queue • A data structure in which elements can be added or deleted at either the front or rear • But no changes can be made in the list • Deque is generalization of both stack and queue
  • 25. DEQUE :- INSERT AND DELETE • There are two variations of a deque. • These are • Input Restricted Deque • An input restricted deque restricts the insertion of elements at one end only, but the deletion of elements can perform at both the ends. • Output Restricted Deque • An output restricted queue, restricts the deletion of elements at one end only, and allows insertion to be done at both the ends of deque
  • 26. POSSIBILITIES • The two possibilities that must be considered while inserting or deleting elements into the queue are : • When an attempt is made to insert a element into a deque which is already full, an overflow occurs. • When an attempt is made to delete an element from a deque which is empty , underflow occurs.
  • 29.
  • 31. INPUT RESTRICTED QUEUE : INSERT ELEMENT • Step 1: start • Step 2:[check condition for overflow] • If(rear==N-1 && front==0 or front=rear+1) • Print “over flow” • else • goto step 3 • Step 3: [check condition] • If(front==null) • front = 0 and rear=-1
  • 32. INPUT RESTRICTED QUEUE : INSERT ELEMENT • else • goto step 4 • Step 4: [check condition and value] • If (rear== N -1) • rear=0 • Else • rear=rear+1 • Step 5: [Add value] • dq[rear]=value • Step 6:end
  • 33. INPUT RESTRICTED QUEUE : DELETE BEGINNING • Step 1: start • Step 2: [check condition for underflow] • If(rear==null & front==null) • Print”underflow” • else • goto step 3 • Step 3: [delete] • dq[rear]=null • Step 4: [check condition] • If(rear==front) • front=rear=null • else • rear--; • Step 5: end
  • 34. INPUT RESTRICTED QUEUE : • Step 1: start DELETE END • Step2 : [check condition for under flow) • If(rear==null & front==null) • Print “under flow” • else • goto step 3 • Step 3: [delete] • dq[front]=null • Step 4: [check condition] • If(rear==front) • rear=-1 and front=null • else • front=front+1 • Step 5: end