SlideShare a Scribd company logo
Binomial Heaps
Referred to “MIT Press: Introduction to Algorithms 2nd
Edition”
Binomial Trees
• The binomial tree B(k) is an ordered tree defined recursively. As
shown in the binomial tree B(0) consists of a single node. The binomial
tree B(k) consists of two binomial trees B(k-1) that are linked together:
the root of one is the leftmost child of the root of the other.
Properties of binomial trees
For the binomial tree B(k),
• 1. there are 2^k nodes,
• 2. the height of the tree is k,
• 3. there are exactly k!/(i!(k-i)!) nodes at depth i for i = 0, 1,
..., k, and
• 4. the root has degree k, which is greater than that of any
other node; moreover if i the children of the root are
numbered from left to right by k - 1, k - 2, ..., 0, child i is
the root of a subtree B(i).
Binomial Heaps
A binomial heap H is a set of binomial trees that satisfies the following
binomial-heap properties.
• 1. Each binomial tree in H obeys the min-heap property: the key of a
node is greater than or equal to the key of its parent. We say that each
such tree is min-heap-ordered.
• 2. For any nonnegative integer k, there is at most one binomial tree in
H whose root has degree k.
Representing binomial heaps
Creating a new binomial heap
• To make an empty binomial heap, the MAKE-BINOMIAL-HEAP
procedure simply allocates and returns an object H , where head[H ] =
NIL. The running time is Θ(1).
Finding the minimum key
• The procedure BINOMIAL-HEAP-MINIMUM returns a pointer to the
node with the minimum key in an n-node binomial heap H. This
implementation assumes that there are no keys with value ∞.
BINOMIAL-HEAP-MINIMUM(H)
1 y ← NIL
2 x ← head[H]
3 min ← ∞
4 while x ≠ NIL
5 do if key[x] < min
6 then min ← key[x]
7 y ← x
8 x ← sibling[x]
9 return y
Uniting two binomial heaps
• The BINOMIAL-HEAP-UNION procedure repeatedly
links binomial trees whose roots have the same degree.
The following procedure links the B(k-1) tree rooted at
node y to the B(k-1) tree rooted at node z; that is, it makes z
the parent of y. Node z thus becomes the root of a B(k)
tree.
BINOMIAL-LINK(y, z)
1 p[y] ← z
2 sibling[y] ← child[z]
3 child[z] ← y
4 degree[z] ← degree[z] + 1
The following procedure unites binomial heaps H1 and H2, returning the
resulting heap. It destroys the representations of H1 and H2 in the
process. Besides BINOMIAL-LINK, the procedure uses an auxiliary
procedure BINOMIAL-HEAP-MERGE that merges the root lists of
H1 and H2 into a single linked list that is sorted by degree into
monotonically increasing order.
BINOMIAL-HEAP-UNION(H1, H2)
1 H ← MAKE-BINOMIAL-HEAP()
2 head[H] ← BINOMIAL-HEAP-MERGE(H1, H2)
3 free the objects H1 and H2 but not the lists they
point to
4 if head[H] = NIL
5 then return H
6 prev-x ← NIL
7 x ← head[H]
8 next-x ← sibling[x]
9 while next-x ≠ NIL
10 do if (degree[x] ≠ degree[next-x]) or
(sibling[next-x] ≠ NIL and
degree[sibling[next-x]] =degree[x] )
11 then prev-x ← x ▹ Cases 1 and 2
12 x ← next-x ▹ Cases 1 and
2(see the figure 2, 5)
13 else if key[x] ≤ key[next-x]
14 then sibling[x] ← sibling[next-x]
▹ Case 3
15 BINOMIAL-
LINK(next-x, x) ▹ Case 3 (1, 4)
16 else if prev-x = NIL ▹ Case 4
17 then head[H] ←
next-x ▹ Case 4
18 else sibling[prev-
x] ← next-x ▹ Case 4
19 BINOMIAL-LINK(x,
next-x) ▹ Case 4
• back
• back
• back
• back
• back
Inserting a node
• The following procedure inserts node x into binomial heap H ,
assuming that x has already been allocated and key[x] has already been
filled in.
BINOMIAL-HEAP-INSERT(H, x)
1 H′ ← MAKE-BINOMIAL-HEAP()
2 p[x] ← NIL
3 child[x] ← NIL
4 sibling[x] ← NIL
5 degree[x] ← 0
6 head[H′] ← x
7 H ← BINOMIAL-HEAP-UNION(H, H′)
Extracting the node with the minimum key
• The following procedure extracts the node with the minimum key
from binomial heap H and returns a pointer to the extracted node.
BINOMIAL-HEAP-EXTRACT-MIN(H)
1 find the root x with the minimum key in
the root list of H,
and remove x from the root list of H
(see the figure)
2 H′ ← MAKE-BINOMIAL-HEAP()
3 reverse the order of the linked list of
x's children,
and set head[H′] to point to the head
of the resulting list (see the figure)
4 H ← BINOMIAL-HEAP-UNION(H, H′)
5 return x
• back
• back
Decreasing a key
• The following procedure decreases the key of a node x in a binomial
heap H to a new value k. It signals an error if k is greater than x's
current key.
BINOMIAL-HEAP-DECREASE-KEY(H, x, k)
1 if k > key[x]
2 then error "new key is greater than current
key"
3 key[x] ← k
4 y ← x
5 z ← p[y]
6 while z ≠ NIL and key[y] < key[z]
7 do exchange key[y] ↔ key[z]
8 ▸ If y and z have satellite fields, exchange
them, too.
9 y ← z
10 z ← p[y]
(see the figure)
• back
Deleting a key
• It is easy to delete a node x's key and satellite information from
binomial heap H in O(lg n) time. The following implementation
assumes that no node currently in the binomial heap has a key of -∞.
BINOMIAL-HEAP-DELETE(H, x)
1 BINOMIAL-HEAP-DECREASE-KEY(H, x, -∞)
2 BINOMIAL-HEAP-EXTRACT-MIN(H)
Exercise 1
Draw the result after inserting nodes with
integer keys from 1 through 15 into an
empty binomial heap in reverse order.
Exercise 2
Draw the result after deleting the node with
key 8 from the final binomial heap in
exercise 1.
Solution to exercise 1
Solution to exercise 2

