Professional Documents
Culture Documents
2
Copyright © 2021, ABES Engineering College
Session Plan - Day 16
3
Copyright © 2021, ABES Engineering College
Quality Content for Outcome based Learning
This section present data structures known as merge-able heaps, which support the
following seven operations.
• MAKE-BINOMIAL-HEAP
• BINOMIAL-HEAP-INSERT
• BINOMIAL-HEAP-MINIMUM
• BINOMIAL-HEAP-EXTRACT-MIN
• BINOMIAL-HEAP-UNION
• BINOMIAL-HEAP DECREASE-KEY
• BINOMIAL-HEAP-DELETE
B2
B1
B1 B0
B1
B0 B1 B2 B3
B3
B2 B0
B1
B4
B1 Bo
B2
Bk-2
Bk-1
(Fig: A General View of B-Tree)
Bk
Copyright © 2021, ABES Engineering College
Binomial Tree
Binomial tree properties:
• has nodes
• has height
• There are exactly nodes at depth i for i=0, 1, 2,…,k.
For Example:
Lets check in and depth 2()
Head[H]
10 1 6
B0 12 25 8 14 29
18
B2 11 17 38
27
B3
Here n=13
So =(So at most 4)
a) p c)
key
degree
child sibling
NIL NIL
2 1
0 2
head[H] NIL NIL
b)
10 12
head[H] 2 1 1 0
NIL NIL
10 12
15
15
0
NIL NIL
3. UNION(H1, H2) creates and returns a new heap that contains all the nodes of
heaps H1 and H2. Heaps H1 and H2 are "destroyed" by this operation.
4. EXTRACT-MIN(H) deletes the node from heap H whose key is minimum, returning
a pointer to the node.
Head[H]
20 15 8
35 10 28
12
3 min ← ∞
35 10 28
4 while x ≠ NIL
5 do if key[x] < min 12
6 then min ← key[x]
7 y←x
8 x ← sibling[x]
9 return y
3 min ← ∞
35 10 28
4 while x ≠ NIL
5 do if key[x] < min 12
After Execution
6 then min ← key[x]
Return y=8
7 y←x
8 x ← sibling[x]
9 return y
x=next x
Example:
Head[H] next → 𝑥 Head[H] x prev → 𝑥
x
x=next x
Example:
Head[H]
100 100
41
Ca
se
4 prev → 𝑥 𝑥 next → 𝑥
12 3 15
Head[H] 18 7 37 28 33
25 41
41 prev → 𝑥 𝑥 next → 𝑥
12 3 15
Head[H] 18 7 37 28 33
12 3
25 41
Head[H] 18 15 7 37
28 33 se
3
25 Ca
41
100 100
100 100
H1 12 7 15 H2 18 3 6
25 28 33 37 29 10 44
48 31
41 17
56
H1 12 7 15 H2 18 3 6
25 28 33 37 29 10 44
48 31
41 17
56
After Merging…….
H 12 18 7 3 15 6
25 37 28 33 29 10 44
48 31
41 17
56
H 12 18 7 3 15 6
25 37 28 33 29 10 44
48 31
41 17
56
Fix Pointer
x next x
H 12 18 7 3 15 6
25 37 28 33 29 10 44
48 31
41 17
56
25 37 28 33 29 10 44
Ca 48 31
se 4 41 17
56
25 37 28 33 29 10 44
Ca
se 4 48 31
41 17
56
next x
H 12 7 3 15 6
x 18 25 37 28 33 29 10 44
48 31
41 17
56
18 25 37 28 33 29 10 44
48 31
41 17
56
18 25 37 28 33 29 10 44
Ca
se 2 48 31
41 17
56
18 25 37 28 33 29 10 44
Ca
se 2 48 31
41 17
56
prevx x next x
H 12 7 3 15 6
18 25 37 28 33 29 10 44
48 31
41 17
56
prevx x next x
H 12 7 3 15 6
18 25 37 28 33 29 10 44
48 31
41 17
56
prevx x next x
H 12 7 3 15 6
Ca
se 4 18 37 28 33 29 10 44
25
48 31
41 17
56
18 25 37 28 33 29 10 44
Ca
se 4 48 31
41 17
56
prevx next x
H 12 3 15 6
x
18 7 37 28 33 29 10 44
25 48 31
41 17
56
x next x
H 12 3 15 6
18 7 37 28 33 29 10 44
25 48 31
41 17
56
x next x
H 12 3 15 6
18 7 37 28 33 29 10 44
Ca
se 48
3 25 41 31 17
56
18 7 37 28 33 29 10 44
Ca
se 48
3 25 41 31 17
56
H 12 15 6
18 3 28 33 29 10 44
7 37 48 31
41 17
25 56
18 3 28 33 29 10 44
7 37 48 31
41 17
25 56
x next x
H 12 15 6
18 3 28 33 29 10 44
Ca
se 3
7 37 48 31
41 17
25 56
H 12 6
18 15 29 10 44
3 28 33 48 31 17
7 37 41 56
25
H 12 6
18 15 29 10 44
3 28 33 48 31 17
7 37 41 56
25
Final Binomial
Heap Tree
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]
(because each iteration either advances the pointers one position down the
root list of H or removes a root from the root list. )