SlideShare una empresa de Scribd logo
1 de 20
Lecture - 9
On
Queues
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
QUEUES
• A Queue is a linear list of elements in which deletions can take place only at one end,
called the front, and insertions can take place only at the other end, called the rear.
The terms “front” and “rear” are used in describing a linear list only when it
implemented as a queue.
• Queues are also called first-in first-out (FIFO) lists, since the first element in a queue
will be the first element out of the queue. In other words, the order in which elements
enter a queue is the order in which they leave. This contrasts with stacks, which are
Last-in First-out (LIFO) lists.
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Queues abound in everyday life.
For example:
• The automobiles waiting to pass through an intersection form a
queue, in which the first car in line is the first car through;
• the people waiting in line at a bank form a queue, where the first
person in line is the first person to be waited on; and so on.
• An important example of a queue in computer science occurs in a
timesharing system, in which programs with the same priority form a
queue while waiting to be executed.
• Queue for printing purposes
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Basic operations that involved in Queue:
• Create queue, Create (Q)
• Identify either queue is empty
• Add new item in queue
• Delete item from queue
• Call first item in queue
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Example :
Figure 6-15 (a) is a schematic diagram of a queue with 4 elements, where AAA is the
front element and DDD is the rear element. Observe that the front and rear elements of
the queue are also, respectively, the first and last elements of the list. Suppose an
element is deleted from the queue. Then it must be AAA. This yields the queue in figure
6-15(b), where BBB is now the front element. Next, suppose EEE is added to the queue
and then FFF is now the rear element. Now suppose another element is deleted from the
queue; then it must be BBB, to yield the queue in fig.6-15(d). And so on. Observe that in
such a data structure, EEE will be deleted before FFF because it has been placed in the
queue before FFF. However, EEE will have to wait until CCC and DDD are deleted.
AAA CCCBBB DDD
CCCBBB DDD
CCCBBB DDD EEE FFF
CCC DDD EEE FFF
(a)
(d)
(b)
(c)
Fig. 6-15
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
REPRESENTATION OF QUEUE
• Queue may be represented in the computer in various ways, usually by
means of one-way lists or linear arrays.
• Each of our queues will be maintained by a linear array QUEUE and two
pointer variables:
• FRONT, containing the location of the front element of the queue;
• and REAR, containing the location of the rear element of the queue.
• The condition FRONT = NULL will indicate that the queue is empty.
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
• when an element is deleted from the queue, the value of FRONT is
increased by 1; this can be implemented by the assignment
• FRONT := FRONT + 1
• Similarly, whenever an element is added to the queue, the value of REAR is
increased by 1; this can be implemented by the assignment
• REAR := REAR + 1
• This means that after N insertions, the rear element of the queue will
occupy QUEUE[N] or, in other words, eventually the queue will occupy the
last part of the array. This occurs even through the queue itself may not
contain many elements.
REPRESENTATION OF QUEUE
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
• Suppose we want to insert an element ITEM into a queue at the time the queue does
occupy the past part of the array,
• i.e. when REAR = N. One way to do this is to simply move the entire queue to the
beginning of the array, changing FRONT and REAR accordingly, and then inserting
ITEM as above.
• Array QUEUE is circular, that is, that QUEUE[1] comes after QUEUE[N] in the array.
With this assumption, we insert ITEM into the queue by assigning ITEM to QUEUE[1].
Specifically, instead of increasing REAR to N+1, we reset REAR=1 and then assign
QUEUE[REAR] := ITEM
• Similarly, if FRONT = N and an element of QUEUE is deleted, we reset FRONT = 1
instead of increasing FRONT to N + 1.
• Suppose that our queue contains only one element, i.e., suppose that
• FRONT = REAR = NULL
• And suppose that the element is deleted. Then we assign
• FRONT := NULL and REAR := NULL
To indicate that the queue is empty.
REPRESENTATION OF QUEUE
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
REPRESENTATION OF QUEUE
FRONT : 1
REAR : 4
FRONT : 2
REAR : 4
FRONT : 2
REAR : 6
FRONT : 3
REAR : 6
Fig : 6.16 Array representation of a queue
QUEUE
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Example
Figure 6-17 shows how a queue may be maintained by a circular array QUEUE with N = 5
memory locations. Observe that the queue always occupies consecutive locations except
when it occupies locations at the beginning and at the end of the array. If the queue is
viewed as a circular array, this means that is still occupies consecutive locations. Also, as
indicated by fig. 6-17(m), the queue will be empty only when FRONT = REAR and an
elements is deleted. For this reason, NULL is assigned to FRONT and REAR in fig. 6-
17(m).
(a) Initially empty : FRONT : 0
REAR : 0
1 2 3 4 5
QUEUE
(b) A, B and then C inserted: FRONT : 1
REAR : 3
(C) A deleted : FRONT : 2
REAR : 3
(d) D and then E inserted : FRONT : 2
REAR : 5
A B C
B C
B C D E
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Example
(e) B and C deleted : FRONT : 4
REAR : 5
D E
1 2 3 4 5
QUEUE
(f) F inserted : FRONT : 4
REAR : 1
(g) D deleted : FRONT : 5
REAR : 1
(h) G and then H inserted : FRONT : 5
REAR : 3
F D E
F E
F G H E
(i) E deleted : FRONT : 1
REAR : 3
(j) F deleted : FRONT : 2
REAR : 3
(k) K inserted : FRONT : 2
REAR : 4
F G H
G G
G H K
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Example
(l) G and H deleted : FRONT : 4
REAR : 5
K
1 2 3 4 5
QUEUE
(m) K deleted, QUEUE is empty : FRONT : 4
REAR : 1
Fig :6.17
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
QINSERT
QINSERT(QUEUE,N,FRONT,REAR,ITEM)
This procedure inserts an element ITEM into a queue.
[Queue already fill]
1. If FRONT=1 and REAR=N, or if FRONT=REAR+1, then :
Write: Overflow, and Return.
2. [Find new value of REAR]
If FRONT=NULL, then :[Queue initially empty]
Set FRONT:=1 and REAR:=1
Else if REAR =N then
Set REAR:=1
Else Set REAR:=REAR+1
[End of if structure]
3. Set QUEUE[REAR]:=ITEM [This inserts new element]
4. Return.
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
QDELETE
ITEM.QDELETE(QUEUE,N,FRONT,REAR,ITEM)
This procedure deletes an element from the queue and assigns it to the
variable
• [Queue already empty]
If FRONT=NULL, then Write: Underflow, and Return.
2. Set ITEM=QUEUE[FRONT]
3. [Find new value of FRONT]
If FRONT=REAR, then [Queue has only one element to start]
Set FRONT=NULL and REAR=NULL
Else if FRONT =N then
Set FRONT =1
Else Set FRONT = FRONT +1
[End of if structure]
4. Return
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Deque
• The mathematical model of a Deque (usually pronounced like "deck") is
an irregular acronym (Operation) of double-ended queue.
• Double-ended queues are a kind of sequence containers.
• Elements can be efficiently added and removed from any of its ends
(either the beginning or the end of the sequence).
•The model allows data to be entered and withdrawn from the front
and rear of the data structure.
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Deques
• Insertions and deletions can occur at either end but not in the middle
• Implementation is similar to that for queues
• Deques are not heavily used
• You should know what a deque is, but we won’t explore them much further
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Double-Ended-QUE
•There are two variations of deque
–Input-restricted deque
An input restricted deque is a deque which allows insertion at only
one end of the list but allows deletion a both end of the list.
–Output-restricted deque
An output restricted deque is a deque which allows deletion at only
one end of the list but allows insertin a both end of the list
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
Priority Queue
• A priority queue is a collection of elements such that each element has
been assigned a priority, such that the order in which the elements are
deleted and processed comes from the following rules:
– An element with higher priority will be processed before any element with
lower priority.
– Two elements with the same priority will be processed in order in which they
are add to the queue.
Prepared by, Jesmin Akhter,
Lecturer, IIT,JU
One way list representation
• Each node contains three items of information
• A node X proceeds with a node Y in the list when
– X has higher priority than Y or
– Both has same priority but X was added in the list before Y.
AAA 1 BBB 2 CCC 3
DDD 4 EEE 5 FFF 6 ×
Start
PRN
• Property:
– First node will processed first

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Queues
QueuesQueues
Queues
 
