SlideShare a Scribd company logo
PRIORITY QUEUE
PRESENTED BY
Maneesh Kumar Jamwal
PRIORITY QUEUE
• Definition
• Simple Implementation
• Binary Heap-Structure Property
• Heap Order Property
• Basic Heap Operation
• Application Of Priority Queues
• d-Heaps
• References
Def:- A Priority Queue is a collection of Elements such that
Each element has been assigned a priority and such that is
the order in which the elements are deleted and processed
From the following rules:-
• An Element of higher priority is processed before any
element of lower priority.
• Two elements with the same priority are processed
According to the order in which they were added to the
queue.
• Any Data Structure that supports the operations of
search of min or max, insert and delete min or max
respectively is called a priority queue.
• Example:-Suppose that we are selling the services of a
machine. Each user pays a fixed amount per use.
However, the time needed by each user is different. We
wish to maximize the returns from this machine under
the assumption that the machine is not to be kept idle
unless no user is available. This can be done by
maintaining a priority queue of all persons waiting to
use the machine. Whenever the machine is available,
the user with the smallest time requirement will be
selected. Hence a priority queue that supports delete
min is required. When a new user requests the
machine, his or her request is put into the priority
queue.
If each user needs the same amount of time on the
machine but people are willing to pay different amounts for
the service, then the priority queue based on the
amount of payment can be maintained. Whenever the
machine becomes available, the user willing to pay the
most is selected. This requires a delete max operation.
Model of Priority Queue:-
Simple general diagram of the
Priority queue is as shown.
Whenever an element is inserted
into queue, priority Queue inserts
the item according to its order.
Here we're assuming that data
with high value has
low priority
Basic Operations on priority Queues:-
• Insert or enqueue:−This operation will add an
item to the rear of the queue.
• Delete or Dequeue:-This operation will remove
an item from the front of the queue.
• Peek − This operation will performed to get the
element at front of the queue.
• isFull − check if queue is full.
• isEmpty − check if queue is empty.
Binary Heap
A binary heap is a heap data structure that takes the
form of a binary tree. Binary heaps are a common
way of implementing priority queues.
A binary heap is defined as a binary tree with two
additional constraints:
1.Shape property:- a binary heap is a complete
binary tree that is, all levels of the tree, except
possibly the last one (deepest) are fully filled,
and, if the last level of the tree is not complete,
the nodes of that level are filled from left to right.
2.Heap property: the key stored in each node is
either greater than or equal to (≥) or less than or
equal to (≤) the keys in the node's children,
according to some total order.
Heaps where the parent key is greater than or
equal to (≥) the child keys are called max-heaps;
those where it is less than or equal to (≤) are
called min-heaps.
Figure shows :- Example of a complete binary max heap
Example of a complete binary min heap
QN:-What is heap order property?
Ans:-A binary heap is a complete binary tree
which satisfies the heap ordering property.
The ordering can be one of two types:
1 min-heap property: the value of each node
is greater than or equal to the value of its
parent, with the minimum-value element at
the root.
2. max-heap property: the value of each node
is less than or equal to the value of its parent,
with the maximum-value element at the root.
Basic Heap Operation
The common operations are:
• Basic operations:-
 Find-max (or find-min): find a maximum item of a
max-heap, or a minimum item of a min-heap,
respectively(peek operation) .
 insert: adding a new key to the heap (push ).
 extract-max (or extract-min): returns the node of
maximum value from a max heap [or minimum value
from a min heap] after removing it from the heap (pop
operation).
 delete-max (or delete-min): removing the root
node of a max heap (or min heap), respectively.
replace: pop root and push a new key. More efficient than
pop followed by push, since only need to balance once, not
twice, and appropriate for fixed-size heaps.
• Creation operations:-
create-heap: This operation creates an empty heap.
merge (union):This operation joining two heaps to
form a valid new heap containing all the elements of both,
preserving the original heaps.
heapify: create a heap out of given array of elements.
• Inspection operations:-
 size: return the number of items in the heap.
 is-empty: return true if the heap is empty,
 false otherwise.
• Internal operations:-
 increase-key or decrease-key: updating a key within
a max- or min-heap, respectively.
 delete: delete an arbitrary node.
 sift-up: move a node up in the tree, as long as needed;
used to restore heap condition after insertion.
sift-down: move a node down in the tree, similar to
sift-up; used to restore heap condition after deletion or
replacement.
Application Of Priority Queues:-
 A* search algorithm implementation can be done using
Priority queues.
 Priority queues are used for load balancing and
interrupt handling.
 Priority queues are used for Huffman codes for data
compression.
 In traffic light, depending upon the traffic, the color will
be given priority.
 Dijkstra’s shortest path algorithm using priority queue