More Related Content

What's hot

heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
Lemia Algmri
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Albin562191
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Avl trees final
Avl trees finalAvl trees final
Avl trees final
PRAKASH RANJAN SINGH
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
Masud Parvaze
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
Hossain Md Shakhawat
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
Anand Ingle
 
stack & queue
stack & queuestack & queue
stack & queue
manju rani
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
Intro C# Book
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
Soumen Santra
 
linked list
linked list linked list
linked list
Mohaimin Rahat
 
Huffman coding
Huffman coding Huffman coding
Huffman coding
Nazmul Hyder
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
Sum of subset problem.pptx
Sum of subset problem.pptxSum of subset problem.pptx
Sum of subset problem.pptx
V.V.Vanniaperumal College for Women
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Abrish06
 

What's hot (20)

heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Avl trees final
Avl trees finalAvl trees final
Avl trees final
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
 
stack & queue
stack & queuestack & queue
stack & queue
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
linked list
linked list linked list
linked list
 
Huffman coding
Huffman coding Huffman coding
Huffman coding
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
 
Sum of subset problem.pptx
Sum of subset problem.pptxSum of subset problem.pptx
Sum of subset problem.pptx
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Lecture24
Lecture24Lecture24
Lecture24
 

Similar to Binomial heaps

Applications of datastructures
Applications of datastructuresApplications of datastructures
Applications of datastructures
Ratsietsi Mokete
 
Binomial heap (a concept of Data Structure)
Binomial heap (a concept of Data Structure)Binomial heap (a concept of Data Structure)
Binomial heap (a concept of Data Structure)
Saliha Bilal
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructuresHitesh Wagle
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructuresHitesh Wagle
 
b-tree.ppt
b-tree.pptb-tree.ppt
b-tree.ppt
SyedAhsan232061
 
358 33 powerpoint-slides_12-heaps_chapter-12
358 33 powerpoint-slides_12-heaps_chapter-12358 33 powerpoint-slides_12-heaps_chapter-12
358 33 powerpoint-slides_12-heaps_chapter-12
sumitbardhan
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
AdityaK92
 
CS-102 BT_24_3_14 Binary Tree Lectures.pdf
CS-102 BT_24_3_14 Binary Tree Lectures.pdfCS-102 BT_24_3_14 Binary Tree Lectures.pdf
CS-102 BT_24_3_14 Binary Tree Lectures.pdf
ssuser034ce1
 
15-btrees.ppt
15-btrees.ppt15-btrees.ppt
15-btrees.ppt
plagcheck
 
Red black trees
Red black treesRed black trees
Red black trees
Amit Kumar Rathi
 
