SlideShare uma empresa Scribd logo
1 de 13
Queues
By
Nilesh Dalvi
Lecturer, Patkar-Varde College.Lecturer, Patkar-Varde College.
http://www.slideshare.net/nileshdalvi01
Java and DataJava and Data
StructuresStructures
Queue
• A queue is a linear list of element in which insertion
can be done at one end which is known as REAR and
deletion can be done which is known as FRONT.
• Operation:
1. Insertion : add a new element in queue
2. Deletion: Removing an element in queue
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Queue
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Array representation of queues:
• Size of the queue is N = 5;
a) Initially empty :
b) A, B, C inserted :
c) A is deleted:
d) D and then E inserted:
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Front: 0
Rear: 0
Front: 1
Rear: 3
Front: 2
Rear: 3
Front: 2
Rear: 5
A B C
B C
B C D E
Operations with Queue:
1. enqueue :
– Insertion of the element into the queue
– Insertion always takes place from the rear end.
– Before performing insertion check weather queue is full or
not
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
enQueue:
Description:
– Here QUEUE is an array with N locations.
– FRONT and REAR points to the front and rear of the QUEUE.
– ITEM is the value to be inserted.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm enqueue(QUEUE, N, FRONT, REAR, ITEM)
{
if (REAR = N) Then //Check for overflow
write ("Overflow");
else
if (FRONT and REAR = 0) Then //Check if QUEUE is empty
{
FRONT := 1;
REAR := 1;
}
else
{
REAR := REAR + 1; //Increment REAR by 1
}
QUEUE[REAR] := ITEM;
}
Operations with Queue:
2. dequeue :
– Deletion of the element from the queue
– Deletion always takes place from the front end.
– Before performing deletion check weather queue is empty
or not
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
deQueue:
Description:
– Here QUEUE is an array with N locations.
– FRONT and REAR points to the front and rear of the QUEUE.
– ITEM is the value to be deleted.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm dequeue(QUEUE, N, FRONT, REAR, ITEM)
{
if (FRONT = 0) Then //Check for underflow
write ("Underflow");
else
{
ITEM := QUEUE[FRONT];
if (FRONT = REAR) Then //Check if only one element is left
{
FRONT := 0;
REAR := 0;
}
else
{
FRONT := FRONT + 1; //Increment FRONT by 1
}
}
}
Circular Queue
• Linear Queue:
• Circular Queue:
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Front: 4
Rear: 8
A B C D E
A B
C
D
EF
H
G
F G H
Front: 4
Rear: 8
REAR := (REAR + 1) % SIZE
:= (8 + 1) % 8
:= 1
1 2
3
4
56
7
8
FRONT := (FRONT + 1) % SIZE
:= (4 + 1) % 8
:= 5
encQueue:
Description:
– Here QUEUE is an array with N locations.
– FRONT and REAR points to the front and rear of the QUEUE.
– ITEM is the value to be inserted.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm encqueue(QUEUE, N, FRONT, REAR, ITEM)
{
if (FRONT == (REAR + 1) % N) Then //Check for overflow
write ("Overflow");
else
{
if (FRONT and REAR = 0) Then //Check if QUEUE is empty
{
FRONT := 1;
REAR := 1;
}
else
{
REAR := (REAR + 1) % N; //Increment REAR by 1
}
QUEUE[REAR] := ITEM;
}
}
decQueue:
Description:
– Here QUEUE is an array with N locations.
– FRONT and REAR points to the front and rear of the QUEUE.
– ITEM is the value to be deleted.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm decqueue(QUEUE, N, FRONT, REAR, ITEM)
{
if (FRONT = 0) Then //Check for underflow
write ("Underflow");
else
{
ITEM := QUEUE[FRONT];
if (FRONT = REAR) Then //Check if only one element is left
{
FRONT := 0;
REAR := 0;
}
else
{
FRONT := (FRONT + 1) % N; //Increment FRONT by 1
}
}
}
Applications of Queue:
• Job Scheduling
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Q & A

Mais conteúdo relacionado

Mais procurados

08 class and object
08   class and object08   class and object
08 class and object
dhrubo kayal
 

Mais procurados (14)

1. Overview of Java
1. Overview of Java1. Overview of Java
1. Overview of Java
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
 
List classes
List classesList classes
List classes
 
264finalppt (1)
264finalppt (1)264finalppt (1)
264finalppt (1)
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
Session 15 - Collections - Array List
Session 15 - Collections - Array ListSession 15 - Collections - Array List
Session 15 - Collections - Array List
 
An introduction to java programming
An introduction to java programmingAn introduction to java programming
An introduction to java programming
 
