尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
Queue
PREPARED BY:-
BHAVESH PARMAR(15ITS304)
 Queue
A queue is a linear Data structure in which insertion is performed at one end called rear and deletion is
performed at another end of the list is called front.
Type of Queue:
1.Simple Queue
2.Circularqueue
3.Dequeue
4.Priority Queue
 Representation of Queue
 The information in such a list is proceeds in the same order as it was received.
 Since insertion is performed at one end and deletion is performed at another end the element which is inserted
first is first to delete. So it is also known as First in First out (FIFO) or First Come First Serve (FCFS) data structure.
 Examples of Queue
A raw of students at registration counter.
Line of cars waiting to proceeds in some direction at traffic signal.
 Application of Queue
o A queue is the natural data structure for a system to serve its incoming requests. Most of
the process scheduling or disk scheduling algorithms in operating systems use queues.
o Computer hardware like a processor or a network card also maintain buffers in the form of
queues for incoming resource requests. A stack-like data structure causes starvation of the
first requests, and is not applicable in such cases.
o A mailbox or port to save messages to communicate between two users or processes in a
system is essentially a queue-like structure.
o Queue is widely used in Simulation.
 Operation on Simple Queue:
(1) Insert an element in to queue
(2) Delete an element from queue
1. Algorithm to insert an element in queue
PROCEDURE QINSERT (Q, F, R, N, Y)
• This function insert an element into the queue
• The Queue is represented by vector Q which contains N elements.
• F is a pointer which points to the front end
• R is a pointer which points to the rear end
• Y is the element to be inserted.
1) [Overflow?]
If R≥N then
Write (‘Overflow’)
2) [Increment rear pointer ]
RR+1
3) [Insert element]
Q[R]Y
4 ) [Is front pointer properly set?]
If F=0 then
F1
Return
2. Algorithm to delete an element from the queue
PROCEDURE QDELETE (Q, F, R)
• This function delete an element into the queue
• The Queue is represented by vector Q which contains N elements.
• F is a pointer which points to the front end
• R is a pointer which points to the rear end
• Y is the element to be inserted.
1) [Overflow?]
If R≥N then
Write (‘Overflow’)
2) [Delete element]
YQ [F]
3) [Queue empty?]
If F =R Then
F0
R0
Else FF+1
4) [Return element]
Return (y)
 For example consider following
operations:
o As shown in figure (a), we insert three elements 5, 10, 15 in simple queue.
o After that we delete 5 and 10 as shown in figure (b). Now even we have a free memory
space we cannot use that memory space. So simple queue results in wastage of memory
space.
o This problem can be solved by using circular queue.
 Circular Queue:
A circular queue is a queue in which elements are added and removed in a circular
fashion / manner, is called Circular Queue.
:
 Represent of circular Queue:
o As shown in figure (a), we insert eight elements 10, 20,30,40,50,60,70,80 in simple
queue. After that we delete 10, 20 and 30 as shown in figure (b). Now we have a free
memory space in circular queue and we can use that memory space by incrementing
rear pointer by 1(rear=0).
 Operations on Circular Queue
(1) Insert new element in to circular queue
(2) Delete element from circular queue
(1) Algorithm to insert element in circular queue
PROCEDURE CQINSERT (Q, F, R, N, Y)
o This function inserts an element in to circular queue.
o The Queue is represented by vector Q which contains N elements.
o F is a pointer which points to the front end
o R is a pointer which points to the rear end
o Y is the element to be inserted.
1) [Reset rear pointer?]
If R = N then
R 1
Else
RR + 1
2) [Overflow?]
if F= R then
Write (“queue overflow”)
Return
3) [Insert element]
Q[R]Y
4) [Is front pointer properly set?]
If F = 0 then
F1
Return
(2) Algorithm to delete element from circular queue.
PROCEDURE CQDELETE (Q, F, R,N)
o This function deletes an element from circular queue
o The Queue is represented by vector Q which contains N elements.
o F is a pointer which points to the front end
o R is a pointer which points to the rear end
o Y is temporary variable.
1) [Underflow]
If F = 0 then
Write (Underflow“)
2) [Delete element]
YQ[F]
3) [Queue empty?}
f F = R then
FßRß0
Return(Y)
4) [Increment front pointer}
If F = N then
F1
Else
FF+1
Return (Y)
 Dequeue:
Dequeue is a linier list in which insertion and deletion operation are performed at
either end of the queue.
Dequeue is also known double ended Queue…
Dequeue is shown below:
Operation on Dequeue
(1) Insert an element in to Dequeue
(2) Delete an element from Dequeue
 There are two types of Dequeue:
o Input restricted Dequeue: in input restricted Dequeue insertion operation is
performed at only one end of the queue.
o Output restricted Dequeue: in output restricted Dequeue deletion operation is
performed at only one end of the queue.
1.Insert operation in Dequeue
qinsert_beg(q,val)
1. If ( q  Rear = Max-1 AND q  FRONT=0]
Print “overflow Queue is full” and goto step 4
End If
2. q Front=-1
set q  Front=q  Rear=0
Set qDqueue [q  Front]= val
End If
3. If qRear != MAX=-1
Set num_item=qRear-qFRONT +1
Set i=qRear+1
set j=1
while j<=num_item
Set q  Dque[i]=q  Dque[i-1]
Set i=i-1
Set j=j+1
End While
Set qDque[i]=val
Set qFront=i
Set qRear =qRear +1
Else
Set qFront=qFront-1
Set qDque[qFront]=val
End if
4. End
2.Insert operation At the end of queue
Procedure qinsert_end(q,val)
1. If (qRear =Max-1 And qFront =0)
print “overflow” goto step4
End If
2. If qFront=-1
set q  Front=q  Rear=0
Set qDqueue [q  Front]= val and goto step4
End If
3. If q Rear = MAX-1
Set i=q  Front-1
While i< q  Rear
Set q Dque[i] =qDque[i+1]
Set i= i+1
End while
Set q  Dque[qRear]=val
Set q  Front=qFront-1
Else
Set q  Rear=qRear+1
Set q  Dque[qRear]=val
End IF
4. End
3.Delete operation in the beginning position
Procedure Qdelete_beg(q)
1. If q  Front = -1
Print “Underflow”
Return 0 and go to step 5
End If
2. Set del_val=q  Dque[qFront]
3.. If q  Front =q  Rear
Set q  front = q  Rear = -1
Else
Set qFront =q  front +1
End if
4. Return del_val
5. End
4.Delete operation At end of queue
Procedure delete_end(q)
1. If q  Front = -1
Print “Underflow”
Return 0 and go to step 5
End if
2. Set q del_val=q  Dque[qrear]
3. q  front = q  Rear
Set qfront = q Rear -1
Else
set q Rear = qrear-1
If qrear = -1
set qfront = -1
End if
End if
4. Return del_val
5.End
 Priority Queue:
A queue in which we are able to insert items or remove items from any position
based on some priority is known as priority queue.
R1 R2 …… Ri-1 O1 O2 ……. Oj-1 B1 B2 …… Bk-1
1 2 …… 1 2 2 …….. 2 3 3 …… 3
:
o Figure represents a priority queue of jobs waiting to use a computer
o Priorities of 1, 2, 3 have been attached to jobs of real time, on-line and batch
respectively.
o Figure shows how the single priority queue can be visualized as three separate
queues.
o When elements are inserted, they are always added at the end of one of the
queues as determined by the priorities
o Elements in the second queue are deleted only when the first queue is empty.
o Elements in the third queue are deleted only when the first and second queue are
empty.
 Operation on Priority Queue
1) Insert operation in priority Queue
2) Delete operation in priority Queue
1.Insert operation into priority Queue
Procedure Qinsert (q,val,prno) //prno is the priority of val
1). (qRear[prno]=MAX-1 AND qFront[prno]=0) OR
(qRear[prno]+1=qFront[prno]=0)
Print(“overflow queue”) and goto step-5
End If
2). If qRear[prno-1]=Max-1
set qRear[prno-1]= 0
Else
Set qRear[prno-1]=qRear[prno-1]+1
End if
3). Set qCqueue[prno-1] [qRear[prno-1]] =val.
4). If qFront[prno-1]= -1
Set qFront[prno-1] = 0
End if
5). End
2.delete operation on priority Queue
Procedure Qdelete(q)
1). Set flag=0,i=0
2). while I =MAX-1
If NOT(q  Front[prno])= -1
Set flag=1
Set del_val=q  Cqueue[1][q  Front[i]]
If qFront[ i ]=qRear[i]
Set q  Front[i] = qRear[i]=-1
Else If q  Rear[prno-1]=Max-1
Set q  Rear[prno-1]= 0
Else
Set q  Rear[prno-1]=q  Rear[prno-1]+1
End if
End if
Break //jump out from while loop
End if
Set i= i+1
End While
3). If FLAG=0
print(“underflow Queue”)
Return 0 and go to step 4
Else
Return Del_val
End IF
4). End
Queue