Recursion
RecursionRecursion
Recursion
Syed Zaid Irshad
 
Trees
TreesTrees
C12 bst
C12 bstC12 bst
Fileprocessing lec-7
Fileprocessing lec-7Fileprocessing lec-7
Fileprocessing lec-7
sawsan slii
 
BST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptx
BST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptxBST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptx
BST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptx
ssuser7b7f4e
 
Binomial Heap DAA PPT (2).ppt
Binomial Heap DAA PPT (2).pptBinomial Heap DAA PPT (2).ppt
Binomial Heap DAA PPT (2).ppt
Azad988896
 
UNIT II.ppt
UNIT II.pptUNIT II.ppt
UNIT II.ppt
SwarndeviKm
 

Similar to Binomial heaps (20)

Applications of datastructures
Applications of datastructuresApplications of datastructures
Applications of datastructures
 
Binomial heap (a concept of Data Structure)
Binomial heap (a concept of Data Structure)Binomial heap (a concept of Data Structure)
Binomial heap (a concept of Data Structure)
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructures
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructures
 
Heaps 4up
Heaps 4upHeaps 4up
Heaps 4up
 
b-tree.ppt
b-tree.pptb-tree.ppt
b-tree.ppt
 
358 33 powerpoint-slides_12-heaps_chapter-12
358 33 powerpoint-slides_12-heaps_chapter-12358 33 powerpoint-slides_12-heaps_chapter-12
358 33 powerpoint-slides_12-heaps_chapter-12
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
CS-102 BT_24_3_14 Binary Tree Lectures.pdf
CS-102 BT_24_3_14 Binary Tree Lectures.pdfCS-102 BT_24_3_14 Binary Tree Lectures.pdf
CS-102 BT_24_3_14 Binary Tree Lectures.pdf
 
15-btrees.ppt
15-btrees.ppt15-btrees.ppt
15-btrees.ppt
 
Red black trees
Red black treesRed black trees
Red black trees
 
Recursion
RecursionRecursion
Recursion
 
Trees
TreesTrees
Trees
 
C12 bst
C12 bstC12 bst
C12 bst
 
C12 bst
C12 bstC12 bst
C12 bst
 
Fileprocessing lec-7
Fileprocessing lec-7Fileprocessing lec-7
Fileprocessing lec-7
 
Lecture3
Lecture3Lecture3
Lecture3
 
BST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptx
BST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptxBST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptx
BST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptx
 
Binomial Heap DAA PPT (2).ppt
Binomial Heap DAA PPT (2).pptBinomial Heap DAA PPT (2).ppt
Binomial Heap DAA PPT (2).ppt
 
UNIT II.ppt
UNIT II.pptUNIT II.ppt
UNIT II.ppt
 

Recently uploaded

JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 

Recently uploaded (20)

JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 