stack & queue
stack & queuestack & queue
stack & queue
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Data structures and algorithms - sorting algorithms
Data structures and algorithms - sorting algorithmsData structures and algorithms - sorting algorithms
Data structures and algorithms - sorting algorithms
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Queue
QueueQueue
Queue
 
Queues-handouts
Queues-handoutsQueues-handouts
Queues-handouts
 
Module 01 Stack and Recursion
Module 01 Stack and RecursionModule 01 Stack and Recursion
Module 01 Stack and Recursion
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
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)
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 

Destacado

Sem3 nivel1 francia romano terra
Sem3 nivel1 francia romano terraSem3 nivel1 francia romano terra
Sem3 nivel1 francia romano terramoncayo1986
 
358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9sumitbardhan
 
المحاضرة الثامنة: تراكيب البيانات الطابور
المحاضرة الثامنة: تراكيب البيانات الطابورالمحاضرة الثامنة: تراكيب البيانات الطابور
المحاضرة الثامنة: تراكيب البيانات الطابورMahmoud Alfarra
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queuesurya pandian
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Roman Rodomansky
 
Register transfer and micro operation
Register transfer and micro operationRegister transfer and micro operation
Register transfer and micro operationKamal Acharya
 
Computer organiztion5
Computer organiztion5Computer organiztion5
Computer organiztion5Umang Gupta
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 
5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
7. Relational Database Design in DBMS
7. Relational Database Design in DBMS7. Relational Database Design in DBMS
7. Relational Database Design in DBMSkoolkampus
 

