![Page 1: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/1.jpg)
Binomial Tree
B0 B1 B2 B3 B4
Adapted from: Kevin Wayne
Bk: a binomial tree Bk-1 with the addition of a left child with another binomial tree Bk-1
![Page 2: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/2.jpg)
Binomial Tree
B0 B1 B2 B3 B4
Number of nodes with respect to k?
N(Bo) = 1N(Bk) = 2 N(Bk-1) = 2k
![Page 3: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/3.jpg)
Binomial Tree
B0 B1 B2 B3 B4
Height?
H(Bo) = 1H(Bk) = 1 + H(Bk-1) = k
![Page 4: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/4.jpg)
Binomial Tree
B0 B1 B2 B3 B4
Degree of root node?
k, each time we add another binomial tree
![Page 5: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/5.jpg)
Binomial Tree
B0 B1 B2 B3 B4
What are the children of the root?
k binomial trees:Bk-1, Bk-2, …, B0
![Page 6: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/6.jpg)
Binomial Tree
B4
depth 2
depth 3
depth 4
depth 0
depth 1
Why is it called a binomial tree?
![Page 7: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/7.jpg)
Binomial Tree
Bk has nodes at depth i.
B4
i
k
62
4
depth 2
depth 3
depth 4
depth 0
depth 1
![Page 8: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/8.jpg)
Binomial Heap
Binomial heap Vuillemin, 1978.
Sequence of binomial trees that satisfy binomial heap property:– each tree is min-heap ordered– top level: full or empty binomial tree of order k– which are empty or full is based on the number of elements
B4 B0B1
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3 18
![Page 9: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/9.jpg)
Binomial Heap
Like our “set” data structure from last time, except binomial tree heaps instead of arrays
B4 B0B1
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3 18
A0: [18]A1: [3, 7]A2: emptyA3: emptyA3: [6, 8, 29, 10, 44, 30, 23, 22, 48, 31, 17, 45, 32, 24, 55]
N = 19# trees = 3height = 4binary = 10011
![Page 10: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/10.jpg)
Binomial Heap: Properties
B4 B0B1
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3 18
N = 19# trees = 3height = 4binary = 10011
How many heaps?
O(log n) – binary number representation
![Page 11: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/11.jpg)
Binomial Heap: Properties
B4 B0B1
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3 18
N = 19# trees = 3height = 4binary = 10011
Where is the max/min?
Must be one of the roots of the heaps
![Page 12: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/12.jpg)
Binomial Heap: Properties
B4 B0B1
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3 18
N = 19# trees = 3height = 4binary = 10011
Runtime of max/min?
O(log n)
![Page 13: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/13.jpg)
Binomial Heap: Properties
B4 B0B1
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3 18
N = 19# trees = 3height = 4binary = 10011
Height?
floor(log2 n)- largest tree = Blog n
- height of that tree is log n
![Page 14: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/14.jpg)
Binomial Heap: Union
How can we merge two binomial tree heaps of the same size (2k)?– connect roots of H' and H''– choose smaller key to be root of H
H''55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
H'
Runtime? O(1)
![Page 15: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/15.jpg)
Binomial Heap: Union
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3 18
3328
15
25
7 12
How can we combine/merge binomial heaps (i.e. a combination of binomial tree heaps)?
![Page 16: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/16.jpg)
Binomial Heap: Union
001 1
100 1+
011 1
11
1
1
0
1
19 + 7 = 26
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3 18
41
3328
15
25
7 12
+
Go through each tree size starting at 0 and merge as we go
![Page 17: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/17.jpg)
Binomial Heap: Union
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3 18
41
3328
15
25
7 12
+
![Page 18: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/18.jpg)
Binomial Heap: Union
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3
41
3328
15
25
7
+
12
18
18
12
![Page 19: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/19.jpg)
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3
41
3328
15
25
7
+
12
18
25
377
3
18
12
18
12
![Page 20: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/20.jpg)
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3
41
3328
15
25
7
12
+
18
25
377
3
41
28 33 25
3715 7
3
18
12
18
12
![Page 21: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/21.jpg)
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3
41
3328
15
25
7
+
18
12
41
28 33 25
3715 7
3
12
18
25
377
3
41
28 33 25
3715 7
3
18
12
![Page 22: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/22.jpg)
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
37
3
41
3328
15
25
7
+
18
12
41
28 33 25
3715 7
3
12
18
25
377
3
41
28 33 25
3715 7
3
55
45 32
30
24
23 22
50
48 31 17
448 29 10
6
18
12
![Page 23: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/23.jpg)
Binomial Heap: Union
Analogous to binary addition
Running time?Proportional to number of trees in root lists 2 O(log2 N)
O(log N)
001 1
100 1+
011 1
11
1
1
0
1
19 + 7 = 26
![Page 24: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/24.jpg)
3
37
6 18
55
45 32
30
24
23 22
50
48 31 17
448 29 10
H
Binomial Heap: Delete Min/Max
We can find the min/max in O(log n).How can we extract it?
Hint: Bk consists of binomial trees:Bk-1, Bk-2, …, B0
![Page 25: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/25.jpg)
3
37
6 18
55
45 32
30
24
23 22
50
48 31 17
448 29 10
H
Binomial Heap: Delete Min
Delete node with minimum key in binomial heap H. Find root x with min key in root list of H, and delete H' broken binomial trees H Union(H', H)
![Page 26: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/26.jpg)
3
37
6 18
55
45 32
30
24
23 22
50
48 31 17
448 29 10
H
Binomial Heap: Delete Min
Delete node with minimum key in binomial heap H. Find root x with min key in root list of H, and delete H' broken binomial trees H Union(H', H)
Running time? O(log N)
![Page 27: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/27.jpg)
3
37
6 18
55
x 32
30
24
23 22
50
48 31 17
448 29 10
H
Binomial Heap: Decrease Key
Just call Decrease-Key/Increase-Key of Heap Suppose x is in binomial tree Bk
Bubble node x up the tree if x is too small
Running time: O(log N) Proportional to depth of node x
depth = 3
![Page 28: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/28.jpg)
Binomial Heap: Delete
Delete node x in binomial heap H Decrease key of x to - Delete min
Running time: O(log N)
![Page 29: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/29.jpg)
Binomial Heap: Insert
Insert a new node x into binomial heap H H' MakeHeap(x) H Union(H', H)
Running time. O(log N)
3
37
6 18
55
45 32
30
24
23 22
50
48 31 17
448 29 10
H
x
H'
![Page 30: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/30.jpg)
Build-Heap
Call insert n times
Runtime?
Can we get a tighter bound?
O(n log n)
![Page 31: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/31.jpg)
Build-Heap
Call insert n times
Consider inserting n numbers how many times will B0 be empty?
how many times will we need to merge with B0?
how many times will we need to merge with B1?
how many times will we need to merge with B2?
… how many times will we need to merge with Blog n?
times cost
![Page 32: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/32.jpg)
Build-Heap
Call insert n times
Consider inserting n numbers how many times will B0 be empty? n/2 O(1)
how many times will we need to merge with B0? n/2 O(1)
how many times will we need to merge with B1? n/4 O(1)
how many times will we need to merge with B2? n/8 O(1)
… how many times will we need to merge with Blog n? 1 O(1)
times cost
Runtime? Θ(n)
![Page 33: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/33.jpg)
Heaps
![Page 34: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/34.jpg)
Fibonacci Heaps
Similar to binomial heap•A Fibonacci heap consists of a sequence of heaps
More flexible•Heaps do not have to be binomial trees
More complicated
23 7 3
38 52 30 18
39 41
17
35
46 26
24
Min [H]
![Page 35: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/35.jpg)
Heaps
Should you always use a Fibonacci heap?
![Page 36: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/36.jpg)
Heaps
• Extract-Max and Delete are O(n) worst case• Constants can be large on some of the operations• Complicated to implement
![Page 37: Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another](https://reader036.vdocument.in/reader036/viewer/2022062309/5697c0101a28abf838ccb049/html5/thumbnails/37.jpg)
Heaps
Can we do better?