Lecture-08 - Advanced Data Structures - 2
Lecture-08 - Advanced Data Structures - 2
CT065-3.5-3
• Heaps
– Binary Heaps
– Binomial Heaps
– Fibonacci Heaps
Min-Heap Max-Heap
• Up-Heap, Bubble/Percolate/Sift-Up
• Worst -> O(log n)
• Average -> O(1)
1) Swap 89 with 1
2) Check 89 with 23 and 12. This is a Min-
Heap, so swap with lowest value
Module Code and Module Title Title of Slides
Root Deletion
• Recursive definition:
B0 B1 B4
Module Code and Module Title Title of Slides
Binomial Heap
• Properties of N-node binomial heap
– Min key contained in root of B0, B1, …, Bk.
– Contains binomial tree Bi iff bi = 1 where bn b2b1b0 is binary representation of
N.
– At most log2 N + 1 binomial trees.
– Height log2 N.
N = 19
binary = 10011
# trees = 3
height = 4
B0 B1 B4
Module Code and Module Title Title of Slides
Binomial Heap: Implementation
Binomial Heap
Leftist-power-of-2 Heap
Module Code and Module Title Title of Slides
Merging
11 + 7 = 18
1111
1011
+ 0111
10010
1111
1011
+ 0111
10010
H=
B4 B1
N = 8, log n = 3
a[ ] = 6 2 -
N = 8, log n = 3
a[ ] = 4 2 -
N = 8, log n = 3
a[ ] = 4 7 2
Then cut 7…
minimum
• Heaps
– Binary Heaps
– Binomial Heaps
– Fibonacci Heaps