SlideShare a Scribd company logo
Introduction
Of
Queue
Introduction
 A queue is a non-primitive linear data structure.
 It is an homogeneous collection of elements in
which new elements are added at one end called the
Rear end and the existing elements are deleted from
other end called the Front end.
 A queue is logically a First In First Out (FIFO)
type of list.
 In our everyday life we come across many situation
where we are wait for the desired service, there we
have to get into a waiting line for our turn to get
serviced.
Introduction
 This waiting queue can be thought of as a Queue.
 This Queue means a Line.
 For example:
 At the railway reservation booth, we have to get
into the reservation queue.
 Here, the important feature of the queue is when
new customers got into the queue from the rear
end, whereas the customers who get their sets
reserved leave the queue from the front end.
Introduction
 It means the customers are serviced in the order
in which they arrive the service center.
 This same characteristics apply to our Queue.
 The next slide figures show queue graphically
during insertion and deletion operations.
Introduction
 The following figures show queue graphically during
insertion operation's=Front & R=Rear
10 20
10
(a) Empty Queue
F=-1 & R=-1 0 1 2 3 4
(b) One element inserted in queue
F=0 & R=0 0 1 2 3 4
0 1 2 3 4
(b) Second element inserted in queue
F=0 & R=1
F R
F R
F R
Introduction
 The following figures show queue graphically during
deletion operation's=Front & R=Rear
10 20
20
(a) Empty Queue
F=-1 & R=-1
0 1 2 3 4
(b) One element inserted in queue
F=1 & R=1
0 1 2 3 4
0 1 2 3 4
(b) Second element inserted in queue
F=0 & R=1
F R
F R
F R
Queue Implementation
 There are two ways to implement a Queue:
 Static implementation (using array)
 Dynamic implementation
(using Pointer/Linked list)
Static Implementation (using array)
 If queue is implemented using arrays, we must be
sure about the exact number of elements .
 We want to store in the queue, because we have to
declare the size of the array at design time or before
the processing starts.
 In this case, the beginning of the array will become
the front for the queue and the last location of the
array will act as rear for the queue.
Static Implementation (using array)
 The following relation gives the total number of
elements present in the queue, when implemented
using arrays:
Total no of elem.=front-rear+1
 Also note that if rear<front then there will be no
element in the queue or queue is always be empty.
Dynamic implementation
(using Pointer/Linked list)
 Implementing queues using pointers, the main
disadvantage is that a node in a linked
representation occupies more memory space then a
corresponding element in the array representation.
Types of Queue
 There are many different way to implement a
Queue:
 Simple Queue/Linear Queue
 Circular Queue
 Double Ended Queue (Deque)
 Priority Queue
Simple Queue
 In the simple queue, the beginning of the array will
become the front for the queue and the last location
of the array will act as rear for the queue.
 The following relation gives the total number of
elements present in the queue, when implemented
using arrays:
Total no of elem.=front-rear+1
Simple Queue
 Also note that if rear<front then there will be no
element in the queue or queue is always be empty.
 Bellow show a figure a empty simple queue Q[5]
which can accommodate five elements.
Q[0] Q[1] Q[2] Q[3] Q[4]
Way of deletion Way of insertion
Fig: Simple Queue
Limitation of Simple Queue
 There are certain problems associated with a simple
queue when queue is implemented using array.
 Consider an example of a simple queue Q[5], which
is initially empty.
 We can only five elements insertion in queue.
 If we attempt to add more elements, the elements
can’t be inserted because in a simple queue rear
increment up to size-1.
Limitation of Simple Queue
 At that time our program will flash the message
“Queue is full”.
 But if the queue is too large of say 5000 elements it
will be a tedious job to do and time consuming too.
 To remove this problem we use circular queue.
Circular Queue
 A circular queue is one in which the insertion of a
new element is done at the very first location of the
queue if the last location of the queue is full.
 In other words if we have a queue Q of say n
elements, then after inserting an element last (n-1th)
location of the array the next elements will be
inserted at the very first location (0) of the array.
 It is possible to insert new elements, if and only if
those location (slots) are empty.
Circular Queue
 We can say that a circular queue is one in which the
first element comes just after the last element.
 It can be viewed as a mesh or loop of wire, in which
the two ends of the wire are connected together.
 A circular queue overcomes the problem of
unutilized space in linear queues implemented as
arrays.
 A circular queue also have a Front and Rear to keep
