




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年河北邯郸市口腔医院秋季博硕人才引进12人备考考试题库附答案解析
- 2025贵州省康复医院合同制人员招聘备考考试题库附答案解析
- 2025甘肃天水市事业单位招聘工作人员270人备考练习题库及答案解析
- 2025贵州江口县第六幼儿园招聘备考考试题库附答案解析
- 2025马关县小坝子镇公开储备一批村“两委”后备干部(16人)笔试备考题库及答案解析
- 2025福建漳州市芗江人力资源服务有限公司招聘若干人备考考试题库附答案解析
- 2025年金华市中医医院招聘编外工作人员5人(第二批)备考考试题库附答案解析
- 工厂安全培训标准周期课件
- 2025江西宜春市直事业单位选调22人备考考试题库附答案解析
- 掌握互动教学法
- 燃气高空作业专项施工方案
- 生鲜店加盟合同模板
- 电影刮痧课件教学课件
- 游戏厅转让合同范本样本
- DB34∕T 4253-2022 公路水运工程质量监督规程
- 人教版数学四年级上册第二单元习题
- 预包装食品标签审核表
- 《旅游政策与法律法规》课件-项目一 任务1-4知识点10-关于以标准化促进餐饮节约反对餐饮浪费
- 《中国诗词大会》必背经典古诗词100首
- 第5课《用发展的观点看问题》第1框《世界是永恒发展的》-【中职专用】《哲学与人生》同步课堂课件
- 垃圾渗滤液处理调试方案
评论
0/150
提交评论