More Related Content

What's hot

Circular queue
Circular queueCircular queue
Team 6
Team 6Team 6
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
Vineeta Garg
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
Farhanum Aziera
 
QUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING CQUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING C
Meghaj Mallick
 
Queue
QueueQueue
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
Mandeep Singh
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
Dabbal Singh Mahara
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
Rajendran
 
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
 
Stacks fundamentals
Stacks fundamentalsStacks fundamentals
Stacks fundamentals
greatqadirgee4u
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Lovely Professional University
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Queue
QueueQueue
Queue
Raj Sarode
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
Tareq Hasan
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
Queues presentation
Queues presentationQueues presentation
Queues presentation
Toseef Hasan
 
Queue
QueueQueue

What's hot (20)

Circular queue
Circular queueCircular queue
Circular queue
 
Team 6
Team 6Team 6
Team 6
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
QUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING CQUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING C
 
Queue
QueueQueue
Queue
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Stacks fundamentals
Stacks fundamentalsStacks fundamentals
Stacks fundamentals
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Queue
QueueQueue
Queue
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Queue
QueueQueue
Queue
 

Similar to Queue

Queue
QueueQueue
05 queues
05 queues05 queues
05 queues
Rajan Gautam
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
Tribhuvan University
 
QUEUES
QUEUESQUEUES
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
SherinRappai
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
maneesh boddu
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
MeghaKulkarni27
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
Soumen Santra
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
singhprpg
 
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
 
sorting1.pptx
sorting1.pptxsorting1.pptx
sorting1.pptx
AJAYVISHALRP
 
Queue
QueueQueue
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.ppt
Queues.pptQueues.ppt
Queues.ppt
ArmanKhan382533
 
@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
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
MattFlordeliza1
 
Queue
QueueQueue

Similar to Queue (20)

Queue
QueueQueue
Queue
 
05 queues
05 queues05 queues
05 queues
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
QUEUES
QUEUESQUEUES
QUEUES
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
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)
 
sorting1.pptx
sorting1.pptxsorting1.pptx
sorting1.pptx
 
Queue
QueueQueue
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
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
 
Queue
QueueQueue
Queue
 

More from Bhavesh Parmar

Inerrupt
InerruptInerrupt
Inerrupt
Bhavesh Parmar
 
Mpeg7
Mpeg7Mpeg7
Master page
Master pageMaster page
Master page
Bhavesh Parmar
 
Training and placement reportmsword
Training and placement reportmswordTraining and placement reportmsword
Training and placement reportmsword
Bhavesh Parmar
 
acknowledgement
acknowledgementacknowledgement
acknowledgement
Bhavesh Parmar
 
index of project
index of projectindex of project
index of project
Bhavesh Parmar
 
Training and placement
Training and placementTraining and placement
Training and placement
Bhavesh Parmar
 
4 index
4 index4 index
3 page acknowledgement1
3 page acknowledgement13 page acknowledgement1
3 page acknowledgement1
Bhavesh Parmar
 
Training and placement ppt
Training and placement pptTraining and placement ppt
Training and placement ppt
Bhavesh Parmar
 

More from Bhavesh Parmar (10)

Inerrupt
InerruptInerrupt
Inerrupt
 
Mpeg7
Mpeg7Mpeg7
Mpeg7
 
Master page
Master pageMaster page
Master page
 
Training and placement reportmsword
Training and placement reportmswordTraining and placement reportmsword
Training and placement reportmsword
 
acknowledgement
acknowledgementacknowledgement
acknowledgement
 