Session 05 - Strings in Java
Session 05 - Strings in JavaSession 05 - Strings in Java
Session 05 - Strings in Java
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
 
Lecture 1 Introduction C++
Lecture 1 Introduction C++Lecture 1 Introduction C++
Lecture 1 Introduction C++
 
08 class and object
08   class and object08   class and object
08 class and object
 
Object Class
Object Class Object Class
Object Class
 
C++ unit-1-part-6
C++ unit-1-part-6C++ unit-1-part-6
C++ unit-1-part-6
 

Destaque

Ch04 Linked List Structure
Ch04 Linked List StructureCh04 Linked List Structure
Ch04 Linked List Structure
leminhvuong
 
取是一種本事捨是一種智慧
取是一種本事捨是一種智慧取是一種本事捨是一種智慧
取是一種本事捨是一種智慧
Jaing Lai
 
Como hacer una pagina en wix
Como hacer una pagina en wixComo hacer una pagina en wix
Como hacer una pagina en wix
wiston98
 

Destaque (18)

7. Multithreading
7. Multithreading7. Multithreading
7. Multithreading
 
Ch04 Linked List Structure
Ch04 Linked List StructureCh04 Linked List Structure
Ch04 Linked List Structure
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception Handling
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Blog diapocitiva ventajas y desventajas
Blog diapocitiva ventajas y desventajasBlog diapocitiva ventajas y desventajas
Blog diapocitiva ventajas y desventajas
 
TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o MalTDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
 
Chinese Cultural Entailment 中国文化蕴涵
Chinese Cultural Entailment  中国文化蕴涵Chinese Cultural Entailment  中国文化蕴涵
Chinese Cultural Entailment 中国文化蕴涵
 
取是一種本事捨是一種智慧
取是一種本事捨是一種智慧取是一種本事捨是一種智慧
取是一種本事捨是一種智慧
 
TDC2016SP - Groovy como você nunca viu
TDC2016SP - Groovy como você nunca viuTDC2016SP - Groovy como você nunca viu
TDC2016SP - Groovy como você nunca viu
 
Actividad de aprendizaje 2 SEGUNDO BLOQUE
Actividad de aprendizaje 2 SEGUNDO BLOQUEActividad de aprendizaje 2 SEGUNDO BLOQUE
Actividad de aprendizaje 2 SEGUNDO BLOQUE
 
Por que sua próxima aplicação web deve ser em Clojure?
Por que sua próxima aplicação web deve ser em Clojure?Por que sua próxima aplicação web deve ser em Clojure?
Por que sua próxima aplicação web deve ser em Clojure?
 
TDC2016SP - Finanças Quantitativas com Python
TDC2016SP - Finanças Quantitativas com PythonTDC2016SP - Finanças Quantitativas com Python
TDC2016SP - Finanças Quantitativas com Python
 
Como hacer una pagina en wix
Como hacer una pagina en wixComo hacer una pagina en wix
Como hacer una pagina en wix
 
TDC2016SP - Desacoplando suas regras de negócio do Rails
TDC2016SP - Desacoplando suas regras de negócio do RailsTDC2016SP - Desacoplando suas regras de negócio do Rails
TDC2016SP - Desacoplando suas regras de negócio do Rails
 
Exposicion final
Exposicion finalExposicion final
Exposicion final
 
TDC2016SP - Flask para Web
TDC2016SP - Flask para WebTDC2016SP - Flask para Web
TDC2016SP - Flask para Web
 
TDC2016SP - Luiza Labs - Migrando .NET p/ Python
TDC2016SP - Luiza Labs - Migrando .NET p/ PythonTDC2016SP - Luiza Labs - Migrando .NET p/ Python
TDC2016SP - Luiza Labs - Migrando .NET p/ Python
 

Semelhante a 13. 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
SadiaSharmin40
 
chapter10-queue-161018120329.pdf
chapter10-queue-161018120329.pdfchapter10-queue-161018120329.pdf
chapter10-queue-161018120329.pdf
ssuserff72e4
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 

Semelhante a 13. Queue (20)

LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
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
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
chapter10-queue-161018120329.pdf
chapter10-queue-161018120329.pdfchapter10-queue-161018120329.pdf
chapter10-queue-161018120329.pdf
 
Queue
QueueQueue
Queue
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
Queues
Queues Queues
Queues
 
Lec3
Lec3Lec3
Lec3
 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2
 
Vectors,squence & list
Vectors,squence & listVectors,squence & list
Vectors,squence & list
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
Lec3
Lec3Lec3
Lec3
 
Tree
TreeTree
Tree
 
Queue
QueueQueue
Queue
 
