SlideShare une entreprise Scribd logo
1  sur  23
 Queses:
 Array and list representation,
 Operations (traversal, insertion and deletion)
 Priority queues and Deques:
 Array and List representations
QUEUES
CONCEPT OF QUEUES
 A Queue is an ordered collection of items from which items may
be deleted at one end (called the front of the queue) and into
which items may be inserted at the other end (the rear of the
queue).
 The first element inserted into the queue is the first element to
be removed. For this reason a queue is sometimes called a FIFO
(first-in first-out) list as opposed to the stack, which is a LIFO
(last-in first-out).
Queue
items[MAXQUEUE-
1]
. .
. .
. .
items[2] C
items[1] B
items[0] A Front=0
Rear=2
Queue AS ABSTRACT DATA TYPE
A minimal set of operations on a queue is as follows:
1. create() — creates an empty queue, Q
2. add(i,Q) — adds the element i to the rear end of the
queue, Q and returns the new queue.
3. delete(Q) —takes out an element from the front end of
the queue and returns the resulting queue.
4. getFront(Q) — returns the element that is at the front
position of the queue.
5. Is_Empty(Q) — returns true if the queue is empty;
otherwise returns false
6. Is_Full(Q) — returns true if the queue is full; otherwise
returns false.
Insert an item A
 A new item (A) is inserted at the Rear of the queue
items[MAXQUEUE
-1]
. .
. .
items[3]
items[2]
items[1]
items[0] A Front=0,
Rear=0
Insert an item B
 A new item (B) is inserted at the Rear of the queue
items[MAXQUEUE
-1]
. .
. .
items[3]
items[2]
items[1] B Rear=1
items[0] A Front=0
Insert an item C
 A new item (C) is inserted at the Rear of the queue
items[MAXQUEUE
-1]
. .
. .
items[3]
items[2] C Rear=2
items[1] B
items[0] A Front=0
Insert an item D
 A new item (D) is inserted at the Rear of the queue