Destacado (20)

Data structure
Data structureData structure
Data structure
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
 
Sem3 nivel1 francia romano terra
Sem3 nivel1 francia romano terraSem3 nivel1 francia romano terra
Sem3 nivel1 francia romano terra
 
Queues
QueuesQueues
Queues
 
Queues
QueuesQueues
Queues
 
358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9
 
Queue
QueueQueue
Queue
 
المحاضرة الثامنة: تراكيب البيانات الطابور
المحاضرة الثامنة: تراكيب البيانات الطابورالمحاضرة الثامنة: تراكيب البيانات الطابور
المحاضرة الثامنة: تراكيب البيانات الطابور
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Register transfer and micro operation
Register transfer and micro operationRegister transfer and micro operation
Register transfer and micro operation
 
Computer organiztion5
Computer organiztion5Computer organiztion5
Computer organiztion5
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
7. Relational Database Design in DBMS
7. Relational Database Design in DBMS7. Relational Database Design in DBMS
7. Relational Database Design in DBMS
 

Similar a Data structure lecture 9

10994103.ppt
10994103.ppt10994103.ppt
10994103.pptSushmaG48
 
cp264_lecture18_queue.ppt
cp264_lecture18_queue.pptcp264_lecture18_queue.ppt
cp264_lecture18_queue.pptssuserff72e4
 
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
 
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
 
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
 
6 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart36 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart3SSE_AndyLi
 
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
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptxDdushb
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptxSonaPathak4
 
chapter10-queue-161018120329.pdf
chapter10-queue-161018120329.pdfchapter10-queue-161018120329.pdf
chapter10-queue-161018120329.pdfssuserff72e4
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptxskilljiolms
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-dequesRishabh Jindal
 

Similar a Data structure lecture 9 (20)

10994103.ppt
10994103.ppt10994103.ppt
10994103.ppt
 
cp264_lecture18_queue.ppt
cp264_lecture18_queue.pptcp264_lecture18_queue.ppt
cp264_lecture18_queue.ppt
 
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
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
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
 
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
 
6 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart36 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart3
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
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 and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
Queue
QueueQueue
Queue
 
chapter10-queue-161018120329.pdf
chapter10-queue-161018120329.pdfchapter10-queue-161018120329.pdf
chapter10-queue-161018120329.pdf
 
LEC3-DS ALGO(updated).pdf
LEC3-DS  ALGO(updated).pdfLEC3-DS  ALGO(updated).pdf
LEC3-DS ALGO(updated).pdf
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-deques
 
Queue
QueueQueue
Queue
 
queue.pptx
queue.pptxqueue.pptx
queue.pptx
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
Queue
QueueQueue
Queue
 

Más de Kumar

Graphics devices
Graphics devicesGraphics devices
Graphics devicesKumar
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithmsKumar
 
region-filling
region-fillingregion-filling
region-fillingKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xsltKumar
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xmlKumar
 
Xml basics
Xml basicsXml basics
Xml basicsKumar
 
XML Schema
XML SchemaXML Schema
XML SchemaKumar
 
Publishing xml
Publishing xmlPublishing xml
Publishing xmlKumar
 
Applying xml
Applying xmlApplying xml
Applying xmlKumar
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XMLKumar
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee applicationKumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLKumar
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB FundmentalsKumar
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programmingKumar
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversKumar
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EEKumar
 