index of project
index of projectindex of project
index of project
 
Training and placement
Training and placementTraining and placement
Training and placement
 
4 index
4 index4 index
4 index
 
3 page acknowledgement1
3 page acknowledgement13 page acknowledgement1
3 page acknowledgement1
 
Training and placement ppt
Training and placement pptTraining and placement ppt
Training and placement ppt
 

Recently uploaded

My Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdfMy Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdf
Geoffrey Wardle. MSc. MSc. Snr.MAIAA
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
kamka4105
 
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
dulbh kashyap
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
Kamal Acharya
 
Technological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdfTechnological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdf
tanujaharish2
 
BBOC407 Module 1.pptx Biology for Engineers
BBOC407  Module 1.pptx Biology for EngineersBBOC407  Module 1.pptx Biology for Engineers
BBOC407 Module 1.pptx Biology for Engineers
sathishkumars808912
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
EMERSON EDUARDO RODRIGUES
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
ShurooqTaib
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Balvir Singh
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
CSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdfCSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdf
Ismail Sultan
 
Microsoft Azure AD architecture and features
Microsoft Azure AD architecture and featuresMicrosoft Azure AD architecture and features
Microsoft Azure AD architecture and features
ssuser381403
 
Kandivali Call Girls ☑ +91-9967584737 ☑ Available Hot Girls Aunty Book Now
Kandivali Call Girls ☑ +91-9967584737 ☑ Available Hot Girls Aunty Book NowKandivali Call Girls ☑ +91-9967584737 ☑ Available Hot Girls Aunty Book Now
Kandivali Call Girls ☑ +91-9967584737 ☑ Available Hot Girls Aunty Book Now
SONALI Batra $A12
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
ShivangMishra54
 
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
IJCNCJournal
 
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Tsuyoshi Horigome
 
SPICE PARK JUL2024 ( 6,866 SPICE Models )
SPICE PARK JUL2024 ( 6,866 SPICE Models )SPICE PARK JUL2024 ( 6,866 SPICE Models )
SPICE PARK JUL2024 ( 6,866 SPICE Models )
Tsuyoshi Horigome
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
sonamrawat5631
 
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC ConduitThe Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
Guangdong Ctube Industry Co., Ltd.
 
Lateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptxLateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptx
DebendraDevKhanal1
 

Recently uploaded (20)

My Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdfMy Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdf
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
 
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
 
Technological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdfTechnological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdf
 
BBOC407 Module 1.pptx Biology for Engineers
BBOC407  Module 1.pptx Biology for EngineersBBOC407  Module 1.pptx Biology for Engineers
BBOC407 Module 1.pptx Biology for Engineers
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
 
CSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdfCSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdf
 
Microsoft Azure AD architecture and features
Microsoft Azure AD architecture and featuresMicrosoft Azure AD architecture and features
Microsoft Azure AD architecture and features
 
Kandivali Call Girls ☑ +91-9967584737 ☑ Available Hot Girls Aunty Book Now
Kandivali Call Girls ☑ +91-9967584737 ☑ Available Hot Girls Aunty Book NowKandivali Call Girls ☑ +91-9967584737 ☑ Available Hot Girls Aunty Book Now
Kandivali Call Girls ☑ +91-9967584737 ☑ Available Hot Girls Aunty Book Now
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
 
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
 
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
 
SPICE PARK JUL2024 ( 6,866 SPICE Models )
SPICE PARK JUL2024 ( 6,866 SPICE Models )SPICE PARK JUL2024 ( 6,866 SPICE Models )
SPICE PARK JUL2024 ( 6,866 SPICE Models )
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
 
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC ConduitThe Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
 
Lateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptxLateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptx
 