Binomial heaps

  • 1. Binomial Heaps Referred to “MIT Press: Introduction to Algorithms 2nd Edition”
  • 2. Binomial Trees • The binomial tree B(k) is an ordered tree defined recursively. As shown in the binomial tree B(0) consists of a single node. The binomial tree B(k) consists of two binomial trees B(k-1) that are linked together: the root of one is the leftmost child of the root of the other.
  • 3. Properties of binomial trees For the binomial tree B(k), • 1. there are 2^k nodes, • 2. the height of the tree is k, • 3. there are exactly k!/(i!(k-i)!) nodes at depth i for i = 0, 1, ..., k, and • 4. the root has degree k, which is greater than that of any other node; moreover if i the children of the root are numbered from left to right by k - 1, k - 2, ..., 0, child i is the root of a subtree B(i).
  • 4. Binomial Heaps A binomial heap H is a set of binomial trees that satisfies the following binomial-heap properties. • 1. Each binomial tree in H obeys the min-heap property: the key of a node is greater than or equal to the key of its parent. We say that each such tree is min-heap-ordered. • 2. For any nonnegative integer k, there is at most one binomial tree in H whose root has degree k.
  • 6. Creating a new binomial heap • To make an empty binomial heap, the MAKE-BINOMIAL-HEAP procedure simply allocates and returns an object H , where head[H ] = NIL. The running time is Θ(1).
  • 7. Finding the minimum key • The procedure BINOMIAL-HEAP-MINIMUM returns a pointer to the node with the minimum key in an n-node binomial heap H. This implementation assumes that there are no keys with value ∞. BINOMIAL-HEAP-MINIMUM(H) 1 y ← NIL 2 x ← head[H] 3 min ← ∞ 4 while x ≠ NIL 5 do if key[x] < min 6 then min ← key[x] 7 y ← x 8 x ← sibling[x] 9 return y
  • 8. Uniting two binomial heaps • The BINOMIAL-HEAP-UNION procedure repeatedly links binomial trees whose roots have the same degree. The following procedure links the B(k-1) tree rooted at node y to the B(k-1) tree rooted at node z; that is, it makes z the parent of y. Node z thus becomes the root of a B(k) tree. BINOMIAL-LINK(y, z) 1 p[y] ← z 2 sibling[y] ← child[z] 3 child[z] ← y 4 degree[z] ← degree[z] + 1
  • 9. The following procedure unites binomial heaps H1 and H2, returning the resulting heap. It destroys the representations of H1 and H2 in the process. Besides BINOMIAL-LINK, the procedure uses an auxiliary procedure BINOMIAL-HEAP-MERGE that merges the root lists of H1 and H2 into a single linked list that is sorted by degree into monotonically increasing order. BINOMIAL-HEAP-UNION(H1, H2) 1 H ← MAKE-BINOMIAL-HEAP() 2 head[H] ← BINOMIAL-HEAP-MERGE(H1, H2) 3 free the objects H1 and H2 but not the lists they point to 4 if head[H] = NIL 5 then return H 6 prev-x ← NIL 7 x ← head[H] 8 next-x ← sibling[x]
  • 10. 9 while next-x ≠ NIL 10 do if (degree[x] ≠ degree[next-x]) or (sibling[next-x] ≠ NIL and degree[sibling[next-x]] =degree[x] ) 11 then prev-x ← x ▹ Cases 1 and 2 12 x ← next-x ▹ Cases 1 and 2(see the figure 2, 5) 13 else if key[x] ≤ key[next-x] 14 then sibling[x] ← sibling[next-x] ▹ Case 3 15 BINOMIAL- LINK(next-x, x) ▹ Case 3 (1, 4) 16 else if prev-x = NIL ▹ Case 4 17 then head[H] ← next-x ▹ Case 4 18 else sibling[prev- x] ← next-x ▹ Case 4 19 BINOMIAL-LINK(x, next-x) ▹ Case 4
  • 16. Inserting a node • The following procedure inserts node x into binomial heap H , assuming that x has already been allocated and key[x] has already been filled in. BINOMIAL-HEAP-INSERT(H, x) 1 H′ ← MAKE-BINOMIAL-HEAP() 2 p[x] ← NIL 3 child[x] ← NIL 4 sibling[x] ← NIL 5 degree[x] ← 0 6 head[H′] ← x 7 H ← BINOMIAL-HEAP-UNION(H, H′)
  • 17. Extracting the node with the minimum key • The following procedure extracts the node with the minimum key from binomial heap H and returns a pointer to the extracted node. BINOMIAL-HEAP-EXTRACT-MIN(H) 1 find the root x with the minimum key in the root list of H, and remove x from the root list of H (see the figure) 2 H′ ← MAKE-BINOMIAL-HEAP() 3 reverse the order of the linked list of x's children, and set head[H′] to point to the head of the resulting list (see the figure) 4 H ← BINOMIAL-HEAP-UNION(H, H′) 5 return x
  • 20. Decreasing a key • The following procedure decreases the key of a node x in a binomial heap H to a new value k. It signals an error if k is greater than x's current key. BINOMIAL-HEAP-DECREASE-KEY(H, x, k) 1 if k > key[x] 2 then error "new key is greater than current key" 3 key[x] ← k 4 y ← x 5 z ← p[y] 6 while z ≠ NIL and key[y] < key[z] 7 do exchange key[y] ↔ key[z] 8 ▸ If y and z have satellite fields, exchange them, too. 9 y ← z 10 z ← p[y] (see the figure)
  • 22. Deleting a key • It is easy to delete a node x's key and satellite information from binomial heap H in O(lg n) time. The following implementation assumes that no node currently in the binomial heap has a key of -∞. BINOMIAL-HEAP-DELETE(H, x) 1 BINOMIAL-HEAP-DECREASE-KEY(H, x, -∞) 2 BINOMIAL-HEAP-EXTRACT-MIN(H)
  • 23. Exercise 1 Draw the result after inserting nodes with integer keys from 1 through 15 into an empty binomial heap in reverse order.
  • 24. Exercise 2 Draw the result after deleting the node with key 8 from the final binomial heap in exercise 1.