SlideShare ist ein Scribd-Unternehmen logo
1 von 26
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.

Weitere ähnliche Inhalte

Ähnlich wie Data structure.ppt

@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 - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptxData Structures - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptxDanielNesaKumarC
 
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 computerabinathsabi
 
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 organizationecomputernotes
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1blessyboban92
 
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
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structuresDeepa Rani
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptxskilljiolms
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for publiciqbalphy1
 
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 StructureMeghaj Mallick
 

Ähnlich wie 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
 

Mehr von SajalFayyaz

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

Mehr von 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
 

Kürzlich hochgeladen

Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteedamy56318795
 
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...amitlee9823
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...amitlee9823
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...amitlee9823
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...amitlee9823
 
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...gajnagarg
 
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...gajnagarg
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 

Kürzlich hochgeladen (20)

Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
 
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 

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.