items[MAXQUEUE-
1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B
items[0] A Front=0
Insert Operation(Array)
QINSERT(QUEUE, N, FRONT, REAR, ITEM)
1. If FRONT = 1 and REAR =n , or FRONT = REAR + 1, then :
write OVERFLOW, and Return.
2. If FRONT = NULL, then:
Set FRONT := 1 and REAR := 1.
Else if REAR = n, then:
Set REAR := 1.
Else :
Set REAR := REAR + 1.
3. Set QUEUE[REAR]:= ITEM.
4. Return.
Delete A
 An item (A) is deleted from the Front of the queue
items[MAXQUEUE-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B Front=1
items[0] A
Delete B
 An item (B) is deleted from the Front of the queue.
items[MAXQUEUE-1]
. .
. .
items[3] D Rear=3
items[2] C Front=2
items[1] B
items[0] A
Delete C
 An item (C) is deleted from the Front of the queue
items[MAXQUEUE-1]
. .
. .
items[3] D Front=Rear=3
items[2] C
items[1] B
items[0] A
Delete D
 An item (A) is deleted from the Front of the queue.
items[MAXQUEUE-1]
. .
items[3] D Front=Rear=-1
items[2] C
items[1] B
items[0] A
Delete Operation(Array)
QDELETE(QUEUE, N, FRONT, REAR, ITEM)
1. If FRONT = NULL then :
write: UNDERFLOW, and Return.
2. Set ITEM := QUEUE[FRONT].
3. If FRONT = REAR,
Set FRONT := NULL and REAR := NULL
Else if FRONT = N, then:
Set FRONT := 1.
Else :
Set FRONT := FRONT + 1.
4. Return.
Insert Operation(LL)
LINKQ_INSERT(INFO, LINK, FRONT, REAR, AVAIL, ITEM)
1. If AVAIL = NULL, then :
write OVERFLOW, and Exit.
2. Set NEW := AVAIL and AVAIL := LINK[AVAIL]
3. Set INFO[NEW]:= ITEM and LINK[NEW]=NULL
4. If (FRONT = NULL), FRONT := REAR := NEW
Else set LINK[REAR] := NEW and REAR := NEW
5. Exit
Delete Operation(LL)
LINKQ_DELETE(INFO, LINK, FRONT, REAR, AVAIL, ITEM)
1. If FRONT = NULL, then :
write UNDERFLOW, and Exit.
2. Set TEMP := FRONT
3. Set ITEM :=INFO[TEMP]
4. FRONT :=LINK[TEMP]
5. LINK[TEMP] = AVAIL and AVAIL = TEMP
6. Exit
Deques(double-ended queue)
 It is a double-ended queue.
 The elements can be added or deleted at either the front
end or the rear end, but no changes can be made elsewhere
in the list.
1. EnqueueFront()—adds elements at the front end of
the queue.
2. EnqueueRear()—adds elements at the rear end of the
queue
3. DequeueFront()—deletes elements from the front end
of the queue
4. DequeueRear()—deletes elements from the rear end
of the queue
deque ADT
Applications of deque - Deque is useful where the data to be
stored has to be ordered, compact storage is needed, and the
retrieval of data elements has to be faster.
Variations of deque We can have two variations of a deque:
1. input-restricted deque - the input-restricted deque allows
insertions only at one end.
2. output-restricted deque - The output-restricted deque
allows deletions fom only one end.
Priority Queue
 A priority queue is a collection of a finite number of prioritized
elements. Priority queues are those in which we can insert or
delete elements from any position based on some fundamental
ordering of the elements.
 Elements can be inserted in any order in a priority queue, but
when an element is removed from the priority queue, it is
always the one with the highest priority.
 In other words 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 be removed is
decided by the priority of the element
 The following rules are applied to maintain a priority
queue:
1. The element with a higher priority is processed before
any element of lower priority.
2. If there were elements with the same priority, then the
element added first in the queue would get processed
first.
 implementing job scheduling by the operating system
 simulation systems where the priority corresponds to
event times.
 A list of patients in an emergency room; each patient
might be given a ranking.
 A list of jobs carried out by a multitasking operating
system; each background job is given a priority level.
Application
Thank You

Contenu connexe

Similaire à Queues.ppt

Similaire à Queues.ppt (20)

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
Queue
QueueQueue
Queue
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Queue - Operations and Implementations
Queue - Operations and ImplementationsQueue - Operations and Implementations
Queue - Operations and Implementations
 
Queue
QueueQueue
Queue
 
Queue data structures and operation on data structures
Queue data structures and operation on data structuresQueue data structures and operation on data structures
Queue data structures and operation on data structures
 
2.1 Queue.pptx
2.1 Queue.pptx2.1 Queue.pptx
2.1 Queue.pptx
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
Computer Engineering Data Structure Queue.pptx
Computer Engineering Data Structure Queue.pptxComputer Engineering Data Structure Queue.pptx
Computer Engineering Data Structure Queue.pptx
 

Dernier

Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 

Dernier (20)

Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 

Queues.ppt

  • 1.  Queses:  Array and list representation,  Operations (traversal, insertion and deletion)  Priority queues and Deques:  Array and List representations QUEUES
  • 2. CONCEPT OF QUEUES  A Queue is an ordered collection of items from which items may be deleted at one end (called the front of the queue) and into which items may be inserted at the other end (the rear of the queue).  The first element inserted into the queue is the first element to be removed. For this reason a queue is sometimes called a FIFO (first-in first-out) list as opposed to the stack, which is a LIFO (last-in first-out).
  • 3. Queue items[MAXQUEUE- 1] . . . . . . items[2] C items[1] B items[0] A Front=0 Rear=2
  • 4. Queue AS ABSTRACT DATA TYPE A minimal set of operations on a queue is as follows: 1. create() — creates an empty queue, Q 2. add(i,Q) — adds the element i to the rear end of the queue, Q and returns the new queue. 3. delete(Q) —takes out an element from the front end of the queue and returns the resulting queue. 4. getFront(Q) — returns the element that is at the front position of the queue. 5. Is_Empty(Q) — returns true if the queue is empty; otherwise returns false 6. Is_Full(Q) — returns true if the queue is full; otherwise returns false.
  • 5. Insert an item A  A new item (A) is inserted at the Rear of the queue items[MAXQUEUE -1] . . . . items[3] items[2] items[1] items[0] A Front=0, Rear=0
  • 6. Insert an item B  A new item (B) is inserted at the Rear of the queue items[MAXQUEUE -1] . . . . items[3] items[2] items[1] B Rear=1 items[0] A Front=0
  • 7. Insert an item C  A new item (C) is inserted at the Rear of the queue items[MAXQUEUE -1] . . . . items[3] items[2] C Rear=2 items[1] B items[0] A Front=0
  • 8. Insert an item D  A new item (D) is inserted at the Rear of the queue items[MAXQUEUE- 1] . . . . items[3] D Rear=3 items[2] C items[1] B items[0] A Front=0
  • 9. Insert Operation(Array) QINSERT(QUEUE, N, FRONT, REAR, ITEM) 1. If FRONT = 1 and REAR =n , or FRONT = REAR + 1, then : write OVERFLOW, and Return. 2. If FRONT = NULL, then: Set FRONT := 1 and REAR := 1. Else if REAR = n, then: Set REAR := 1. Else : Set REAR := REAR + 1. 3. Set QUEUE[REAR]:= ITEM. 4. Return.
  • 10. Delete A  An item (A) is deleted from the Front of the queue items[MAXQUEUE-1] . . . . items[3] D Rear=3 items[2] C items[1] B Front=1 items[0] A
  • 11. Delete B  An item (B) is deleted from the Front of the queue. items[MAXQUEUE-1] . . . . items[3] D Rear=3 items[2] C Front=2 items[1] B items[0] A
  • 12. Delete C  An item (C) is deleted from the Front of the queue items[MAXQUEUE-1] . . . . items[3] D Front=Rear=3 items[2] C items[1] B items[0] A
  • 13. Delete D  An item (A) is deleted from the Front of the queue. items[MAXQUEUE-1] . . items[3] D Front=Rear=-1 items[2] C items[1] B items[0] A
  • 14. Delete Operation(Array) QDELETE(QUEUE, N, FRONT, REAR, ITEM) 1. If FRONT = NULL then : write: UNDERFLOW, and Return. 2. Set ITEM := QUEUE[FRONT]. 3. If FRONT = REAR, Set FRONT := NULL and REAR := NULL Else if FRONT = N, then: Set FRONT := 1. Else : Set FRONT := FRONT + 1. 4. Return.
  • 15. Insert Operation(LL) LINKQ_INSERT(INFO, LINK, FRONT, REAR, AVAIL, ITEM) 1. If AVAIL = NULL, then : write OVERFLOW, and Exit. 2. Set NEW := AVAIL and AVAIL := LINK[AVAIL] 3. Set INFO[NEW]:= ITEM and LINK[NEW]=NULL 4. If (FRONT = NULL), FRONT := REAR := NEW Else set LINK[REAR] := NEW and REAR := NEW 5. Exit
  • 16. Delete Operation(LL) LINKQ_DELETE(INFO, LINK, FRONT, REAR, AVAIL, ITEM) 1. If FRONT = NULL, then : write UNDERFLOW, and Exit. 2. Set TEMP := FRONT 3. Set ITEM :=INFO[TEMP] 4. FRONT :=LINK[TEMP] 5. LINK[TEMP] = AVAIL and AVAIL = TEMP 6. Exit
  • 17. Deques(double-ended queue)  It is a double-ended queue.  The elements can be added or deleted at either the front end or the rear end, but no changes can be made elsewhere in the list.
  • 18. 1. EnqueueFront()—adds elements at the front end of the queue. 2. EnqueueRear()—adds elements at the rear end of the queue 3. DequeueFront()—deletes elements from the front end of the queue 4. DequeueRear()—deletes elements from the rear end of the queue deque ADT
  • 19. Applications of deque - Deque is useful where the data to be stored has to be ordered, compact storage is needed, and the retrieval of data elements has to be faster. Variations of deque We can have two variations of a deque: 1. input-restricted deque - the input-restricted deque allows insertions only at one end. 2. output-restricted deque - The output-restricted deque allows deletions fom only one end.
  • 20. Priority Queue  A priority queue is a collection of a finite number of prioritized elements. Priority queues are those in which we can insert or delete elements from any position based on some fundamental ordering of the elements.  Elements can be inserted in any order in a priority queue, but when an element is removed from the priority queue, it is always the one with the highest priority.  In other words 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 be removed is decided by the priority of the element
  • 21.  The following rules are applied to maintain a priority queue: 1. The element with a higher priority is processed before any element of lower priority. 2. If there were elements with the same priority, then the element added first in the queue would get processed first.
  • 22.  implementing job scheduling by the operating system  simulation systems where the priority corresponds to event times.  A list of patients in an emergency room; each patient might be given a ranking.  A list of jobs carried out by a multitasking operating system; each background job is given a priority level. Application