Más de Kumar (20)

Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
region-filling
region-fillingregion-filling
region-filling
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DTD
DTDDTD
DTD
 
Applying xml
Applying xmlApplying xml
Applying xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
 

Último

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Último (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

Data structure lecture 9

  • 2. Prepared by, Jesmin Akhter, Lecturer, IIT,JU QUEUES • A Queue is a linear list of elements in which deletions can take place only at one end, called the front, and insertions can take place only at the other end, called the rear. The terms “front” and “rear” are used in describing a linear list only when it implemented as a queue. • Queues are also called first-in first-out (FIFO) lists, since the first element in a queue will be the first element out of the queue. In other words, the order in which elements enter a queue is the order in which they leave. This contrasts with stacks, which are Last-in First-out (LIFO) lists.
  • 3. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Queues abound in everyday life. For example: • The automobiles waiting to pass through an intersection form a queue, in which the first car in line is the first car through; • the people waiting in line at a bank form a queue, where the first person in line is the first person to be waited on; and so on. • An important example of a queue in computer science occurs in a timesharing system, in which programs with the same priority form a queue while waiting to be executed. • Queue for printing purposes
  • 4. Prepared by, Jesmin Akhter, Lecturer, IIT,JU
  • 5. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Basic operations that involved in Queue: • Create queue, Create (Q) • Identify either queue is empty • Add new item in queue • Delete item from queue • Call first item in queue
  • 6. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Example : Figure 6-15 (a) is a schematic diagram of a queue with 4 elements, where AAA is the front element and DDD is the rear element. Observe that the front and rear elements of the queue are also, respectively, the first and last elements of the list. Suppose an element is deleted from the queue. Then it must be AAA. This yields the queue in figure 6-15(b), where BBB is now the front element. Next, suppose EEE is added to the queue and then FFF is now the rear element. Now suppose another element is deleted from the queue; then it must be BBB, to yield the queue in fig.6-15(d). And so on. Observe that in such a data structure, EEE will be deleted before FFF because it has been placed in the queue before FFF. However, EEE will have to wait until CCC and DDD are deleted. AAA CCCBBB DDD CCCBBB DDD CCCBBB DDD EEE FFF CCC DDD EEE FFF (a) (d) (b) (c) Fig. 6-15
  • 7. Prepared by, Jesmin Akhter, Lecturer, IIT,JU REPRESENTATION OF QUEUE • Queue may be represented in the computer in various ways, usually by means of one-way lists or linear arrays. • Each of our queues will be maintained by a linear array QUEUE and two pointer variables: • FRONT, containing the location of the front element of the queue; • and REAR, containing the location of the rear element of the queue. • The condition FRONT = NULL will indicate that the queue is empty.
  • 8. Prepared by, Jesmin Akhter, Lecturer, IIT,JU • when an element is deleted from the queue, the value of FRONT is increased by 1; this can be implemented by the assignment • FRONT := FRONT + 1 • Similarly, whenever an element is added to the queue, the value of REAR is increased by 1; this can be implemented by the assignment • REAR := REAR + 1 • This means that after N insertions, the rear element of the queue will occupy QUEUE[N] or, in other words, eventually the queue will occupy the last part of the array. This occurs even through the queue itself may not contain many elements. REPRESENTATION OF QUEUE
  • 9. Prepared by, Jesmin Akhter, Lecturer, IIT,JU • Suppose we want to insert an element ITEM into a queue at the time the queue does occupy the past part of the array, • i.e. when REAR = N. One way to do this is to simply move the entire queue to the beginning of the array, changing FRONT and REAR accordingly, and then inserting ITEM as above. • Array QUEUE is circular, that is, that QUEUE[1] comes after QUEUE[N] in the array. With this assumption, we insert ITEM into the queue by assigning ITEM to QUEUE[1]. Specifically, instead of increasing REAR to N+1, we reset REAR=1 and then assign QUEUE[REAR] := ITEM • Similarly, if FRONT = N and an element of QUEUE is deleted, we reset FRONT = 1 instead of increasing FRONT to N + 1. • Suppose that our queue contains only one element, i.e., suppose that • FRONT = REAR = NULL • And suppose that the element is deleted. Then we assign • FRONT := NULL and REAR := NULL To indicate that the queue is empty. REPRESENTATION OF QUEUE
  • 10. Prepared by, Jesmin Akhter, Lecturer, IIT,JU REPRESENTATION OF QUEUE FRONT : 1 REAR : 4 FRONT : 2 REAR : 4 FRONT : 2 REAR : 6 FRONT : 3 REAR : 6 Fig : 6.16 Array representation of a queue QUEUE
  • 11. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Example Figure 6-17 shows how a queue may be maintained by a circular array QUEUE with N = 5 memory locations. Observe that the queue always occupies consecutive locations except when it occupies locations at the beginning and at the end of the array. If the queue is viewed as a circular array, this means that is still occupies consecutive locations. Also, as indicated by fig. 6-17(m), the queue will be empty only when FRONT = REAR and an elements is deleted. For this reason, NULL is assigned to FRONT and REAR in fig. 6- 17(m). (a) Initially empty : FRONT : 0 REAR : 0 1 2 3 4 5 QUEUE (b) A, B and then C inserted: FRONT : 1 REAR : 3 (C) A deleted : FRONT : 2 REAR : 3 (d) D and then E inserted : FRONT : 2 REAR : 5 A B C B C B C D E
  • 12. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Example (e) B and C deleted : FRONT : 4 REAR : 5 D E 1 2 3 4 5 QUEUE (f) F inserted : FRONT : 4 REAR : 1 (g) D deleted : FRONT : 5 REAR : 1 (h) G and then H inserted : FRONT : 5 REAR : 3 F D E F E F G H E (i) E deleted : FRONT : 1 REAR : 3 (j) F deleted : FRONT : 2 REAR : 3 (k) K inserted : FRONT : 2 REAR : 4 F G H G G G H K
  • 13. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Example (l) G and H deleted : FRONT : 4 REAR : 5 K 1 2 3 4 5 QUEUE (m) K deleted, QUEUE is empty : FRONT : 4 REAR : 1 Fig :6.17
  • 14. Prepared by, Jesmin Akhter, Lecturer, IIT,JU QINSERT QINSERT(QUEUE,N,FRONT,REAR,ITEM) This procedure inserts an element ITEM into a queue. [Queue already fill] 1. If FRONT=1 and REAR=N, or if FRONT=REAR+1, then : Write: Overflow, and Return. 2. [Find new value of REAR] If FRONT=NULL, then :[Queue initially empty] Set FRONT:=1 and REAR:=1 Else if REAR =N then Set REAR:=1 Else Set REAR:=REAR+1 [End of if structure] 3. Set QUEUE[REAR]:=ITEM [This inserts new element] 4. Return.
  • 15. Prepared by, Jesmin Akhter, Lecturer, IIT,JU QDELETE ITEM.QDELETE(QUEUE,N,FRONT,REAR,ITEM) This procedure deletes an element from the queue and assigns it to the variable • [Queue already empty] If FRONT=NULL, then Write: Underflow, and Return. 2. Set ITEM=QUEUE[FRONT] 3. [Find new value of FRONT] If FRONT=REAR, then [Queue has only one element to start] Set FRONT=NULL and REAR=NULL Else if FRONT =N then Set FRONT =1 Else Set FRONT = FRONT +1 [End of if structure] 4. Return
  • 16. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Deque • The mathematical model of a Deque (usually pronounced like "deck") is an irregular acronym (Operation) of double-ended queue. • Double-ended queues are a kind of sequence containers. • Elements can be efficiently added and removed from any of its ends (either the beginning or the end of the sequence). •The model allows data to be entered and withdrawn from the front and rear of the data structure.
  • 17. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Deques • Insertions and deletions can occur at either end but not in the middle • Implementation is similar to that for queues • Deques are not heavily used • You should know what a deque is, but we won’t explore them much further
  • 18. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Double-Ended-QUE •There are two variations of deque –Input-restricted deque An input restricted deque is a deque which allows insertion at only one end of the list but allows deletion a both end of the list. –Output-restricted deque An output restricted deque is a deque which allows deletion at only one end of the list but allows insertin a both end of the list
  • 19. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Priority Queue • A priority queue is a collection of elements such that each element has been assigned a priority, such that the order in which the elements are deleted and processed comes from the following rules: – An element with higher priority will be processed before any element with lower priority. – Two elements with the same priority will be processed in order in which they are add to the queue.
  • 20. Prepared by, Jesmin Akhter, Lecturer, IIT,JU One way list representation • Each node contains three items of information • A node X proceeds with a node Y in the list when – X has higher priority than Y or – Both has same priority but X was added in the list before Y. AAA 1 BBB 2 CCC 3 DDD 4 EEE 5 FFF 6 × Start PRN • Property: – First node will processed first