GDSC MPSTME Shirpur DSA Day 1.pptx
GDSC MPSTME Shirpur DSA Day 1.pptxGDSC MPSTME Shirpur DSA Day 1.pptx
GDSC MPSTME Shirpur DSA Day 1.pptx
 
Leniar datastructure
Leniar datastructureLeniar datastructure
Leniar datastructure
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
Data structure
Data  structureData  structure
Data structure
 
Searching/Sorting algorithms
Searching/Sorting algorithmsSearching/Sorting algorithms
Searching/Sorting algorithms
 

Mais de Nilesh Dalvi (11)

2. Basics of Java
2. Basics of Java2. Basics of Java
2. Basics of Java
 
Templates
TemplatesTemplates
Templates
 
File handling
File handlingFile handling
File handling
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Strings
StringsStrings
Strings
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 

Último

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 

Último (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

13. Queue

  • 1. Queues By Nilesh Dalvi Lecturer, Patkar-Varde College.Lecturer, Patkar-Varde College. http://www.slideshare.net/nileshdalvi01 Java and DataJava and Data StructuresStructures
  • 2. Queue • A queue is a linear list of element in which insertion can be done at one end which is known as REAR and deletion can be done which is known as FRONT. • Operation: 1. Insertion : add a new element in queue 2. Deletion: Removing an element in queue Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 4. Array representation of queues: • Size of the queue is N = 5; a) Initially empty : b) A, B, C inserted : c) A is deleted: d) D and then E inserted: Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Front: 0 Rear: 0 Front: 1 Rear: 3 Front: 2 Rear: 3 Front: 2 Rear: 5 A B C B C B C D E
  • 5. Operations with Queue: 1. enqueue : – Insertion of the element into the queue – Insertion always takes place from the rear end. – Before performing insertion check weather queue is full or not Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 6. enQueue: Description: – Here QUEUE is an array with N locations. – FRONT and REAR points to the front and rear of the QUEUE. – ITEM is the value to be inserted. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm enqueue(QUEUE, N, FRONT, REAR, ITEM) { if (REAR = N) Then //Check for overflow write ("Overflow"); else if (FRONT and REAR = 0) Then //Check if QUEUE is empty { FRONT := 1; REAR := 1; } else { REAR := REAR + 1; //Increment REAR by 1 } QUEUE[REAR] := ITEM; }
  • 7. Operations with Queue: 2. dequeue : – Deletion of the element from the queue – Deletion always takes place from the front end. – Before performing deletion check weather queue is empty or not Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 8. deQueue: Description: – Here QUEUE is an array with N locations. – FRONT and REAR points to the front and rear of the QUEUE. – ITEM is the value to be deleted. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm dequeue(QUEUE, N, FRONT, REAR, ITEM) { if (FRONT = 0) Then //Check for underflow write ("Underflow"); else { ITEM := QUEUE[FRONT]; if (FRONT = REAR) Then //Check if only one element is left { FRONT := 0; REAR := 0; } else { FRONT := FRONT + 1; //Increment FRONT by 1 } } }
  • 9. Circular Queue • Linear Queue: • Circular Queue: Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Front: 4 Rear: 8 A B C D E A B C D EF H G F G H Front: 4 Rear: 8 REAR := (REAR + 1) % SIZE := (8 + 1) % 8 := 1 1 2 3 4 56 7 8 FRONT := (FRONT + 1) % SIZE := (4 + 1) % 8 := 5
  • 10. encQueue: Description: – Here QUEUE is an array with N locations. – FRONT and REAR points to the front and rear of the QUEUE. – ITEM is the value to be inserted. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm encqueue(QUEUE, N, FRONT, REAR, ITEM) { if (FRONT == (REAR + 1) % N) Then //Check for overflow write ("Overflow"); else { if (FRONT and REAR = 0) Then //Check if QUEUE is empty { FRONT := 1; REAR := 1; } else { REAR := (REAR + 1) % N; //Increment REAR by 1 } QUEUE[REAR] := ITEM; } }
  • 11. decQueue: Description: – Here QUEUE is an array with N locations. – FRONT and REAR points to the front and rear of the QUEUE. – ITEM is the value to be deleted. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm decqueue(QUEUE, N, FRONT, REAR, ITEM) { if (FRONT = 0) Then //Check for underflow write ("Underflow"); else { ITEM := QUEUE[FRONT]; if (FRONT = REAR) Then //Check if only one element is left { FRONT := 0; REAR := 0; } else { FRONT := (FRONT + 1) % N; //Increment FRONT by 1 } } }
  • 12. Applications of Queue: • Job Scheduling Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 13. Q & A