when the graph is stored in the form of adjacency list or
matrix, priority queue can be used to extract minimum
efficiency when implementing Dijkstra’s algorithms.
 Prims algorithms implementation can be done using
Priority queue & also used to sort heaps.
d-array heap:-The d-ary heap or d-heap is a priority
queue data structure, a generalization of the binary heap in
which the nodes have d children instead of 2. Thus, a binary
heap is a 2-heap, and a ternary heap is a 3-heap.
References:-
1.wikipedia.
2.Data Structures by Seymour lipschutz.
3.Fundamentals of Data Structures by Sartaj Sahini
4.World wide web.
Thank You

More Related Content

What's hot

Heap sort
Heap sortHeap sort
Heap sort
Shayshab Azad
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
LavanyaJ28
 
In class, we discussed min-heaps. In a min-heap the element of the heap with ...
In class, we discussed min-heaps. In a min-heap the element of the heap with ...In class, we discussed min-heaps. In a min-heap the element of the heap with ...
In class, we discussed min-heaps. In a min-heap the element of the heap with ...
licservernoida
 
3.7 heap sort
3.7 heap sort3.7 heap sort
3.7 heap sort
Krish_ver2
 
Heapsort ppt
Heapsort pptHeapsort ppt
Heapsort ppt
Mariam Saeed
 
Heap
HeapHeap
NUS-ISS Learning Day 2019-Pandas in the cloud
NUS-ISS Learning Day 2019-Pandas in the cloudNUS-ISS Learning Day 2019-Pandas in the cloud
NUS-ISS Learning Day 2019-Pandas in the cloud
NUS-ISS
 
