SlideShare une entreprise Scribd logo
1  sur  29
By Saliha Bilal
A binomial heap is a heap similar to a binary
heap but also supports quick merging of two
heaps.
A binomial heap is implemented as a
collection of binomial trees
A binomial heap is implemented as a collection
of binomial trees (compare with a binary heap,
which has a shape of a single binary tree).
A binomial tree is defined recursively:
A binomial tree of order 0 is a single node
A binomial tree of order k has a root node whose
children are roots of binomial trees of
orders k−1, k−2, ..., 2, 1, 0 (in this order).
Binary heap supports various operations
quickly:
extract-min, insert, decrease-key
If we already have two min-heaps, A and B,
there is no efficient way to combine them
into a single min-heap
•Introduce Binomial Heap
It can support efficient union operation
A data structure that supports the following 5
operations:
•Make-Heap( ) : return an empty heap
•Insert(H , x , k) : insert an item x with
key k into a heap H
•Find-Min(H) : return item with min key
•Extract-Min(H) : return and remove
•Union(H1, H2) : merge heaps H1 and H2
Examples:
Binomial Heap
Fibonacci Heap
Decrease-Key(H,x,k) : assign item x
with a smaller key k
Delete(H,x) : remove item x
Operation
↓
Binomial
heap
Make
heap
O(1)
Find
minimum
O(log n)
Extract
minimum
O(log n)
Insert
O(log n)
Delete
O(log n)
Decrease
key
O(log n)
Union
O(log n)
Binomial Heap
Unlike binary heap which consists of a
single tree, a binomial heap consists of a
small set of component trees
 no need to rebuild everything when
union is perform
Each component tree is in a special
format, called a binomial tree
Binomial tree
A binomial tree of order k, denoted
by
Bk, is defined recursively as follows:
B0 is a tree with a single node
For k ≥1, Bk is formed by joining
two
Bk-1, such that the root of one tree
becomes the leftmost child of the
root of the other
Binomial tree
B0
B1 B2
B3
B4
Properties of Binomial Tree
For a binomial tree Bk
There are 2k nodes
height = k
deg(root) = k ; deg(other node) ˂k
Children of root, from left to right,
are Bk-1, Bk-2, …, B1, B0
Binomial Heap
Binomial heap of n elements consists of a specific
set of binomial trees
Each binomial tree satisfies min-heap
ordering: for each node x,
key(x) ≥ key(parent(x))
For each k, at most one binomial tree
whose root has degree k
(i.e., for each k, at most one Bk)
Binomial heap with 13 elements
12 8
35
25 13
19
33
32
41
52
15
16
21
Binomial Heap Operations
With the binomial heap,
•Make-Heap( ): O(1) time
•Find-Min( ): O(log n) time
•Decrease-Key( ): O(log n) time
[ Decrease-Key assumes we have the pointer to
the item x in which its key is changed ]
•Remaining operations : Based on Union( )
Union Operation
•Let H1 and H2 be two binomial heaps
•To Union them, we process all binomial
trees in the two heaps with same order
together, starting with smaller order
first
•Let k be the order of the set of binomial
trees we currently process
There are three cases:
1. If there is only one Bk →done
2. If there are two Bk
→ Merge together, forming Bk+1
3. If there are three Bk
→ Leave one, merge remaining to Bk+1
After that, process next k
Union of two BH with 5 and 13 nodes
12
8
35
25 13 19
33
32
41 52
15
16
21
4
9
14 11
31
H1
H2
Union of two BH with 5 and 13 nodes
12
8
35
25 13 19
33
32
41 52
15
16
21
4
9
14 11
31
After processing
K=0
Union of two BH with 5 and 13 nodes
12 8
35
25 13
19
33
32
41
52
15
16
21
4
9
14 11
31
After processing
K=1,2
Union of two BH with 5 and 13 nodes
12
8
35
25 13
19
33
32 41
52
15
16
21
4
9
14 11
31
After processing
K=3
Binomial Heap Operations
So, Union( ) takes O(log n) time
For remaining operations,
Insert( ), Extract-Min( ), Delete( )
how can they be done with Union?
Insert(H, x, k):
→Create new heap H’, storing the item x
with key k; then, Union(H, H’)
Extract-Min(H):
→Find the tree Bj containing the min;
Detach Bj from H → forming a heap H1 ;
Remove root of Bj → forming a heap H2 ;
Finally, Union(H, H’)
Delete(H, x):
→Decrease-Key(H,x,-∞); Extract-Min(H);
Binomial Heap Operations
Extract- min (H)
Step1: select the tree Bj containing the min value
12 8
35
25 13
19
33
32
41
52
15
16
21
Bj with Min
Extract- min (H)
Step2: forming two heaps & extracting “8” from H2
12
8
35
25 13
19
33
32
41
52
15
16
21
H2
H1
Extract- min (H)
Step3: union of H1 and H2
12
35
25 13
19
33
32
41
52
15
16
21
Performance:
Insert a new element to the heap
Find the element with minimum key
Delete the element with minimum key from
the heap
Decrease key of a given element
Delete given element from the heap
Merge two given heaps to one heap
Finding the element with minimum key can
also be done in O(1) by using an additional
pointer to the minimum.
Applications:
Discrete event simulation
Priority queues
Binomial heap (a concept of Data Structure)