the track of the elements to be deleted and inserted
and therefore to maintain the unique characteristic
of the queue.
Circular Queue
 Bellow show a figure a empty circular queue Q[5]
which can accommodate five elements.
`
Q[0] Q[1]
Q[2]
Q[3]
Q[4]
Fig: Circular Queue
Double Ended Queue (Deque)
 It is also a homogeneous list of elements in which
insertion and deletion operations are performed
from both the ends.
 That is, we can insert elements from the rear end or
from the front ends.
 Hence it is called double-ended queue. It is
commonly referred as a Deque.
 There are two types of Deque. These two types are
due to the restrictions put to perform either the
insertions or deletions only at one end.
Double Ended Queue (Deque)
 There are:
 Input-restricted Deque.
 Output-restricted Deque.
 Bellow show a figure a empty Deque Q[5] which
can accommodate five elements.
Q[0] Q[1] Q[2] Q[3] Q[4]
deletion
deletion
insertion
insertion
Fig: A Deque
Double Ended Queue (Deque)
 There are:
 Input-restricted Deque: An input restricted
Deque restricts the insertion of the elements at
one end only, the deletion of elements can be
done at both the end of a queue.
10 20 30 40 50
Q[0] Q[1] Q[2] Q[3] Q[4]
deletion
deletion
insertion
Fig: A representation of an input-restricted Deque
F R
Double Ended Queue (Deque)
 There are:
 Output-restricted Deque: on the contrary, an
Output-restricted Deque, restricts the deletion of
elements at one end only, and allows insertion to
be done at both the ends of a Deque.
10 20 30 40 50
Q[0] Q[1] Q[2] Q[3] Q[4]
insertion
deletion
insertion
Fig: A representation of an Output-restricted Deque
F R
Double Ended Queue (Deque)
 The programs for input-restricted Deque and
output-restricted Deque would be similar to the
previous program of Deque except for a small
difference.
 The program for the input-restricted Deque would
not contain the function addqatbeg().
 Similarly the program for the output-restricted
Deque would not contain the function delatbeg().
Priority Queue
 A priority queue is a collection of elements where
the elements are stored according to their priority
levels.
 The order in which the elements should get added or
removed is decided by the priority or the element.
 Following rules are applied to maintain a priority
queue.
 The element with a higher priority is processes
before any element of lower priority.
Priority Queue
 If there are elements with same priority, then the
element added first in the queue would get
processed
 Here, smallest number that is most highest priority
and greater number that is less priority.
 Priority queues are used for implementing job
scheduling by the operating system.
 Where jobs with higher priorities are to be processed
first.
 Another application of priority queue is simulation
systems where priority corresponds to event times.
Applications of Queues
 Round robin technique for processor scheduling is
implemented using queues.
 All types of customer service (like railway ticket
reservation) center software’s are designed using
queues to store customers information.
 Printer server routines are designed using queues. A
number of users share a printer using printer server
the printer server then spools all the jobs from all the
users, to the server’s hard disk in a queue. From here
jobs are printed one-by-one according to their
number in the queue.

More Related Content

Similar to Data structure.ppt

Data structures
Data structuresData structures
Data structures
naveeth babu
 
Queue
QueueQueue
@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
 
Data Structures - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptxData Structures - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptx
DanielNesaKumarC
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
abinathsabi
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
Victor Palmar
 
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
 
computer notes - Memory organization
computer notes - Memory organizationcomputer notes - Memory organization
computer notes - Memory organization
ecomputernotes
 
DSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdfDSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdf
Bharati Vidyapeeth COE, Navi Mumbai
 
queues.pptx
queues.pptxqueues.pptx
queues.pptx
Aadilhussain65
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
blessyboban92
 
QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)
Mehedi Hasan
 
Queue
QueueQueue
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
Muhammad Hammad Waseem
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
Deepa Rani
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
skilljiolms
 
Queue
QueueQueue
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
Pulkitmodi1998
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
iqbalphy1
 
Study & Analysis of Complexities of Stack & Queue Operations in Data Structure
Study & Analysis of Complexities of Stack & Queue Operations in Data StructureStudy & Analysis of Complexities of Stack & Queue Operations in Data Structure
Study & Analysis of Complexities of Stack & Queue Operations in Data Structure
Meghaj Mallick
 

Similar to Data structure.ppt (20)

Data structures
Data structuresData structures
Data structures
 
Queue
QueueQueue
Queue
 
@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 - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptxData Structures - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptx
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d 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)
 
computer notes - Memory organization
computer notes - Memory organizationcomputer notes - Memory organization
computer notes - Memory organization
 
DSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdfDSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdf
 
queues.pptx
queues.pptxqueues.pptx
queues.pptx
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)
 
Queue
QueueQueue
Queue
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Queue
QueueQueue
Queue
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Study & Analysis of Complexities of Stack & Queue Operations in Data Structure
Study & Analysis of Complexities of Stack & Queue Operations in Data StructureStudy & Analysis of Complexities of Stack & Queue Operations in Data Structure
Study & Analysis of Complexities of Stack & Queue Operations in Data Structure
 

More from SajalFayyaz

Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
SajalFayyaz
 
data structure 9.pptx
data structure 9.pptxdata structure 9.pptx
data structure 9.pptx
SajalFayyaz
 
Data structure 8.pptx
Data structure 8.pptxData structure 8.pptx
Data structure 8.pptx
SajalFayyaz
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
SajalFayyaz
 
Data structure 6.pptx
Data structure 6.pptxData structure 6.pptx
Data structure 6.pptx
SajalFayyaz
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
SajalFayyaz
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
SajalFayyaz
 
data structure3.pptx
data structure3.pptxdata structure3.pptx
data structure3.pptx
SajalFayyaz
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
SajalFayyaz
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
SajalFayyaz
 

More from SajalFayyaz (10)

Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
data structure 9.pptx
data structure 9.pptxdata structure 9.pptx
data structure 9.pptx
 
Data structure 8.pptx
Data structure 8.pptxData structure 8.pptx
Data structure 8.pptx
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
Data structure 6.pptx
Data structure 6.pptxData structure 6.pptx
Data structure 6.pptx
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
data structure3.pptx
data structure3.pptxdata structure3.pptx
data structure3.pptx
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 

Recently uploaded

Australian Catholic University degree offer diploma Transcript
Australian Catholic University  degree offer diploma TranscriptAustralian Catholic University  degree offer diploma Transcript
Australian Catholic University degree offer diploma Transcript
taqyea
 
🚂🚘 Premium Girls Call Nashik 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Nashik  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...🚂🚘 Premium Girls Call Nashik  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Nashik 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
kuldeepsharmaks8120
 
M44.pdf dairy management farm report of an
M44.pdf dairy management farm report of anM44.pdf dairy management farm report of an
M44.pdf dairy management farm report of an
ManjuBv2
 
Introduction to the Red Hat Portfolio.pdf
Introduction to the Red Hat Portfolio.pdfIntroduction to the Red Hat Portfolio.pdf
Introduction to the Red Hat Portfolio.pdf
kihus38
 
the unexpected potential of Dijkstra's Algorithm
the unexpected potential of Dijkstra's Algorithmthe unexpected potential of Dijkstra's Algorithm
the unexpected potential of Dijkstra's Algorithm
huseindihon
 
OpenMetadata Spotlight - OpenMetadata @ Aspire by Vinol Joy Dsouza
OpenMetadata Spotlight - OpenMetadata @ Aspire by Vinol Joy DsouzaOpenMetadata Spotlight - OpenMetadata @ Aspire by Vinol Joy Dsouza
OpenMetadata Spotlight - OpenMetadata @ Aspire by Vinol Joy Dsouza
OpenMetadata
 
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
sharonblush
 
Machine learning _new.pptx for a presentation
Machine learning _new.pptx for a presentationMachine learning _new.pptx for a presentation
Machine learning _new.pptx for a presentation
RahulS66654
 
the potential of the development of the Ford–Fulkerson algorithm to solve the...
the potential of the development of the Ford–Fulkerson algorithm to solve the...the potential of the development of the Ford–Fulkerson algorithm to solve the...
the potential of the development of the Ford–Fulkerson algorithm to solve the...
huseindihon
 
DataScienceConcept_Kanchana_Weerasinghe.pptx
DataScienceConcept_Kanchana_Weerasinghe.pptxDataScienceConcept_Kanchana_Weerasinghe.pptx
DataScienceConcept_Kanchana_Weerasinghe.pptx
Kanchana Weerasinghe
 
bai-tap-tieng-anh-lop-12-unit-4-the-mass-media (1).doc
bai-tap-tieng-anh-lop-12-unit-4-the-mass-media (1).docbai-tap-tieng-anh-lop-12-unit-4-the-mass-media (1).doc
bai-tap-tieng-anh-lop-12-unit-4-the-mass-media (1).doc
PhngThLmHnh
 
🚂🚘 Premium Girls Call Bangalore 🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
🚂🚘 Premium Girls Call Bangalore  🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...🚂🚘 Premium Girls Call Bangalore  🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
🚂🚘 Premium Girls Call Bangalore 🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
bhupeshkumar0889
 
Seamlessly Pay Online, Pay In Stores or Send Money
Seamlessly Pay Online, Pay In Stores or Send MoneySeamlessly Pay Online, Pay In Stores or Send Money
Seamlessly Pay Online, Pay In Stores or Send Money
gargtinna79
 
Girls Call Vadodara 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Vadodara 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Vadodara 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Vadodara 000XX00000 Provide Best And Top Girl Service And No1 in City
gargnatasha985
 
VIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
VIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...VIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
VIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
44annissa
 
Maruti Wagon R on road price in Faridabad - CarDekho
Maruti Wagon R on road price in Faridabad - CarDekhoMaruti Wagon R on road price in Faridabad - CarDekho
Maruti Wagon R on road price in Faridabad - CarDekho
kamli sharma#S10
 
Potential Uses of the Floyd-Warshall Algorithm as appropriate
Potential Uses of the Floyd-Warshall Algorithm as appropriatePotential Uses of the Floyd-Warshall Algorithm as appropriate
Potential Uses of the Floyd-Warshall Algorithm as appropriate
huseindihon
 
transgenders community data in india by govt
transgenders community data in india by govttransgenders community data in india by govt
transgenders community data in india by govt
palanisamyiiiier
 
Supervised Learning (Data Science).pptx
Supervised Learning  (Data Science).pptxSupervised Learning  (Data Science).pptx
Supervised Learning (Data Science).pptx
TARIKU ENDALE
 
Welcome back to Instagram. Sign in to check out what your
Welcome back to Instagram. Sign in to check out what yourWelcome back to Instagram. Sign in to check out what your
Welcome back to Instagram. Sign in to check out what your
Virni Arrora
 

Recently uploaded (20)

Australian Catholic University degree offer diploma Transcript
Australian Catholic University  degree offer diploma TranscriptAustralian Catholic University  degree offer diploma Transcript
Australian Catholic University degree offer diploma Transcript
 
🚂🚘 Premium Girls Call Nashik 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Nashik  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...🚂🚘 Premium Girls Call Nashik  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Nashik 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
 
M44.pdf dairy management farm report of an
M44.pdf dairy management farm report of anM44.pdf dairy management farm report of an
M44.pdf dairy management farm report of an
 
Introduction to the Red Hat Portfolio.pdf
Introduction to the Red Hat Portfolio.pdfIntroduction to the Red Hat Portfolio.pdf
Introduction to the Red Hat Portfolio.pdf
 
the unexpected potential of Dijkstra's Algorithm
the unexpected potential of Dijkstra's Algorithmthe unexpected potential of Dijkstra's Algorithm
the unexpected potential of Dijkstra's Algorithm
 
OpenMetadata Spotlight - OpenMetadata @ Aspire by Vinol Joy Dsouza
OpenMetadata Spotlight - OpenMetadata @ Aspire by Vinol Joy DsouzaOpenMetadata Spotlight - OpenMetadata @ Aspire by Vinol Joy Dsouza
OpenMetadata Spotlight - OpenMetadata @ Aspire by Vinol Joy Dsouza
 
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
 
Machine learning _new.pptx for a presentation
Machine learning _new.pptx for a presentationMachine learning _new.pptx for a presentation
Machine learning _new.pptx for a presentation
 
the potential of the development of the Ford–Fulkerson algorithm to solve the...
the potential of the development of the Ford–Fulkerson algorithm to solve the...the potential of the development of the Ford–Fulkerson algorithm to solve the...
the potential of the development of the Ford–Fulkerson algorithm to solve the...
 
DataScienceConcept_Kanchana_Weerasinghe.pptx
DataScienceConcept_Kanchana_Weerasinghe.pptxDataScienceConcept_Kanchana_Weerasinghe.pptx
DataScienceConcept_Kanchana_Weerasinghe.pptx
 
bai-tap-tieng-anh-lop-12-unit-4-the-mass-media (1).doc
bai-tap-tieng-anh-lop-12-unit-4-the-mass-media (1).docbai-tap-tieng-anh-lop-12-unit-4-the-mass-media (1).doc
bai-tap-tieng-anh-lop-12-unit-4-the-mass-media (1).doc
 
🚂🚘 Premium Girls Call Bangalore 🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
🚂🚘 Premium Girls Call Bangalore  🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...🚂🚘 Premium Girls Call Bangalore  🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
🚂🚘 Premium Girls Call Bangalore 🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
 
Seamlessly Pay Online, Pay In Stores or Send Money
Seamlessly Pay Online, Pay In Stores or Send MoneySeamlessly Pay Online, Pay In Stores or Send Money
Seamlessly Pay Online, Pay In Stores or Send Money
 
Girls Call Vadodara 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Vadodara 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Vadodara 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Vadodara 000XX00000 Provide Best And Top Girl Service And No1 in City
 
VIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
VIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...VIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
VIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
 
Maruti Wagon R on road price in Faridabad - CarDekho
Maruti Wagon R on road price in Faridabad - CarDekhoMaruti Wagon R on road price in Faridabad - CarDekho
Maruti Wagon R on road price in Faridabad - CarDekho
 
Potential Uses of the Floyd-Warshall Algorithm as appropriate
Potential Uses of the Floyd-Warshall Algorithm as appropriatePotential Uses of the Floyd-Warshall Algorithm as appropriate
Potential Uses of the Floyd-Warshall Algorithm as appropriate
 
transgenders community data in india by govt
transgenders community data in india by govttransgenders community data in india by govt
transgenders community data in india by govt
 
Supervised Learning (Data Science).pptx
Supervised Learning  (Data Science).pptxSupervised Learning  (Data Science).pptx
Supervised Learning (Data Science).pptx
 
Welcome back to Instagram. Sign in to check out what your
Welcome back to Instagram. Sign in to check out what yourWelcome back to Instagram. Sign in to check out what your
Welcome back to Instagram. Sign in to check out what your
 

Data structure.ppt

  • 2. Introduction  A queue is a non-primitive linear data structure.  It is an homogeneous collection of elements in which new elements are added at one end called the Rear end and the existing elements are deleted from other end called the Front end.  A queue is logically a First In First Out (FIFO) type of list.  In our everyday life we come across many situation where we are wait for the desired service, there we have to get into a waiting line for our turn to get serviced.
  • 3. Introduction  This waiting queue can be thought of as a Queue.  This Queue means a Line.  For example:  At the railway reservation booth, we have to get into the reservation queue.  Here, the important feature of the queue is when new customers got into the queue from the rear end, whereas the customers who get their sets reserved leave the queue from the front end.
  • 4. Introduction  It means the customers are serviced in the order in which they arrive the service center.  This same characteristics apply to our Queue.  The next slide figures show queue graphically during insertion and deletion operations.
  • 5. Introduction  The following figures show queue graphically during insertion operation's=Front & R=Rear 10 20 10 (a) Empty Queue F=-1 & R=-1 0 1 2 3 4 (b) One element inserted in queue F=0 & R=0 0 1 2 3 4 0 1 2 3 4 (b) Second element inserted in queue F=0 & R=1 F R F R F R
  • 6. Introduction  The following figures show queue graphically during deletion operation's=Front & R=Rear 10 20 20 (a) Empty Queue F=-1 & R=-1 0 1 2 3 4 (b) One element inserted in queue F=1 & R=1 0 1 2 3 4 0 1 2 3 4 (b) Second element inserted in queue F=0 & R=1 F R F R F R
  • 7. Queue Implementation  There are two ways to implement a Queue:  Static implementation (using array)  Dynamic implementation (using Pointer/Linked list)
  • 8. Static Implementation (using array)  If queue is implemented using arrays, we must be sure about the exact number of elements .  We want to store in the queue, because we have to declare the size of the array at design time or before the processing starts.  In this case, the beginning of the array will become the front for the queue and the last location of the array will act as rear for the queue.
  • 9. Static Implementation (using array)  The following relation gives the total number of elements present in the queue, when implemented using arrays: Total no of elem.=front-rear+1  Also note that if rear<front then there will be no element in the queue or queue is always be empty.
  • 10. Dynamic implementation (using Pointer/Linked list)  Implementing queues using pointers, the main disadvantage is that a node in a linked representation occupies more memory space then a corresponding element in the array representation.
  • 11. Types of Queue  There are many different way to implement a Queue:  Simple Queue/Linear Queue  Circular Queue  Double Ended Queue (Deque)  Priority Queue
  • 12. Simple Queue  In the simple queue, the beginning of the array will become the front for the queue and the last location of the array will act as rear for the queue.  The following relation gives the total number of elements present in the queue, when implemented using arrays: Total no of elem.=front-rear+1
  • 13. Simple Queue  Also note that if rear<front then there will be no element in the queue or queue is always be empty.  Bellow show a figure a empty simple queue Q[5] which can accommodate five elements. Q[0] Q[1] Q[2] Q[3] Q[4] Way of deletion Way of insertion Fig: Simple Queue
  • 14. Limitation of Simple Queue  There are certain problems associated with a simple queue when queue is implemented using array.  Consider an example of a simple queue Q[5], which is initially empty.  We can only five elements insertion in queue.  If we attempt to add more elements, the elements can’t be inserted because in a simple queue rear increment up to size-1.
  • 15. Limitation of Simple Queue  At that time our program will flash the message “Queue is full”.  But if the queue is too large of say 5000 elements it will be a tedious job to do and time consuming too.  To remove this problem we use circular queue.
  • 16. Circular Queue  A circular queue is one in which the insertion of a new element is done at the very first location of the queue if the last location of the queue is full.  In other words if we have a queue Q of say n elements, then after inserting an element last (n-1th) location of the array the next elements will be inserted at the very first location (0) of the array.  It is possible to insert new elements, if and only if those location (slots) are empty.
  • 17. Circular Queue  We can say that a circular queue is one in which the first element comes just after the last element.  It can be viewed as a mesh or loop of wire, in which the two ends of the wire are connected together.  A circular queue overcomes the problem of unutilized space in linear queues implemented as arrays.  A circular queue also have a Front and Rear to keep the track of the elements to be deleted and inserted and therefore to maintain the unique characteristic of the queue.
  • 18. Circular Queue  Bellow show a figure a empty circular queue Q[5] which can accommodate five elements. ` Q[0] Q[1] Q[2] Q[3] Q[4] Fig: Circular Queue
  • 19. Double Ended Queue (Deque)  It is also a homogeneous list of elements in which insertion and deletion operations are performed from both the ends.  That is, we can insert elements from the rear end or from the front ends.  Hence it is called double-ended queue. It is commonly referred as a Deque.  There are two types of Deque. These two types are due to the restrictions put to perform either the insertions or deletions only at one end.
  • 20. Double Ended Queue (Deque)  There are:  Input-restricted Deque.  Output-restricted Deque.  Bellow show a figure a empty Deque Q[5] which can accommodate five elements. Q[0] Q[1] Q[2] Q[3] Q[4] deletion deletion insertion insertion Fig: A Deque
  • 21. Double Ended Queue (Deque)  There are:  Input-restricted Deque: An input restricted Deque restricts the insertion of the elements at one end only, the deletion of elements can be done at both the end of a queue. 10 20 30 40 50 Q[0] Q[1] Q[2] Q[3] Q[4] deletion deletion insertion Fig: A representation of an input-restricted Deque F R
  • 22. Double Ended Queue (Deque)  There are:  Output-restricted Deque: on the contrary, an Output-restricted Deque, restricts the deletion of elements at one end only, and allows insertion to be done at both the ends of a Deque. 10 20 30 40 50 Q[0] Q[1] Q[2] Q[3] Q[4] insertion deletion insertion Fig: A representation of an Output-restricted Deque F R
  • 23. Double Ended Queue (Deque)  The programs for input-restricted Deque and output-restricted Deque would be similar to the previous program of Deque except for a small difference.  The program for the input-restricted Deque would not contain the function addqatbeg().  Similarly the program for the output-restricted Deque would not contain the function delatbeg().
  • 24. Priority Queue  A priority queue is a collection of elements where the elements are stored according to their priority levels.  The order in which the elements should get added or removed is decided by the priority or the element.  Following rules are applied to maintain a priority queue.  The element with a higher priority is processes before any element of lower priority.
  • 25. Priority Queue  If there are elements with same priority, then the element added first in the queue would get processed  Here, smallest number that is most highest priority and greater number that is less priority.  Priority queues are used for implementing job scheduling by the operating system.  Where jobs with higher priorities are to be processed first.  Another application of priority queue is simulation systems where priority corresponds to event times.
  • 26. Applications of Queues  Round robin technique for processor scheduling is implemented using queues.  All types of customer service (like railway ticket reservation) center software’s are designed using queues to store customers information.  Printer server routines are designed using queues. A number of users share a printer using printer server the printer server then spools all the jobs from all the users, to the server’s hard disk in a queue. From here jobs are printed one-by-one according to their number in the queue.