330 likes | 342 Views
Binomial Heaps allow for efficient operations such as insert, meld, remove min, and reinsert subtrees. Pairwise combining min trees and tree table management contribute to the heap's complexity. Learn about binomial trees, nodes, and their representation in this detailed guide.
E N D
1 4 6 5 5 2 3 7 9 9 9 4 5 8 7 6 6 8 Min Binomial Heap • Collection of min trees.
Node Structure • Degree • Number of children. • Child • Pointer to one of the node’s children. • Null iff node has no child. • Sibling • Used for circular linked list of siblings. • Data
A 1 4 6 5 5 2 3 7 9 9 9 4 5 8 7 6 6 8 Binomial Heap Representation • Circular linked list of min trees. Degree fields not shown.
A 1 4 6 5 5 2 3 7 10 9 9 9 4 5 8 7 6 6 8 Insert 10 • Update min-element pointer if necessary. • Add a new single-node min tree to the collection.
4 1 7 5 B 3 7 9 A 8 Meld • Combine the 2 top-level circular lists. • Set min-element pointer.
Meld 4 1 7 5 3 C 7 9 8
Remove Min • Empty binomial heap=> fail.
A 1 4 6 5 5 2 3 7 10 9 9 9 4 5 8 7 6 6 8 Nonempty Binomial Heap • Remove a min tree. • Reinsert subtrees of removed min tree. • Update binomial heap pointer.
a b c d e d A Remove Min Tree • Same as remove a node from a circular list. • No next node => empty after remove. • Otherwise, copy next-node data and remove next node.
4 1 7 5 3 7 9 B A subtrees 8 Reinsert Subtrees • Combine the 2 top-level circular lists. • Same as in meld operation.
Update Binomial Heap Pointer • Must examine roots of all min trees to determine the min value.
Complexity Of Remove Min • Remove a min tree. • O(1). • Reinsert subtrees. • O(1). • Update binomial heap pointer. • O(s), where s is the number of min trees in final top-level circular list. • s = O(n). • Overall complexity of remove min is O(n).
Enhanced Remove Min • During reinsert of subtrees, pairwise combine min trees whose roots have equal degree. • This is essential to get stated amortized bounds and so is the correct way to remove from a Binomial heap. • The simple remove min described earlier does not result in the desired amortized complexity and so is incorrect for Binomial heaps.
1 4 6 5 5 10 2 3 7 9 9 9 4 5 8 7 6 6 8 Pairwise Combine Examine the s = 7 trees in some order. Determined by the 2 top-level circular lists.
1 4 6 5 5 10 2 3 7 9 9 9 4 5 8 4 3 tree table 2 7 6 6 1 0 8 Pairwise Combine Use a table to keep track of trees by degree.
1 4 6 5 5 10 2 3 7 9 9 9 4 5 8 4 3 tree table 2 7 6 6 1 0 8 Pairwise Combine
1 4 6 5 5 10 2 3 7 9 9 9 4 5 8 4 3 tree table 2 7 6 6 1 0 8 Pairwise Combine Combine 2 min trees of degree 0. Make the one with larger root a subtree of other.
10 1 4 6 5 5 2 3 7 9 9 9 4 5 8 4 3 tree table 2 7 6 6 1 0 8 Pairwise Combine Update tree table.
10 1 4 6 5 5 2 3 7 9 9 9 4 5 8 4 3 tree table 2 7 6 6 1 0 8 Pairwise Combine Combine 2 min trees of degree 1. Make the one with larger root a subtree of other.
10 1 5 4 6 5 2 3 9 7 9 9 4 5 8 4 3 tree table 2 7 6 6 1 0 8 Pairwise Combine Update tree table.
10 1 5 4 6 5 2 3 9 7 9 9 4 5 8 4 3 tree table 2 7 6 6 1 0 8 Pairwise Combine
10 1 5 4 6 5 2 3 9 7 9 9 4 5 8 4 3 tree table 2 7 6 6 1 0 8 Pairwise Combine Combine 2 min trees of degree 2. Make the one with larger root a subtree of other.
1 4 6 5 2 3 7 10 5 9 9 4 5 8 9 4 3 tree table 2 7 6 6 1 0 8 Pairwise Combine Combine 2 min trees of degree 3. Make the one with larger root a subtree of other.
4 2 1 6 5 10 9 5 3 4 5 7 9 9 7 6 6 8 4 3 tree table 2 8 1 0 Pairwise Combine Update tree table.
4 2 1 6 5 10 9 5 3 4 5 7 9 9 7 6 6 8 4 3 tree table 2 8 1 0 Pairwise Combine
4 2 1 6 5 10 9 5 3 4 5 7 9 9 7 6 6 8 4 3 tree table 2 8 1 0 Pairwise Combine Create circular list of remaining trees.
Complexity Of Remove Min • Create and initialize tree table. • O(MaxDegree). • Done once only. • Examine s min trees and pairwise combine. • O(s). • Collect remaining trees from tree table, reset table entries to null, and set binomial heap pointer. • O(MaxDegree). • Overall complexity of remove min. • O(MaxDegree + s).
B0 … Bk-1 B2 B1 B0 Binomial Trees • Bkis degree k binomial tree. • Bk, k > 0, is:
B3 B2 B0 B1 Examples
… Bk-1 B2 B1 B0 B0 Number Of Nodes In Bk N0 = 1 • Nk = number of nodes in Bk. • Bk, k > 0, is: • Nk = N0 + N1 + N2 + …+ Nk-1 + 1 = 2k.
B3 B2 B1 Equivalent Definition • Bk, k > 0, is two Bk-1s. • One of these is a subtree of the other.
Nk And MaxDegree • N0 = 1 • Nk = 2Nk-1 = 2k. • If we start with zero elements and perform operations as described, then all trees in all binomial heaps are binomial trees. • So, MaxDegree = O(log n).