Содержание
- 2. Summary of Heap ADT Analysis Consider a heap of N nodes Space needed: O(N) Actually, O(MaxSize)
- 3. Other Heap Operations Find and FindMax: O(N) DecreaseKey(P,Δ,H): Subtract Δ from current key value at position
- 4. But What About... Merge(H1,H2): Merge two heaps H1 and H2 of size O(N). E.g. Combine queues
- 5. Binomial Queues Binomial queues support all three priority queue operations Merge, Insert and DeleteMin in O(log
- 6. Building a Binomial Tree To construct a binomial tree Bk of height k: Take the binomial
- 7. Building a Binomial Tree To construct a binomial tree Bk of height k: Take the binomial
- 8. Building a Binomial Tree To construct a binomial tree Bk of height k: Take the binomial
- 9. Building a Binomial Tree To construct a binomial tree Bk of height k: Take the binomial
- 10. Building a Binomial Tree To construct a binomial tree Bk of height k: Take the binomial
- 11. Building a Binomial Tree To construct a binomial tree Bk of height k: Take the binomial
- 12. Building a Binomial Tree To construct a binomial tree Bk of height k: Take the binomial
- 13. Why Binomial? Why are these trees called binomial? Hint: how many nodes at depth d? B0
- 14. Why Binomial? Why are these trees called binomial? Hint: how many nodes at depth d? Number
- 15. Definition of Binomial Queues 3 Binomial Queue = “forest” of heap-ordered binomial trees 1 7 -1
- 16. Binomial Queue Properties Suppose you are given a binomial queue of N nodes There is a
- 17. Binomial Queues: Merge Main Idea: Merge two binomial queues by merging individual binomial trees Since Bk+1
- 18. Example: Binomial Queue Merge Merge H1 and H2 3 1 7 -1 2 1 3 8
- 19. Example: Binomial Queue Merge Merge H1 and H2 3 1 7 -1 2 1 3 8
- 20. Example: Binomial Queue Merge Merge H1 and H2 3 1 7 -1 2 1 3 8
- 21. Example: Binomial Queue Merge Merge H1 and H2 3 1 7 -1 2 1 3 8
- 22. Example: Binomial Queue Merge Merge H1 and H2 3 1 7 -1 2 1 3 8
- 23. Example: Binomial Queue Merge Merge H1 and H2 3 1 7 -1 2 1 3 8
- 24. Example: Binomial Queue Merge Merge H1 and H2 3 1 7 -1 2 1 3 8
- 25. Example: Binomial Queue Merge Merge H1 and H2 3 1 7 -1 2 1 3 8
- 26. Example: Binomial Queue Merge Merge H1 and H2 3 1 7 -1 2 1 3 8
- 27. Binomial Queues: Merge and Insert What is the run time for Merge of two O(N) queues?
- 28. Binomial Queues: Merge and Insert What is the run time for Merge of two O(N) queues?
- 29. Insert 1,2,…,7 1
- 30. Insert 1,2,…,7 1 2
- 31. Insert 1,2,…,7 1 2 3
- 32. Insert 1,2,…,7 1 2 3 4
- 33. Insert 1,2,…,7 1 2 3 4
- 34. Insert 1,2,…,7 1 2 3 4 5
- 35. Insert 1,2,…,7 1 2 3 4 5 6
- 36. Insert 1,2,…,7 1 2 3 4 5 6 7
- 37. Binomial Queues: DeleteMin Steps: Find tree Bk with the smallest root Remove Bk from the queue
- 38. Insert 1,2,…,7 1 2 3 4 5 6 7
- 39. DeleteMin 2 3 4 5 6 7
- 40. Merge 2 3 4 5 6 7
- 41. Merge 2 3 4 5 6 7
- 42. Merge 2 3 4 5 6 7
- 43. Merge 2 3 4 5 6 7 DONE!
- 44. Implementation of Binomial Queues Need to be able to scan through all trees, and given two
- 45. Other Mergeable Priority Queues: Leftist and Skew Heaps Leftist Heaps: Binary heap-ordered trees with left subtrees
- 47. Скачать презентацию