已阅读5页,还剩26页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Pairing Heaps,Actual Complexity,Pairing Heaps,Amortized Complexity,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.,+,=,Actual cost = O(1).,Insert,Create 1-element max tree with new item and meld with existing max pairing heap.,+,insert(2),=,Insert,Create 1-element max tree with new item and meld with existing max pairing heap.,+,insert(14),=,Actual cost = O(1).,Worst-Case Degree,Insert 9, 8, 7, , 1, in this order.,Worst-case degree = n 1.,Worst-Case Height,Insert 1, 2, 3, , n, in this order.,Worst-case height = n.,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),If theNode is not the root, remove subtree rooted at theNode from its sibling list.,IncreaseKey(theNode, theAmount),Meld subtree with remaining tree.,1,2,6,9,2,18,3,3,IncreaseKey(theNode, theAmount),2,18,3,3,Actual cost = O(1).,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.,Meld into one tree.,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 insert is O(1), amortized cost of a remove max must be Q(n).,Good Ways To Meld Subtrees,Two-pass scheme. Multipass scheme. Both have same asymptotic complexity. Two-pass scheme gives better observed performance.,Two-Pass Scheme,Pass 1. Examine subtrees from left to right. Meld pairs of subtrees, reducing the number of subtrees to half the original number. If # subtrees was odd, meld remaining original subtree with last newly generated subtree. Pass 2. Start with rightmost subtree of Pass 1. Call this the working tree. Meld remaining subtrees, one at a time, from right to left, into the working tree.,Two-Pass Scheme Example,Pass 1,Two-Pass Scheme Example,Pass 2,Multipass Scheme,Place the subtrees into a FIFO queue. Repeat until 1 tree remains. Remove 2 subtrees from the queue. Meld them. Put the resulting tree onto the queue.,Multipass Scheme Example,Multipass Scheme-Example,Multipass Scheme-Example,Actual cost = O(n).,Remove Nonroot Element,Remove theNode from its sibling list. Meld children of theNode using either 2-pass or multipass scheme. Meld resulting tree with whats left of original tree.,Remove(theNode),Remove theNode from its doubly-linked sibling list.,Remove(theNode),Meld children of theNode.,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 教师成长工作计划
- 地理教师教学心得6篇
- 可卡因引起的残留性和迟发性精神病性障碍个案护理
- 家族性渗出性玻璃体视网膜病变个案护理
- 售票员聘用合同
- 新媒体账号代运营服务合同
- (正式版)JTT 1500-2024 视觉航标表面色测量方法
- 主题策略-情绪投资系列:情绪指标权重提升下拥挤度方法
- 山东省济宁市一中2023-2024学年高一下学期开学考试生物试题
- 内部控制工作小组成立方案
- 大数据采集与预处理课件教学大纲-大数据-数据采与处理
- 大概念视角下的初中数学单元教学设计 论文
- 洁净施工方案
- 幼儿园中班美术《舞动的草裙》课件
- 数据治理体系建设项目实施方案技术投标文件正文
- 二尖瓣狭窄超声课件
- 公积金借款合同电子版(6篇)
- 机电一体化实训报告
- 医学装备管理
- 产品发运流程
- 托管运营合作协议
评论
0/150
提交评论