22 - More Heaps Data Structures and Algorithms Andrei...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: More Heaps Data Structures and Algorithms Andrei Bulatov Algorithms – More Heaps 22-2 Binomial Heap: Union Create heap H that is union of heaps H‘ and H''. – "Mergeable heaps." – Easy if H‘ and H'' are each order k binomial trees. • connect roots of H‘ and H'' oose smaller key to be root of H • choose smaller key to be root of H H'' 55 45 32 30 24 23 22 50 48 31 17 44 8 29 10 6 H' Algorithms – More Heaps 22-3 Binomial Heap: Union 30 23 22 48 31 17 44 8 29 10 6 37 3 18 15 7 12 + 1 1 1 1 1 1 1 1 1 1 1 1 19 + 7 = 26 55 45 32 24 50 41 33 28 25 + Algorithms – More Heaps 22-4 Binomial Heap: Union 30 23 22 48 31 17 44 8 29 10 6 37 3 18 15 7 12 55 45 32 24 50 41 33 28 25 + Algorithms – More Heaps 22-5 Binomial Heap: Union 30 23 22 48 31 17 44 8 29 10 6 37 3 18 15 7 12 12 18 55 45 32 24 50 41 33 28 25 + 30 23 22 48 31 17 44 8 29 10 6 37 3 15 7 12 18 25 37 7 3 18 12 Algorithms – More Heaps 22-6 6 55 45 32 24 50 41 33 28 25 + 18 12 30 23 22 48 31 17 44 8 29 10 6 37 3 15 7 12 18 25 37 7 3 41 28 33 25 37 15 7 3 18 12 Algorithms – More Heaps 22-7 7 55 45 32 24 50 41 33 28 25 + 18 12 30 23 22 48 31 17 44 8 29 10 6 37 3 15 7 12 18 25 37 7 3 41 28 33 25 37 15 7 3 18 12 Algorithms – More Heaps 22-8 8 55 45 32 24 50 41 33 28 25 + 18 12 41 28 33 25 37 15 7 3 30 23 22 48 31 17 44 8 29 10 6 37 3 15 7 12 18 25 37 7 3 41 28 33 25 37 15 7 3 18 12 Algorithms – More Heaps 22-9 9 55 45 32 24 50 41 33 28 25 + 18 12 41 28 33 25 37 15 7 3 55 45 32 30 24 23 22 50 48 31 17 44 8 29 10 6 Algorithms – More Heaps 22-10 Union: Running Time Proof he running time is proportional to the number of trees in root lists, Theorem [ Union can be executed in O(log n) time The running time is proportional to the number of trees in root lists, which is at most 2( log N + 1). QED Algorithms – More Heaps 22-11 Delete Minimal 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) 3 37 6 18 55 45 32 30 24 23 22 50 48 31 17 44 8 29 10 H Algorithms – More Heaps 22-12 Delete Minimal 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) 55 45 32 30 24 23 22 50 48 31 17 37 6 18 44 8 29 10 H H' Algorithms – More Heaps 22-13 Decrease Key Decrease key of node x in binomial heap H. – Suppose x is in binomial tree B k . – Bubble node x up the tree if x is too small. Running time: O(log N) roportional to depth of node x g – Proportional to depth of node x ≤ log 2 N . 3 37 6 18 55 x 32 30 24 23 22 50 48 31 17 44 8 29 10 H depth = 3 Algorithms – More Heaps 22-14 Delete Delete node x in binomial heap H....
View Full Document

{[ snackBarMessage ]}

Page1 / 51

22 - More Heaps Data Structures and Algorithms Andrei...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online