高级数据结构pairing Heap.ppt

  1. 1、本文档共31页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
高级数据结构pairing Heap

Pairing Heaps Pairing Heaps Pairing Heaps Experimental results suggest that pairing heaps are actually faster than Fibonacci heaps. Simpler to implement. Smaller runtime overheads. Less space per node. Definition A min (max) pairing heap is a min (max) tree in which operations are done in a specified manner. Node Structure Child Pointer to first node of children list. Left and Right Sibling Used for doubly linked linked list (not circular) of siblings. Left pointer of first node is to parent. x is first node in list iff x.left.child = x. Data Note: No Parent, Degree, or ChildCut fields. Meld – Max Pairing Heap Compare-Link Operation Compare roots. Tree with smaller root becomes leftmost subtree. Insert Create 1-element max tree with new item and meld with existing max pairing heap. Insert Create 1-element max tree with new item and meld with existing max pairing heap. Worst-Case Degree Insert 9, 8, 7, …, 1, in this order. Worst-Case Height Insert 1, 2, 3, …, n, in this order. IncreaseKey(theNode, theAmount) Since nodes do not have parent fields, we cannot easily check whether the key in theNode becomes larger than that in its parent. So, detach theNode from sibling doubly-linked list and meld. IncreaseKey(theNode, theAmount) IncreaseKey(theNode, theAmount) IncreaseKey(theNode, theAmount) Remove Max If empty => fail. Otherwise, remove tree root and meld subtrees into a single max tree. How to meld subtrees? Good way => O(log n) amortized complexity for remove max. Bad way => O(n) amortized complexity. Bad Way To Meld Subtrees currentTree = first subtree. for (each of the remaining trees) currentTree = compareLink(currentTree, nextTree); Example Remove max. Example Actual cost of insert is 1. Actual cost of remove max is degree of root. n/2 inserts (9, 7, 5, 3, 1, 2, 4, 6, 8) followed by n/2 remove maxs. Cost of inserts is n/2. Cost of remove maxs is 1 + 2 + … + n/2 – 1 = Q(n2). If amortized cost of an

文档评论(0)

tianma2015 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档