Contenu connexe

Tendances (7)

lecture 13
lecture 13lecture 13
lecture 13
 
Discrete assignment
Discrete assignmentDiscrete assignment
Discrete assignment
 
Day 7 examples u3f13
Day 7 examples u3f13Day 7 examples u3f13
Day 7 examples u3f13
 
Factoring by gcf part 1 2nd
Factoring by gcf part 1 2ndFactoring by gcf part 1 2nd
Factoring by gcf part 1 2nd
 
Quick leaning
Quick leaningQuick leaning
Quick leaning
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
Lagrange
LagrangeLagrange
Lagrange
 

En vedette (11)

Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
binomial & fibonaccci heap by priya
binomial & fibonaccci heap by priyabinomial & fibonaccci heap by priya
binomial & fibonaccci heap by priya
 
Fibonacci Heaps
Fibonacci Heaps Fibonacci Heaps
Fibonacci Heaps
 
Heap tree
Heap treeHeap tree
Heap tree
 
16 Fibonacci Heaps
16 Fibonacci Heaps16 Fibonacci Heaps
16 Fibonacci Heaps
 
Heapsort quick sort
Heapsort quick sortHeapsort quick sort
Heapsort quick sort
 
Heaps
HeapsHeaps
Heaps
 
Leftist heap
Leftist heapLeftist heap
Leftist heap
 
Fibonacci Heap
Fibonacci HeapFibonacci Heap
Fibonacci Heap
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Splay Tree
Splay TreeSplay Tree
Splay Tree
 

Dernier

What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Dernier (20)

What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

