SlideShare una empresa de Scribd logo
1 de 14
Queue
1
Queue (Linear Queue)
• It is a linear data structure consisting of list of items.
• In queue, data elements are added at one end, called the rear and removed from another
end, called the front of the list.
• Two basic operations are associated with queue:
1. “Insert” operation is used to insert an element into a queue.
2. “Delete” operation is used to delete an element from a queue.
● FIFO list
• Example:
Queue: AAA, BBB, CCC, DDD, EEE
AAA BBB CCC DDD EEE
Rear
1 2 3 4 5 6 7
Front
EEE
DDD
CCC
BBB
AAA
Rear
Front
2
7
1
2
3
4
5
6
3
Algorithms for Insert and Delete Operations in Linear Queue
For Insert Operation
Insert-Queue(Queue, Rear, Front, N, Item)
Here, Queue is the place where to store data. Rear represents the location in which the
data element is to be inserted and Front represents the location from which the data
element is to be removed. Here N is the maximum size of the Queue and finally, Item is
the new item to be added.
1. If Rear = N then Print: Overflow and Return. /*…Queue already filled..*/
2. Set Rear := Rear +1
3. Set Queue[Rear] := Item
4. Return.
4
For Delete Operation
Delete-Queue(Queue, Front, Rear, Item)
Here, Queue is the place where data are stored. Rear represents the location in which the
data element is to be inserted and Front represents the location from which the data
element is to be removed. Front element is assigned to Item.
1. If Front = N+1 then Print: Underflow and Return. /*…Queue Empty
2. Set Item := Queue[Front]
3. Set Front := Front + 1
4. Return.
5
Example: Consider the following queue (linear queue).
Rear = 4 and Front = 1 and N = 7
10 50 30 40
(1) Insert 20. Now Rear = 5 and Front = 1
1 2 3 4 5 6 7
10 50 30 40 20
1 2 3 4 5 6 7
(2) Delete Front Element. Now Rear = 5 and Front = 2
50 30 40 20
1 2 3 4 5 6 7
(3) Delete Front Element. Now Rear = 5 and Front = 3
30 40 20
1 2 3 4 5 6 7
(4) Insert 60. Now Rear = 6 and Front = 3
30 40 20 60
1 2 3 4 5 6 7
6
Drawback of Linear Queue
• Once the queue is full, even though few elements from the front are deleted and
some occupied space is relieved, it is not possible to add anymore new elements,
as the rear has already reached the Queue’s rear most position.
Circular Queue
• This queue is not linear but circular.
• Its structure can be like the following figure:
Figure: Circular Queue having
Rear = 5 and Front = 0
• In circular queue, once the Queue is full the
"First" element of the Queue becomes the
"Rear" most element, if and only if the "Front"
has moved forward. otherwise it will again be
a "Queue overflow" state.
7
Algorithms for Insert and Delete Operations in Circular Queue
For Insert Operation
Insert-Circular-Q(CQueue, Rear, Front, N, Item)
Here, CQueue is a circular queue where to store data. Rear represents the
location in which the data element is to be inserted and Front represents the
location from which the data element is to be removed. Here N is the maximum
size of CQueue and finally, Item is the new item to be added. Initailly Rear = 0 and
Front = 0.
1. If Front = 0 and Rear = 0 then Set Front := 1 and go to step 4.
2. If Front =1 and Rear = N or Front = Rear + 1
then Print: “Circular Queue Overflow” and Return.
3. If Rear = N then Set Rear := 1 and go to step 5.
4. Set Rear := Rear + 1
5. Set CQueue [Rear] := Item.
6. Return
8
For Delete Operation
Delete-Circular-Q(CQueue, Front, Rear, Item)
Here, CQueue is the place where data are stored. Rear represents the location in
which the data element is to be inserted and Front represents the location from
which the data element is to be removed. Front element is assigned to Item.
Initially, Front = 1.
1. If Front = 0 then
Print: “Circular Queue Underflow” and Return. /*..Delete without Insertion
2. Set Item := CQueue [Front]
3. If Front = N then Set Front = 1 and Return.
4. If Front = Rear then Set Front = 0 and Rear = 0 and Return.
5. Set Front := Front + 1
6. Return.
9
Example: Consider the following circular queue with N = 5.
1. Initially, Rear = 0, Front = 0.
2. Insert 10, Rear = 1, Front = 1.
3. Insert 50, Rear = 2, Front = 1.
4. Insert 20, Rear = 3, Front = 0.
5. Insert 70, Rear = 4, Front = 1.
6. Delete front, Rear = 4, Front = 2.
Rear
Rear
Rear
Rear
Rear
Front
Front
Front
Front
Front
10
7. Insert 100, Rear = 5, Front = 2.
8. Insert 40, Rear = 1, Front = 2.
9. Insert 140, Rear = 1, Front = 2.
As Front = Rear + 1, so Queue overflow.
10. Delete front, Rear = 1, Front = 3.
Front
Rear
FrontRear
Rear
Rear
Front
Front
11. Delete front, Rear = 1, Front = 4.
12. Delete front, Rear = 1, Front = 5.
Rear
Rear
Front
Front
Priority Queue
11
12
Priority Queue
• A priority queue is a collection of elements such that each element has been assigned a
priority.
● A priority queue supports inserting new priorities, and removing the highest priority.
● Two elements with the same priority are processed according to the order in which they
were added to the queue.
Representation of Priority Queue
• Each node in the list has three fields: an information field INFO, a priority number PRN
and a link number Link.
● A node X precedes a node Y in the list when X has higher priority than Y or both have
the same priority but X was added to the list before Y.
13
Deques
• A deque is a linear list in which data elements can be added or removed at either end but not
in the middle.
• This type of queue is also known as dequeue and double-ended queue.
• There are two types of DEQUE.
Input-Restricted Deque – Allow insertions at only one end of the list but deletions at
both ends of the list.
Output-Restricted Deque - Allow insertions at both ends but deletions at only one end of
the list.
•Example:
801002060
0 1 2 3 4 5 6 7
Figure: Example of a Deque
14
END!!!!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue
QueueQueue
Queue
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
Circular Queue data structure
Circular Queue data structureCircular Queue data structure
Circular Queue data structure
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Sorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesSorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - Notes
 
Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)
 
Array operations
Array operationsArray operations
Array operations
 
Priority queues and heap sorting
Priority queues and heap sortingPriority queues and heap sorting
Priority queues and heap sorting
 
Queue
QueueQueue
Queue
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Queues-handouts
Queues-handoutsQueues-handouts
Queues-handouts
 
Quick sort
Quick sortQuick sort
Quick sort
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 

Similar a Queue

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
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 vertexSadiaSharmin40
 
Detalied information of queue
Detalied information of queueDetalied information of queue
Detalied information of queueSmit Parikh
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queueRai University
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueRai University
 
10994103.ppt
10994103.ppt10994103.ppt
10994103.pptSushmaG48
 
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,queueRai University
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
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
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementationshaik faroq
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queueskalyanineve
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptxNuraMohamed9
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptxsinghprpg
 
Queue data structures and operation on data structures
Queue data structures and operation on data structuresQueue data structures and operation on data structures
Queue data structures and operation on data structuresmuskans14
 

Similar a Queue (20)

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular 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
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Detalied information of queue
Detalied information of queueDetalied information of queue
Detalied information of queue
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
10994103.ppt
10994103.ppt10994103.ppt
10994103.ppt
 
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
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
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)
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
Queue data structures and operation on data structures
Queue data structures and operation on data structuresQueue data structures and operation on data structures
Queue data structures and operation on data structures
 

Más de Himadri Sen Gupta (9)

Report of industrial training
Report of industrial trainingReport of industrial training
Report of industrial training
 
Binary search trees (1)
Binary search trees (1)Binary search trees (1)
Binary search trees (1)
 
Graphs
GraphsGraphs
Graphs
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
14 recursion
14 recursion14 recursion
14 recursion
 
Tree
TreeTree
Tree
 
Heap
HeapHeap
Heap
 
Linked lists
Linked listsLinked lists
Linked lists
 
1311004
13110041311004
1311004
 

Último

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 

Último (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 

Queue

  • 2. Queue (Linear Queue) • It is a linear data structure consisting of list of items. • In queue, data elements are added at one end, called the rear and removed from another end, called the front of the list. • Two basic operations are associated with queue: 1. “Insert” operation is used to insert an element into a queue. 2. “Delete” operation is used to delete an element from a queue. ● FIFO list • Example: Queue: AAA, BBB, CCC, DDD, EEE AAA BBB CCC DDD EEE Rear 1 2 3 4 5 6 7 Front EEE DDD CCC BBB AAA Rear Front 2 7 1 2 3 4 5 6
  • 3. 3 Algorithms for Insert and Delete Operations in Linear Queue For Insert Operation Insert-Queue(Queue, Rear, Front, N, Item) Here, Queue is the place where to store data. Rear represents the location in which the data element is to be inserted and Front represents the location from which the data element is to be removed. Here N is the maximum size of the Queue and finally, Item is the new item to be added. 1. If Rear = N then Print: Overflow and Return. /*…Queue already filled..*/ 2. Set Rear := Rear +1 3. Set Queue[Rear] := Item 4. Return.
  • 4. 4 For Delete Operation Delete-Queue(Queue, Front, Rear, Item) Here, Queue is the place where data are stored. Rear represents the location in which the data element is to be inserted and Front represents the location from which the data element is to be removed. Front element is assigned to Item. 1. If Front = N+1 then Print: Underflow and Return. /*…Queue Empty 2. Set Item := Queue[Front] 3. Set Front := Front + 1 4. Return.
  • 5. 5 Example: Consider the following queue (linear queue). Rear = 4 and Front = 1 and N = 7 10 50 30 40 (1) Insert 20. Now Rear = 5 and Front = 1 1 2 3 4 5 6 7 10 50 30 40 20 1 2 3 4 5 6 7 (2) Delete Front Element. Now Rear = 5 and Front = 2 50 30 40 20 1 2 3 4 5 6 7 (3) Delete Front Element. Now Rear = 5 and Front = 3 30 40 20 1 2 3 4 5 6 7 (4) Insert 60. Now Rear = 6 and Front = 3 30 40 20 60 1 2 3 4 5 6 7
  • 6. 6 Drawback of Linear Queue • Once the queue is full, even though few elements from the front are deleted and some occupied space is relieved, it is not possible to add anymore new elements, as the rear has already reached the Queue’s rear most position. Circular Queue • This queue is not linear but circular. • Its structure can be like the following figure: Figure: Circular Queue having Rear = 5 and Front = 0 • In circular queue, once the Queue is full the "First" element of the Queue becomes the "Rear" most element, if and only if the "Front" has moved forward. otherwise it will again be a "Queue overflow" state.
  • 7. 7 Algorithms for Insert and Delete Operations in Circular Queue For Insert Operation Insert-Circular-Q(CQueue, Rear, Front, N, Item) Here, CQueue is a circular queue where to store data. Rear represents the location in which the data element is to be inserted and Front represents the location from which the data element is to be removed. Here N is the maximum size of CQueue and finally, Item is the new item to be added. Initailly Rear = 0 and Front = 0. 1. If Front = 0 and Rear = 0 then Set Front := 1 and go to step 4. 2. If Front =1 and Rear = N or Front = Rear + 1 then Print: “Circular Queue Overflow” and Return. 3. If Rear = N then Set Rear := 1 and go to step 5. 4. Set Rear := Rear + 1 5. Set CQueue [Rear] := Item. 6. Return
  • 8. 8 For Delete Operation Delete-Circular-Q(CQueue, Front, Rear, Item) Here, CQueue is the place where data are stored. Rear represents the location in which the data element is to be inserted and Front represents the location from which the data element is to be removed. Front element is assigned to Item. Initially, Front = 1. 1. If Front = 0 then Print: “Circular Queue Underflow” and Return. /*..Delete without Insertion 2. Set Item := CQueue [Front] 3. If Front = N then Set Front = 1 and Return. 4. If Front = Rear then Set Front = 0 and Rear = 0 and Return. 5. Set Front := Front + 1 6. Return.
  • 9. 9 Example: Consider the following circular queue with N = 5. 1. Initially, Rear = 0, Front = 0. 2. Insert 10, Rear = 1, Front = 1. 3. Insert 50, Rear = 2, Front = 1. 4. Insert 20, Rear = 3, Front = 0. 5. Insert 70, Rear = 4, Front = 1. 6. Delete front, Rear = 4, Front = 2. Rear Rear Rear Rear Rear Front Front Front Front Front
  • 10. 10 7. Insert 100, Rear = 5, Front = 2. 8. Insert 40, Rear = 1, Front = 2. 9. Insert 140, Rear = 1, Front = 2. As Front = Rear + 1, so Queue overflow. 10. Delete front, Rear = 1, Front = 3. Front Rear FrontRear Rear Rear Front Front 11. Delete front, Rear = 1, Front = 4. 12. Delete front, Rear = 1, Front = 5. Rear Rear Front Front
  • 12. 12 Priority Queue • A priority queue is a collection of elements such that each element has been assigned a priority. ● A priority queue supports inserting new priorities, and removing the highest priority. ● Two elements with the same priority are processed according to the order in which they were added to the queue. Representation of Priority Queue • Each node in the list has three fields: an information field INFO, a priority number PRN and a link number Link. ● A node X precedes a node Y in the list when X has higher priority than Y or both have the same priority but X was added to the list before Y.
  • 13. 13 Deques • A deque is a linear list in which data elements can be added or removed at either end but not in the middle. • This type of queue is also known as dequeue and double-ended queue. • There are two types of DEQUE. Input-Restricted Deque – Allow insertions at only one end of the list but deletions at both ends of the list. Output-Restricted Deque - Allow insertions at both ends but deletions at only one end of the list. •Example: 801002060 0 1 2 3 4 5 6 7 Figure: Example of a Deque