已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 招4人!湟源县人民医院2025年招聘编外专业技术人员笔试考试参考试题及答案解析
- 2025中材锂膜(内蒙古)有限公司招聘5人考试笔试参考题库及答案解析
- 2025重庆市锁定科技有限公司招聘13人考试笔试模拟试题及答案解析
- 2025广东深圳市眼科医院招聘工作人员9人笔试考试备考题库及答案解析
- gct数学真题及答案
- 2025北京热力热源分公司招聘10人考试笔试备考试题及答案解析
- 2025云南丽江宁蒗县大兴街道办事处面向社会公开招聘公益性岗位11人笔试考试备考试题及答案解析
- 员工关系冲突处理案例分析
- 安全法的考试题及答案
- 2025江西省医疗保障研究会劳务派遣人员招聘2人考试笔试参考题库及答案解析
- 《智慧斑马线 高分子复合材料LED发光地砖》
- 房屋修缮加固工程施工组织设计方案
- 初三简单数学试卷
- 机械伤害的安全培训课件
- 同等学力申硕(临床医学)考试题库(全真题库)
- 高清视频会议系统售后服务及培训计划
- 宁德新能源verify测试题库
- 第15课 两次鸦片战争 课件高一上学期统编版(2019)必修中外历史纲要上-1
- 国家安全教育高教-第六章坚持以经济安全为基础
- 韦莱韬悦-东方明珠新媒体集团一体化职位职级体系方案-2018
- 中国神经病理性疼痛诊疗指南(2024 版)
评论
0/150
提交评论