Queue

  • 2.  Queue A queue is a linear Data structure in which insertion is performed at one end called rear and deletion is performed at another end of the list is called front. Type of Queue: 1.Simple Queue 2.Circularqueue 3.Dequeue 4.Priority Queue  Representation of Queue  The information in such a list is proceeds in the same order as it was received.  Since insertion is performed at one end and deletion is performed at another end the element which is inserted first is first to delete. So it is also known as First in First out (FIFO) or First Come First Serve (FCFS) data structure.
  • 3.  Examples of Queue A raw of students at registration counter. Line of cars waiting to proceeds in some direction at traffic signal.  Application of Queue o A queue is the natural data structure for a system to serve its incoming requests. Most of the process scheduling or disk scheduling algorithms in operating systems use queues. o Computer hardware like a processor or a network card also maintain buffers in the form of queues for incoming resource requests. A stack-like data structure causes starvation of the first requests, and is not applicable in such cases. o A mailbox or port to save messages to communicate between two users or processes in a system is essentially a queue-like structure. o Queue is widely used in Simulation.
  • 4.  Operation on Simple Queue: (1) Insert an element in to queue (2) Delete an element from queue 1. Algorithm to insert an element in queue PROCEDURE QINSERT (Q, F, R, N, Y) • This function insert an element into the queue • The Queue is represented by vector Q which contains N elements. • F is a pointer which points to the front end • R is a pointer which points to the rear end • Y is the element to be inserted. 1) [Overflow?] If R≥N then Write (‘Overflow’)
  • 5. 2) [Increment rear pointer ] RR+1 3) [Insert element] Q[R]Y 4 ) [Is front pointer properly set?] If F=0 then F1 Return
  • 6. 2. Algorithm to delete an element from the queue PROCEDURE QDELETE (Q, F, R) • This function delete an element into the queue • The Queue is represented by vector Q which contains N elements. • F is a pointer which points to the front end • R is a pointer which points to the rear end • Y is the element to be inserted. 1) [Overflow?] If R≥N then Write (‘Overflow’) 2) [Delete element] YQ [F] 3) [Queue empty?] If F =R Then F0 R0 Else FF+1 4) [Return element] Return (y)
  • 7.  For example consider following operations: o As shown in figure (a), we insert three elements 5, 10, 15 in simple queue. o After that we delete 5 and 10 as shown in figure (b). Now even we have a free memory space we cannot use that memory space. So simple queue results in wastage of memory space. o This problem can be solved by using circular queue.
  • 8.  Circular Queue: A circular queue is a queue in which elements are added and removed in a circular fashion / manner, is called Circular Queue. :  Represent of circular Queue:
  • 9. o As shown in figure (a), we insert eight elements 10, 20,30,40,50,60,70,80 in simple queue. After that we delete 10, 20 and 30 as shown in figure (b). Now we have a free memory space in circular queue and we can use that memory space by incrementing rear pointer by 1(rear=0).  Operations on Circular Queue (1) Insert new element in to circular queue (2) Delete element from circular queue
  • 10. (1) Algorithm to insert element in circular queue PROCEDURE CQINSERT (Q, F, R, N, Y) o This function inserts an element in to circular queue. o The Queue is represented by vector Q which contains N elements. o F is a pointer which points to the front end o R is a pointer which points to the rear end o Y is the element to be inserted. 1) [Reset rear pointer?] If R = N then R 1 Else RR + 1 2) [Overflow?] if F= R then Write (“queue overflow”) Return 3) [Insert element] Q[R]Y
  • 11. 4) [Is front pointer properly set?] If F = 0 then F1 Return
  • 12. (2) Algorithm to delete element from circular queue. PROCEDURE CQDELETE (Q, F, R,N) o This function deletes an element from circular queue o The Queue is represented by vector Q which contains N elements. o F is a pointer which points to the front end o R is a pointer which points to the rear end o Y is temporary variable. 1) [Underflow] If F = 0 then Write (Underflow“) 2) [Delete element] YQ[F] 3) [Queue empty?} f F = R then FßRß0 Return(Y)
  • 13. 4) [Increment front pointer} If F = N then F1 Else FF+1 Return (Y)
  • 14.  Dequeue: Dequeue is a linier list in which insertion and deletion operation are performed at either end of the queue. Dequeue is also known double ended Queue… Dequeue is shown below:
  • 15. Operation on Dequeue (1) Insert an element in to Dequeue (2) Delete an element from Dequeue  There are two types of Dequeue: o Input restricted Dequeue: in input restricted Dequeue insertion operation is performed at only one end of the queue. o Output restricted Dequeue: in output restricted Dequeue deletion operation is performed at only one end of the queue.
  • 16. 1.Insert operation in Dequeue qinsert_beg(q,val) 1. If ( q  Rear = Max-1 AND q  FRONT=0] Print “overflow Queue is full” and goto step 4 End If 2. q Front=-1 set q  Front=q  Rear=0 Set qDqueue [q  Front]= val End If 3. If qRear != MAX=-1 Set num_item=qRear-qFRONT +1 Set i=qRear+1 set j=1 while j<=num_item Set q  Dque[i]=q  Dque[i-1] Set i=i-1
  • 17. Set j=j+1 End While Set qDque[i]=val Set qFront=i Set qRear =qRear +1 Else Set qFront=qFront-1 Set qDque[qFront]=val End if 4. End 2.Insert operation At the end of queue Procedure qinsert_end(q,val) 1. If (qRear =Max-1 And qFront =0) print “overflow” goto step4 End If
  • 18. 2. If qFront=-1 set q  Front=q  Rear=0 Set qDqueue [q  Front]= val and goto step4 End If 3. If q Rear = MAX-1 Set i=q  Front-1 While i< q  Rear Set q Dque[i] =qDque[i+1] Set i= i+1 End while Set q  Dque[qRear]=val Set q  Front=qFront-1 Else Set q  Rear=qRear+1 Set q  Dque[qRear]=val End IF 4. End
  • 19. 3.Delete operation in the beginning position Procedure Qdelete_beg(q) 1. If q  Front = -1 Print “Underflow” Return 0 and go to step 5 End If 2. Set del_val=q  Dque[qFront] 3.. If q  Front =q  Rear Set q  front = q  Rear = -1 Else Set qFront =q  front +1 End if 4. Return del_val 5. End
  • 20. 4.Delete operation At end of queue Procedure delete_end(q) 1. If q  Front = -1 Print “Underflow” Return 0 and go to step 5 End if 2. Set q del_val=q  Dque[qrear] 3. q  front = q  Rear Set qfront = q Rear -1 Else set q Rear = qrear-1 If qrear = -1 set qfront = -1 End if End if 4. Return del_val 5.End
  • 21.  Priority Queue: A queue in which we are able to insert items or remove items from any position based on some priority is known as priority queue. R1 R2 …… Ri-1 O1 O2 ……. Oj-1 B1 B2 …… Bk-1 1 2 …… 1 2 2 …….. 2 3 3 …… 3 : o Figure represents a priority queue of jobs waiting to use a computer o Priorities of 1, 2, 3 have been attached to jobs of real time, on-line and batch respectively. o Figure shows how the single priority queue can be visualized as three separate queues.
  • 22. o When elements are inserted, they are always added at the end of one of the queues as determined by the priorities o Elements in the second queue are deleted only when the first queue is empty. o Elements in the third queue are deleted only when the first and second queue are empty.  Operation on Priority Queue 1) Insert operation in priority Queue 2) Delete operation in priority Queue
  • 23. 1.Insert operation into priority Queue Procedure Qinsert (q,val,prno) //prno is the priority of val 1). (qRear[prno]=MAX-1 AND qFront[prno]=0) OR (qRear[prno]+1=qFront[prno]=0) Print(“overflow queue”) and goto step-5 End If 2). If qRear[prno-1]=Max-1 set qRear[prno-1]= 0 Else Set qRear[prno-1]=qRear[prno-1]+1 End if 3). Set qCqueue[prno-1] [qRear[prno-1]] =val. 4). If qFront[prno-1]= -1 Set qFront[prno-1] = 0 End if 5). End
  • 24. 2.delete operation on priority Queue Procedure Qdelete(q) 1). Set flag=0,i=0 2). while I =MAX-1 If NOT(q  Front[prno])= -1 Set flag=1 Set del_val=q  Cqueue[1][q  Front[i]] If qFront[ i ]=qRear[i] Set q  Front[i] = qRear[i]=-1 Else If q  Rear[prno-1]=Max-1 Set q  Rear[prno-1]= 0 Else Set q  Rear[prno-1]=q  Rear[prno-1]+1 End if End if Break //jump out from while loop End if Set i= i+1 End While
  • 25. 3). If FLAG=0 print(“underflow Queue”) Return 0 and go to step 4 Else Return Del_val End IF 4). End

Editor's Notes

  1. qRear[]
  翻译: