Download presentation
Presentation is loading. Please wait.
Published byArchibald Bond Modified over 9 years ago
1
1 Binomial Tree Binomial tree. n Recursive definition: B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4
2
2 Binomial Tree Useful properties of order k binomial tree B k. n Number of nodes = 2 k. n Height = k. n Degree of root = k. n Deleting root yields binomial trees B k-1, …, B 0. Proof. n By induction on k. B0B0 B1B1 B2B2 B3B3 B4B4 B1B1 BkBk B k+1 B2B2 B0B0
3
3 Binomial Tree A property useful for naming the data structure. n B k has nodes at depth i. B4B4 depth 2 depth 3 depth 4 depth 0 depth 1
4
4 Binomial Heap Binomial heap. Vuillemin, 1978. n Sequence of binomial trees that satisfy binomial heap property. – each tree is min-heap ordered – 0 or 1 binomial tree of order k B4B4 B0B0 B1B1 55 45 32 30 24 2322 50 483117 44 82910 6 37 318
5
5 Binomial Heap: Implementation Implementation. n Represent trees using left-child, right sibling pointers. – three links per node (parent, left, right) n Roots of trees connected with singly linked list. – degrees of trees strictly decreasing from left to right 50 483117 44 10 6 37 318 29 6 37 318 48 3150 10 4417 heap 29 Leftist Power-of-2 HeapBinomial Heap Parent Left Right
6
6 Binomial Heap: Properties Properties of N-node binomial heap. n Min key contained in root of B 0, B 1,..., B k. n Contains binomial tree B i iff b i = 1 where b n b 2 b 1 b 0 is binary representation of N. n At most log 2 N + 1 binomial trees. n Height log 2 N . B4B4 B0B0 B1B1 55 45 32 30 24 2322 50 483117 44 82910 6 37 318 N = 19 # trees = 3 height = 4 binary = 10011
7
7 Binomial Heap: Union Create heap H that is union of heaps H' and H''. n "Mergeable heaps." n Easy if H' and H'' are each order k binomial trees. – connect roots of H' and H'' – choose smaller key to be root of H H'' 55 45 32 30 24 2322 50 483117 44 82910 6 H'
8
8 Binomial Heap: Union 0011 1001+ 0111 11 1 1 0 1 19 + 7 = 26 55 45 32 30 24 2322 50 483117 44 82910 6 37 318 41 33 28 15 25 712 +
9
9 Binomial Heap: Union 55 45 32 30 24 2322 50 483117 44 82910 6 37 318 41 33 28 15 25 712 +
10
10 Binomial Heap: Union 55 45 32 30 24 2322 50 483117 44 82910 6 37 3 41 33 28 15 25 7 + 12 18 12
11
11 55 45 32 30 24 2322 50 483117 44 82910 6 37 3 41 33 28 15 25 7 + 12 18 25 37 7 3 18 12 18 12
12
55 45 32 30 24 2322 50 483117 44 82910 6 37 3 41 33 28 15 25 7 12 + 18 25 37 7 3 41 283325 37 157 3 18 12 18 12
13
13 55 45 32 30 24 2322 50 483117 44 82910 6 37 3 41 33 28 15 25 7 + 18 12 41 283325 37 157 3 12 18 25 37 7 3 41 283325 37 157 3 18 12
14
14 55 45 32 30 24 2322 50 483117 44 82910 6 37 3 41 33 28 15 25 7 + 18 12 41 283325 37 157 3 12 18 25 37 7 3 41 283325 37 157 3 55 45 32 30 24 2322 50 483117 44 82910 6 18 12
15
15 Binomial Heap: Union Create heap H that is union of heaps H' and H''. n Analogous to binary addition. Running time. O(log N) n Proportional to number of trees in root lists 2( log 2 N + 1). 0011 1001+ 0111 11 1 1 0 1 19 + 7 = 26
16
16 3 37 618 55 45 32 30 24 2322 50 483117 44 82910 H Binomial Heap: Delete Min Delete node with minimum key in binomial heap H. n Find root x with min key in root list of H, and delete n H' broken binomial trees n H Union(H', H) Running time. O(log N)
17
17 Binomial Heap: Delete Min Delete node with minimum key in binomial heap H. n Find root x with min key in root list of H, and delete n H' broken binomial trees n H Union(H', H) Running time. O(log N) 55 45 32 30 24 2322 50 483117 37 618 44 82910 H H'
18
18 3 37 618 55 x 32 30 24 2322 50 483117 44 82910 H Binomial Heap: Decrease Key Decrease key of node x in binomial heap H. n Suppose x is in binomial tree B k. n Bubble node x up the tree if x is too small. Running time. O(log N) n Proportional to depth of node x log 2 N . depth = 3
19
19 Binomial Heap: Delete Delete node x in binomial heap H. n Decrease key of x to - . n Delete min. Running time. O(log N)
20
20 Binomial Heap: Insert Insert a new node x into binomial heap H. n H' MakeHeap(x) n H Union(H', H) Running time. O(log N) 3 37 618 55 45 32 30 24 2322 50 483117 44 82910 H x H'
21
21 Binomial Heap: Sequence of Inserts Insert a new node x into binomial heap H. If N =.......0, then only 1 steps. If N =......01, then only 2 steps. If N =.....011, then only 3 steps. If N =....0111, then only 4 steps. Inserting 1 item can take (log N) time. If N = 11...111, then log 2 N steps. But, inserting sequence of N items takes O(N) time! n (N/2)(1) + (N/4)(2) + (N/8)(3) +... 2N n Amortized analysis. n Basis for getting most operations down to constant time. 50 483117 44 2910 3 37 6 x
22
22 Priority Queues make-heap Operation insert find-min delete-min union decrease-key delete 1 Binary log N 1 N 1 Binomial log N 1 Fibonacci * 1 1 log N 1 1 1 Relaxed 1 1 log N 1 1 1 Linked List 1 N N 1 1 N is-empty11111 Heaps just did this
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.