Cascading talk in Etsy (http://www.meetup.com/cascading/events/169390262/)
Cascading talk in Etsy (http://www.meetup.com/cascading/events/169390262/)Cascading talk in Etsy (http://www.meetup.com/cascading/events/169390262/)
Cascading talk in Etsy (http://www.meetup.com/cascading/events/169390262/)
Jyotirmoy Sundi
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
Lemia Algmri
 
Climate data in r with the raster package
Climate data in r with the raster packageClimate data in r with the raster package
Climate data in r with the raster package
Alberto Labarga
 
MBrace: Large-scale cloud computation with F# (CUFP 2014)
MBrace: Large-scale cloud computation with F# (CUFP 2014)MBrace: Large-scale cloud computation with F# (CUFP 2014)
MBrace: Large-scale cloud computation with F# (CUFP 2014)
Eirik George Tsarpalis
 
MBrace: Cloud Computing with F#
MBrace: Cloud Computing with F#MBrace: Cloud Computing with F#
MBrace: Cloud Computing with F#
Eirik George Tsarpalis
 
Snabb - A toolkit for user-space networking (FOSDEM 2018)
Snabb - A toolkit for user-space networking (FOSDEM 2018)Snabb - A toolkit for user-space networking (FOSDEM 2018)
Snabb - A toolkit for user-space networking (FOSDEM 2018)
Igalia
 
Python library
Python libraryPython library
Python library
ToniyaP1
 
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
Junghoon Kim
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
InfluxData
 
Stack and heap
Stack and heapStack and heap
Bloom filters
Bloom filtersBloom filters
Bloom filters
🌎 Berkay Dinçer
 
150970116028 2140705
150970116028 2140705150970116028 2140705
150970116028 2140705
Manoj Shahu
 
5 Coding Hacks to Reduce GC Overhead
5 Coding Hacks to Reduce GC Overhead5 Coding Hacks to Reduce GC Overhead
5 Coding Hacks to Reduce GC Overhead
Takipi
 

What's hot (20)

Heap sort
Heap sortHeap sort
Heap sort
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
In class, we discussed min-heaps. In a min-heap the element of the heap with ...
In class, we discussed min-heaps. In a min-heap the element of the heap with ...In class, we discussed min-heaps. In a min-heap the element of the heap with ...
In class, we discussed min-heaps. In a min-heap the element of the heap with ...
 
3.7 heap sort
3.7 heap sort3.7 heap sort
3.7 heap sort
 
Heapsort ppt
Heapsort pptHeapsort ppt
Heapsort ppt
 
Heap
HeapHeap
Heap
 
NUS-ISS Learning Day 2019-Pandas in the cloud
NUS-ISS Learning Day 2019-Pandas in the cloudNUS-ISS Learning Day 2019-Pandas in the cloud
NUS-ISS Learning Day 2019-Pandas in the cloud
 
Cascading talk in Etsy (http://www.meetup.com/cascading/events/169390262/)
Cascading talk in Etsy (http://www.meetup.com/cascading/events/169390262/)Cascading talk in Etsy (http://www.meetup.com/cascading/events/169390262/)
Cascading talk in Etsy (http://www.meetup.com/cascading/events/169390262/)
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Climate data in r with the raster package
Climate data in r with the raster packageClimate data in r with the raster package
Climate data in r with the raster package
 
MBrace: Large-scale cloud computation with F# (CUFP 2014)
MBrace: Large-scale cloud computation with F# (CUFP 2014)MBrace: Large-scale cloud computation with F# (CUFP 2014)
MBrace: Large-scale cloud computation with F# (CUFP 2014)
 
MBrace: Cloud Computing with F#
MBrace: Cloud Computing with F#MBrace: Cloud Computing with F#
MBrace: Cloud Computing with F#
 
Snabb - A toolkit for user-space networking (FOSDEM 2018)
Snabb - A toolkit for user-space networking (FOSDEM 2018)Snabb - A toolkit for user-space networking (FOSDEM 2018)
Snabb - A toolkit for user-space networking (FOSDEM 2018)
 
Python library
Python libraryPython library
Python library
 
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
 
Stack and heap
Stack and heapStack and heap
Stack and heap
 
Bloom filters
Bloom filtersBloom filters
Bloom filters
 
150970116028 2140705
150970116028 2140705150970116028 2140705
150970116028 2140705
 
5 Coding Hacks to Reduce GC Overhead
5 Coding Hacks to Reduce GC Overhead5 Coding Hacks to Reduce GC Overhead
5 Coding Hacks to Reduce GC Overhead
 

Similar to Priority queue

Stacks
StacksStacks
Stacks
Acad
 
Heaps
HeapsHeaps
Heap Sort 1053.pptx
Heap Sort 1053.pptxHeap Sort 1053.pptx
Heap Sort 1053.pptx
ZainiXh
 
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdfComplete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
americanopticalscbe
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
Dr.Shweta
 
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
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
LavanyaJ28
 
PriorityqDhruvBaswal.pptx
PriorityqDhruvBaswal.pptxPriorityqDhruvBaswal.pptx
PriorityqDhruvBaswal.pptx
ssuser17c9c21
 
Queues
QueuesQueues
Mathemetics module
Mathemetics moduleMathemetics module
Mathemetics module
manikanta361
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
LECO9
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
SKUP1
 
6 module 4
6 module 46 module 4
6 module 4
tafosepsdfasg
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
mayankKatiyar17
 
Data Structures
Data StructuresData Structures
Data Structures
Dr.Umadevi V
 
UNIT-2.pptx
UNIT-2.pptxUNIT-2.pptx
UNIT-2.pptx
ChiragSuresh
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
iqbalphy1
 
05-stack_queue.ppt
05-stack_queue.ppt05-stack_queue.ppt
05-stack_queue.ppt
Sarojkumari55
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
abinathsabi
 
Machine learning Module-2, 6th Semester Elective
Machine learning Module-2, 6th Semester ElectiveMachine learning Module-2, 6th Semester Elective
Machine learning Module-2, 6th Semester Elective
MayuraD1
 

Similar to Priority queue (20)

Stacks
StacksStacks
Stacks
 
Heaps
HeapsHeaps
Heaps
 
Heap Sort 1053.pptx
Heap Sort 1053.pptxHeap Sort 1053.pptx
Heap Sort 1053.pptx
 
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdfComplete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
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)
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
PriorityqDhruvBaswal.pptx
PriorityqDhruvBaswal.pptxPriorityqDhruvBaswal.pptx
PriorityqDhruvBaswal.pptx
 
Queues
QueuesQueues
Queues
 
Mathemetics module
Mathemetics moduleMathemetics module
Mathemetics module
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
6 module 4
6 module 46 module 4
6 module 4
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
Data Structures
Data StructuresData Structures
Data Structures
 
UNIT-2.pptx
UNIT-2.pptxUNIT-2.pptx
UNIT-2.pptx
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
05-stack_queue.ppt
05-stack_queue.ppt05-stack_queue.ppt
05-stack_queue.ppt
 
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
 
Machine learning Module-2, 6th Semester Elective
Machine learning Module-2, 6th Semester ElectiveMachine learning Module-2, 6th Semester Elective
Machine learning Module-2, 6th Semester Elective
 

Recently uploaded

2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
bjmsejournal
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
ramrag33
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
Madan Karki
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
IJECEIAES
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
gaafergoudaay7aga
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 

Recently uploaded (20)

2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 

Priority queue

  • 2. PRIORITY QUEUE • Definition • Simple Implementation • Binary Heap-Structure Property • Heap Order Property • Basic Heap Operation • Application Of Priority Queues • d-Heaps • References
  • 3. Def:- A Priority Queue is a collection of Elements such that Each element has been assigned a priority and such that is the order in which the elements are deleted and processed From the following rules:- • An Element of higher priority is processed before any element of lower priority. • Two elements with the same priority are processed According to the order in which they were added to the queue. • Any Data Structure that supports the operations of search of min or max, insert and delete min or max respectively is called a priority queue.
  • 4. • Example:-Suppose that we are selling the services of a machine. Each user pays a fixed amount per use. However, the time needed by each user is different. We wish to maximize the returns from this machine under the assumption that the machine is not to be kept idle unless no user is available. This can be done by maintaining a priority queue of all persons waiting to use the machine. Whenever the machine is available, the user with the smallest time requirement will be selected. Hence a priority queue that supports delete min is required. When a new user requests the machine, his or her request is put into the priority queue. If each user needs the same amount of time on the machine but people are willing to pay different amounts for
  • 5. the service, then the priority queue based on the amount of payment can be maintained. Whenever the machine becomes available, the user willing to pay the most is selected. This requires a delete max operation. Model of Priority Queue:- Simple general diagram of the Priority queue is as shown. Whenever an element is inserted into queue, priority Queue inserts the item according to its order. Here we're assuming that data with high value has low priority
  • 6. Basic Operations on priority Queues:- • Insert or enqueue:−This operation will add an item to the rear of the queue. • Delete or Dequeue:-This operation will remove an item from the front of the queue. • Peek − This operation will performed to get the element at front of the queue. • isFull − check if queue is full. • isEmpty − check if queue is empty.
  • 7. Binary Heap A binary heap is a heap data structure that takes the form of a binary tree. Binary heaps are a common way of implementing priority queues. A binary heap is defined as a binary tree with two additional constraints: 1.Shape property:- a binary heap is a complete binary tree that is, all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.
  • 8. 2.Heap property: the key stored in each node is either greater than or equal to (≥) or less than or equal to (≤) the keys in the node's children, according to some total order. Heaps where the parent key is greater than or equal to (≥) the child keys are called max-heaps; those where it is less than or equal to (≤) are called min-heaps.
  • 9. Figure shows :- Example of a complete binary max heap
  • 10. Example of a complete binary min heap
  • 11. QN:-What is heap order property? Ans:-A binary heap is a complete binary tree which satisfies the heap ordering property. The ordering can be one of two types: 1 min-heap property: the value of each node is greater than or equal to the value of its parent, with the minimum-value element at the root. 2. max-heap property: the value of each node is less than or equal to the value of its parent, with the maximum-value element at the root.
  • 12. Basic Heap Operation The common operations are: • Basic operations:-  Find-max (or find-min): find a maximum item of a max-heap, or a minimum item of a min-heap, respectively(peek operation) .  insert: adding a new key to the heap (push ).  extract-max (or extract-min): returns the node of maximum value from a max heap [or minimum value from a min heap] after removing it from the heap (pop operation).  delete-max (or delete-min): removing the root node of a max heap (or min heap), respectively.
  • 13. replace: pop root and push a new key. More efficient than pop followed by push, since only need to balance once, not twice, and appropriate for fixed-size heaps. • Creation operations:- create-heap: This operation creates an empty heap. merge (union):This operation joining two heaps to form a valid new heap containing all the elements of both, preserving the original heaps. heapify: create a heap out of given array of elements.
  • 14. • Inspection operations:-  size: return the number of items in the heap.  is-empty: return true if the heap is empty,  false otherwise. • Internal operations:-  increase-key or decrease-key: updating a key within a max- or min-heap, respectively.  delete: delete an arbitrary node.  sift-up: move a node up in the tree, as long as needed; used to restore heap condition after insertion. sift-down: move a node down in the tree, similar to sift-up; used to restore heap condition after deletion or replacement.
  • 15. Application Of Priority Queues:-  A* search algorithm implementation can be done using Priority queues.  Priority queues are used for load balancing and interrupt handling.  Priority queues are used for Huffman codes for data compression.  In traffic light, depending upon the traffic, the color will be given priority.  Dijkstra’s shortest path algorithm using priority queue when the graph is stored in the form of adjacency list or matrix, priority queue can be used to extract minimum efficiency when implementing Dijkstra’s algorithms.  Prims algorithms implementation can be done using Priority queue & also used to sort heaps.
  • 16. d-array heap:-The d-ary heap or d-heap is a priority queue data structure, a generalization of the binary heap in which the nodes have d children instead of 2. Thus, a binary heap is a 2-heap, and a ternary heap is a 3-heap. References:- 1.wikipedia. 2.Data Structures by Seymour lipschutz. 3.Fundamentals of Data Structures by Sartaj Sahini 4.World wide web.