0% found this document useful (0 votes)
141 views16 pages

Binomial Heap

A binomial heap consists of a collection of binomial trees rather than a single tree like a binary heap. Each binomial tree has a special structure where the root has the maximum degree and children are full binomial trees of descending orders. The union operation merges trees of the same order together starting from the smallest. Extract-min finds the tree containing the minimum, detaches it to form one heap, and removes the root to form another, then unions the two resulting heaps.

Uploaded by

blessy thomas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views16 pages

Binomial Heap

A binomial heap consists of a collection of binomial trees rather than a single tree like a binary heap. Each binomial tree has a special structure where the root has the maximum degree and children are full binomial trees of descending orders. The union operation merges trees of the same order together starting from the smallest. Extract-min finds the tree containing the minimum, detaches it to form one heap, and removes the root to form another, then unions the two resulting heaps.

Uploaded by

blessy thomas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Binomial Heap

1
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

2
Binomial Tree
Definition:
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

3
Binomial Tree
B0 B1 B2 B3

B4

4
Binomial Heap
Properties of Binomial Tree
Lemma: For a binomial tree Bk,
1. There are 2k nodes
2. height = k
3. deg(root) = k ; deg(other node)  k
4. Children of root, from left to right,
are Bk-1, Bk-2, …, B1, B0
5. Exactly C(k,i) nodes at depth I
5
Binomial Heap
Example: A binomial heap with 13 elements

12 8 15

25 13 19 32 16

41 33 21 52

35

6
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
7
Union Operation
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


8
Union two binomial heaps with 5 and 13 nodes

8
H1 12 15

25 13 32 16
19

41 52
33 21
H2
4 9
35

14 11

31
18
4 8 15

12 25 13 19 32 16

41 33 21 52

9 35

14 11
after
processing
31 k=0
19
4 15

12 19 32 16

8
33 21 52

9 25 13
35
14 11 41
after
31 processing
k = 1, 2
20
4
8

12 15 13
9 25

19 32 16 14 11 41

33 21 52 31

35 Done after
processing
k=3
21
Binomial Heap Operations
• 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,-1); Extract-Min(H);
22
Extract-Min(H)
Step 1: Find Bj with Min

H 12 8 15

25 13 32 16
19

41 52
33 21

35
Bj with Min
23
Extract-Min(H)
Step 2: Forming two heaps

H1 12 15

19 32 16
H2 8
33 21 52
25 13
35
41

24
Extract-Min(H)
Step 3: Union two heaps

12 15

25 13 19 32 16

41 33 21 52

35

25

You might also like