Binomial heap (a concept of Data Structure)

  • 2.
  • 3. A binomial heap is a heap similar to a binary heap but also supports quick merging of two heaps. A binomial heap is implemented as a collection of binomial trees
  • 4. A binomial heap is implemented as a collection of binomial trees (compare with a binary heap, which has a shape of a single binary tree). A binomial tree is defined recursively: A binomial tree of order 0 is a single node A binomial tree of order k has a root node whose children are roots of binomial trees of orders k−1, k−2, ..., 2, 1, 0 (in this order).
  • 5.
  • 6. Binary heap supports various operations quickly: extract-min, insert, decrease-key If we already have two min-heaps, A and B, there is no efficient way to combine them into a single min-heap •Introduce Binomial Heap It can support efficient union operation
  • 7. A data structure that supports the following 5 operations: •Make-Heap( ) : return an empty heap •Insert(H , x , k) : insert an item x with key k into a heap H •Find-Min(H) : return item with min key •Extract-Min(H) : return and remove •Union(H1, H2) : merge heaps H1 and H2
  • 8. Examples: Binomial Heap Fibonacci Heap Decrease-Key(H,x,k) : assign item x with a smaller key k Delete(H,x) : remove item x
  • 10. Binomial Heap Unlike binary heap which consists of a single tree, a binomial heap consists of a small set of component trees  no need to rebuild everything when union is perform Each component tree is in a special format, called a binomial tree
  • 11. Binomial tree A binomial tree of order k, denoted by Bk, is defined recursively as follows: B0 is a tree with a single node For k ≥1, Bk is formed by joining two Bk-1, such that the root of one tree becomes the leftmost child of the root of the other
  • 13. Properties of Binomial Tree For a binomial tree Bk There are 2k nodes height = k deg(root) = k ; deg(other node) ˂k Children of root, from left to right, are Bk-1, Bk-2, …, B1, B0
  • 14. Binomial Heap Binomial heap of n elements consists of a specific set of binomial trees Each binomial tree satisfies min-heap ordering: for each node x, key(x) ≥ key(parent(x)) For each k, at most one binomial tree whose root has degree k (i.e., for each k, at most one Bk)
  • 15. Binomial heap with 13 elements 12 8 35 25 13 19 33 32 41 52 15 16 21
  • 16. Binomial Heap Operations With the binomial heap, •Make-Heap( ): O(1) time •Find-Min( ): O(log n) time •Decrease-Key( ): O(log n) time [ Decrease-Key assumes we have the pointer to the item x in which its key is changed ] •Remaining operations : Based on Union( )
  • 17. Union Operation •Let H1 and H2 be two binomial heaps •To Union them, we process all binomial trees in the two heaps with same order together, starting with smaller order first •Let k be the order of the set of binomial trees we currently process There are three cases: 1. If there is only one Bk →done 2. If there are two Bk → Merge together, forming Bk+1 3. If there are three Bk → Leave one, merge remaining to Bk+1 After that, process next k
  • 18. Union of two BH with 5 and 13 nodes 12 8 35 25 13 19 33 32 41 52 15 16 21 4 9 14 11 31 H1 H2
  • 19. Union of two BH with 5 and 13 nodes 12 8 35 25 13 19 33 32 41 52 15 16 21 4 9 14 11 31 After processing K=0
  • 20. Union of two BH with 5 and 13 nodes 12 8 35 25 13 19 33 32 41 52 15 16 21 4 9 14 11 31 After processing K=1,2
  • 21. Union of two BH with 5 and 13 nodes 12 8 35 25 13 19 33 32 41 52 15 16 21 4 9 14 11 31 After processing K=3
  • 22. Binomial Heap Operations So, Union( ) takes O(log n) time For remaining operations, Insert( ), Extract-Min( ), Delete( ) how can they be done with Union? Insert(H, x, k): →Create new heap H’, storing the item x with key k; then, Union(H, H’)
  • 23. Extract-Min(H): →Find the tree Bj containing the min; Detach Bj from H → forming a heap H1 ; Remove root of Bj → forming a heap H2 ; Finally, Union(H, H’) Delete(H, x): →Decrease-Key(H,x,-∞); Extract-Min(H); Binomial Heap Operations
  • 24. Extract- min (H) Step1: select the tree Bj containing the min value 12 8 35 25 13 19 33 32 41 52 15 16 21 Bj with Min
  • 25. Extract- min (H) Step2: forming two heaps & extracting “8” from H2 12 8 35 25 13 19 33 32 41 52 15 16 21 H2 H1
  • 26. Extract- min (H) Step3: union of H1 and H2 12 35 25 13 19 33 32 41 52 15 16 21
  • 27. Performance: Insert a new element to the heap Find the element with minimum key Delete the element with minimum key from the heap Decrease key of a given element Delete given element from the heap Merge two given heaps to one heap Finding the element with minimum key can also be done in O(1) by using an additional pointer to the minimum.