已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 保险行业客户服务技巧模拟试题
- 保险消费者权益保护考试题库
- 内蒙古自治区巴彦淖尔市统计专业技术中级资格考试(统计工作实务)备考题库及答案(2026年)
- 杭州建兰中学新初一分班英语试卷含答案解析
- 2026年福建省福清市高二生物下册期末考试模拟检测卷(模拟题)附答案
- 医用超声雾化加湿设备考试题库及答案
- 卫生资格《职业卫生与中毒》练习试题及答案
- 国开国际经济法形考任务1-4试题及答案
- 2026年护士资格妇产科护理学练习题及参考答案
- 2026年急诊科院感应急防控试题及答案
- T/GDCA 034-2023化妆品用原料 红茶发酵产物
- 2026年全国行政执法人员执法资格考试必考题库与答案
- 2025年中国干粉砂浆市场调查研究报告
- 重庆数字资源集团招聘考试真题2025
- 城镇土地使用税房产税纳税申报表
- T∕CPCPA 0017-2026 托育机构婴幼儿回应性照护服务规范
- 2026云南保山电力股份有限公司校园招聘50人备考题库及参考答案详解1套
- 2025-2026学年苏教版(2024)小学科学一年级上册期末综合测试卷及答案
- 施工单位商务汇报体系
- Python程序设计基础及实践(慕课版 第2版)课件 郭炜 1. Python初探 -7. 组合数据类型(3)字典和集合
- 15189认可培训课件
评论
0/150
提交评论