用bitmap实现中位数的算法
来源:互联网 发布:云计算服务器搭建 编辑:程序博客网 时间:2024/06/10 07:15
50亿个整数,内存限制为1G,找出中位数。
50亿个整数用bitmap来存储的话,大约150M的空间就足够了。
下面是具体的算法,用PHP实现
define("MASK", 0x1f);$source = array(1, 74, 4, 256, 1024, 110, 111, 112, 123, 112, 100);$array = array();$count = 0;foreach($source as $num) {set($num); // add to bit map}$count = intval($count >> 1) + 1; // cal middle numberfor($i = 0;;$i++) { // travel the bit map and find the middle number$num = $array[$i];if(!$num) {continue;}$sum = 0;while($num) {if($num & 0x1) {if(!--$count) {echo ($i << 5) + $sum;exit;}}$num >>= 1;$sum++;}}/* * set number to bit map */function set($i) {global $array;global $count;$temp = (1 << ($i & MASK));$array[$i >> 5] |= $temp;if($temp) {$count++;}}
- 用bitmap实现中位数的算法
- BFPRT(中位数的中位数)算法
- 《算法导论的Java实现》 10 中位数和顺序统计学
- 算法实现——X和Y的中位数问题
- 算法导论——(1)加权中位数的实现
- java实现Bitmap算法
- 实现bitmap算法
- 算法----中位数算法的妙用(更新中)
- bitmap算法的介绍
- 算法学习 - bitmap实现(c++)
- 海量数据处理系列----C++中Bitmap算法的实现
- 海量数据处理系列----C++中Bitmap算法的实现
- 海量数据处理系列----C++中Bitmap算法的实现
- 海量数据处理系列----C++中Bitmap算法的实现
- 【数据结构】位图BitMap、布隆过滤器的算法实现
- BitMap算法用于磁盘文件排序的原理与实现
- 【转】 海量数据处理系列----C++中Bitmap算法的实现
- No.14 【大数据算法】BitMap的原理和实现
- 奇异函数
- 服务中监视会话切换
- 使用RHManagedObjectContextManager 来进行 CoreData的数据处理
- 拿win7学习php+mysql比较坑爹呀
- assert()函数用法总结
- 用bitmap实现中位数的算法
- 设计模式与实例代码:Template Method模式
- iOS5系统API和5个开源库的JSON解析速度测试
- Tarjan算法
- 浅谈创业计划书
- ASSERT()和assert() | const,static和volatile要注意的几个问题 |define宏与const区别
- s2si配置
- Mac OS X 平台上的开发利器---XCode
- 第8周实验报告3