CLRS:max_heap and min_heap operation (pseudocode)
//max_heap
heap_maximum:return A[1] O(1);
Extract_Heap_maximum:swap(A[1],A[heap.size]) adjust up to down from A[1] to hold the max_heap character O(lgn) every stepfind max child
increase_Heap_max(i,key):[key>=A[i]],adjust down to up from A[i] toA[1] until satsify the max_heap O(lgn) every step find father
insert_heap_max:heap_size ++;A[heap.size]=key; increase_heap_max(heap.size,key) O(lgn) find father
//min_heap
heap_minimum:return A[1] O(1);
Extract_Heap_miniimum:swap ,adjust find min child; O(lgn)
decrease_heap_min:change value ,adjust up find smaller father O(lgn)
CLRS:max_heap and min_heap operation (pseudocode)的更多相关文章
- Find Median from Data Stream
常规方法 超时 class MedianFinder { vector<int> coll; public: MedianFinder(){ } void heapfu(vector< ...
- (转)【C++ STL】细数C++ STL 的那些事 -- priority_queue(优先队列)
装载自http://blog.csdn.net/tianshuai1111/article/details/7652553 一,概述 priority_queue是拥有权值观念的queue,它允许加入 ...
- STL序列式容器学习总结
STL序列式容器学习总结 参考资料:<STL源码剖析> 参考网址: Vector: http://www.cnblogs.com/zhonghuasong/p/5975979.html L ...
- 剑指offer算法题
数组中只出现一次的数字(一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字): 解法在于位运算中的异或,直接异或可以得到这两个数的异或,按照最后的有效数字位可以 ...
- STL中heap相关函数
heap并不是属于STL中的containers,而是在<algorithm>下提供了相关的函数 make_heap,sort_heap,pop_heap,push_heap 函数的说明: ...
- 中位数II
该题目与思路分析来自九章算法的文章,仅仅是自己做个笔记! 题目:数字是不断进入数组的,在每次添加一个新的数进入数组的同时返回当前新数组的中位数. 解答: 这道题是用堆解决的问题.用两个堆,max he ...
- 终端mysql Operation not permitted错误解决方案
前言 前段时间装mysql,就遇到了ln: /usr/bin/mysql: Operation not permitted的错误,网上好多方法都过时了,下边是我的解决方法 原因 这是因为苹果在OS X ...
- SVN:Previous operation has not finished; run 'cleanup' if it was interrupted
异常处理汇总-开发工具 http://www.cnblogs.com/dunitian/p/4522988.html cleanup failed to process the following ...
- Mysql Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
MySQL字符串比较bug: select * from table_a a left join table_b b on a.field_a = b.field_b error: Illegal ...
随机推荐
- System.InvalidOperationException: Sequence contains no elements
foreach (var keyCode in unexpectedKeyCodesDetected) { string unexpected = expectedCapturedKeyCodes.W ...
- 转-Fragment+FragmentTabHost组件(实现新浪微博底部菜单)
http://www.cnblogs.com/lichenwei/p/3985121.html 记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果, ...
- vs2015-Azure Mobile Service
/App_Data /App_Start/ WebApiConfig.cs using System; using System.Collections.Generic; using System.C ...
- CSS根据屏幕分辨率应用相应样式
当屏幕尺寸小于1200px时,应用下面的CSS样式 @media screen and (max-width: 1200px) { /*当屏幕尺寸小于1200px时,应用下面的CSS样式*/ .ind ...
- CAP原则(CAP定理)
CAP原则又称CAP定理,指的是在一个分布式系统中, Consistency(一致性). Availability(可用性).Partition tolerance(分区容错性),三者不可得兼. CA ...
- mysql中游标的使用
BEGIN #遍历占领野地表还原军队 # and cityid=cityid) ,) ;#occupyWild表的TroopsId ,) ;#occupyWild表的CityId ,) ;#occup ...
- Python标准库04 文件管理 (部分os包,shutil包)
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在操作系统下,用户可以通过操作系统的命令来管理文件,参考linux文件管理相关命令 ...
- spring配置定时器的时间设置
时间大小由小到大排列,从秒开始,顺序为 秒,分,时,天,月,年 *为任意 ?为无限制. 具体如下: "0/10 * * * * ?" 每10秒触发 "0 0 12 ...
- DSS 搭建手机流媒体服务器
最近研究了一下手机流媒体服务器的搭建,目的是实现通过3G手机看在线视频. 开始的时候研究了一下 Tudou手机版 ,可它哪并没有实现在线播放,因为视频地址是 http 协议的.参看了许多文章,终于了解 ...
- freemarker空值的多种处理方法
默认情况下,freemarker的变量必须有值,如果没有被赋值的变量在页面上使用就会抛出异常,出错的信息都会显示在页面上. 解决办法: 方法一.我们可以在页面上使用freemarker变量时 以 ${ ...