Escolar Documentos
Profissional Documentos
Cultura Documentos
@ McGraw-Hill Education
Copyrighted Material -Additional resource material supplied with the book Data Structures and Algorithms : Concepts, Techniques and Applications authored by G.A.V. Pai and published by
Tata McGraw Hill. This resource material is for Instructor's use only.
Queues
(Chapter 5)
PROPRIETARY MATERIAL. 2008 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.
Outline of Chapter
1. Introduction
- Definition
- Operations on queues
2. Linear Queue implementation
- Using array as a queue
- Implementation of insert and delete operations on a queue
- Limitations of linear queues
3. Circular queues
- Operations on circular queues
- Implementation of insert and delete operations on a circular queue
5. Applications
6. ADT for queues
1. INTRODUCTION
a
Front
c
Rear
A queue
Rear
Front
Rear
(a) A queue Q
a
b
d
Front
Rear
(b) Insert d into Q
b
Front
Rear
(c) Delete from Q
Operations on Queue?
The queue data
structure supports
two operations viz.,
Insertion (or addition
or enqueue) of
elements to a queue
Deletion (or removal
or dequeue) of
elements from a
queue
Front
Rear
(a) A queue Q
a
b
d
Front
Rear
(b) Insert d into Q
b
Front
Rear
(c) Delete from Q
Linear queue
Priority queue
Deque
Conceptual View
rear
front
H
Circular queue
C
E
2. LINEAR QUEUES
IMPLEMENTATION
The Front and Rear variables contain indices of Front and Rear
R S
Front
Rear
A queue Q
Fron 0
Rear 4
t
R S V G
[1] [2] [3] [4] [5] [6]
[7]
Array representation
of Q[1:7]
10
The Front and Rear variables contain indices of Front and Rear
R
R S
G
S
Front
Rear
A queue Q
G
Linked List
11
Front
R
Rear
0
V
Rear
0
V
7
A
12
Queue-Full
When
Rear=N
Where
N=size of
queue
13
Front
R
Rear
7
A
Rear
1
V
7
A
14
Fron 0
t
Rear 0
QueueEmpty
When
Rear=Front
15
Checking for
Queue-Full
16
Checking for
Queue-Empty
17
18
3. CIRCULAR QUEUES
19
Circular Queues?
As the name indicates a
Conceptual View
rear
front
H
C
E
0 1 2 3
4 5
7
A B C D E F G
front
rear
6
H
20
21
Algorithm 5.4:
circular queue.
22
23
The top priority element at the head of the queue is the one to
be deleted.
24
Implementations:
#1 - Multiple queues as there are priority factors.
A low priority queue will be operated for deletion only when all
its high priority predecessors are empty.
25
(II) Deques
A deque (double ended queue) is a linear list
26
Deques (2)
Conceptual
View
rear
front
H A
G
C
E
27
5. APPLICATION OF QUEUES
28
Job leaves
CPU
New job
enters (with
user-id)
29
It is known that
30
31
32
33
7. CONCLUSION
34
Conclusion
A Queue is a linear list in which all insertions are
made at one end of the list known as rear or tail of
the queue and all deletions are made at the other end
known as front or head of the queue.
An insertion operation is also referred to as
enqueuing a queue and a deletion operation is
referred to as dequeuing a queue.
A queue data structure obeys the principle of first
in first out (FIFO) or first come first served (FCFS)
Different types of queues:
Linear queues
Circular queue
Deques (double ended queue)
Priority queues