![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithm
文章平均质量分 64
breeze_gao
I'm Singing, Amen I'm Alive!
I'm Alive, Amen I'm singing!
展开
-
Qiuck Sort
<br />Quick Sort is a divide and conquer algorithm.<br /> <br />erlang code:<br />%implements the partition method. Just for demonstration. Actually you can use BIF lists:partition(Cmp, List).part([], _, Smaller, Larger) -> {Smaller, Larger};part([H|L]原创 2011-04-13 15:01:00 · 465 阅读 · 0 评论 -
find the kth largest element in a list and find the first k largest elements in a list
<br />Problem 1: Given an unordered list, find the kth largest element in this list.<br /><br />Solution 1<br /> sort this list and you can immediately get the kth largest element.<br /> The time-complexity is O(NlogN).<br /> <br />Solution 2<br /> py原创 2011-04-14 16:17:00 · 1286 阅读 · 0 评论 -
bitwise trie tree 的参考实现-nedtries简单解析
trie tree 是一种公共前缀树,(和关联规则的一种算法frequent-pattern growth算法的数据结构相同),具体定义见wiki。上面为一棵trie tree,直观上看,如这种数据结构做索引,应该不错,事实也是如此:)。节点值为0/1的trie tree,称为bitwise trie。bitwise trie是一个二叉查找trie tree。下面看nedtri原创 2013-03-08 16:53:29 · 2155 阅读 · 0 评论 -
separate odd and even numbers in an array in O(n) time complexity and O(1) space complexity
Problem: as titleSolution: same as partition algorithm in quick sort./**after processing, odd number is in the left part, even number in the right part*/void separate(int a[], int size) { if (s原创 2013-03-26 16:53:30 · 632 阅读 · 0 评论 -
find the two same numbers in 1 million random numbers
Problem: There are two same numbers and other unique numbers in a set which contains 1 million random numbers totally. Find out the two same numbers.Ideas: If the range of numbers is small, we原创 2013-03-27 17:33:40 · 652 阅读 · 0 评论 -
时间缓存容器TimeCacheMap的实现
Storm中实现了一个容器,它里面的元素存一定时间,超过该时间的元素便可能被删除,以保证容器可以加入更多新容器。实现思想:初始化N个容器,N个容器组成链表,元素的最短存储时间为T,每次将新元素插入到链表头部的容器内,每隔T/(N-1)时间,将链表尾部的容器删除,同时在链表头部插入新容器,每次删除在N个容器中分别执行删除操作。可以每个元素的存储时间为:[T, T + T/(N-1)]在具体实原创 2013-07-16 14:45:08 · 2397 阅读 · 0 评论 -
多路归并排序
将一个大文件分割为小文件,对小文件进行内存排序,在对排序后的小文件做合并即可。关于合并,可以采用堆来实现,堆中存储每个小文件中的最小值,以此从堆中取出最小值,输入到结果文件,同时从最小值对应文件中取出下一个最小值,保持堆依然存储每个小文件的最小值。如果只需要对文件按键值分组(不关心键之间的顺序),则采用哈希函数,将不同的键值对应的记录划分到不同的文件,对子文件进行排序即可,然和直接合并子文件即原创 2013-07-16 14:49:58 · 694 阅读 · 0 评论 -
索引优先队列
一次广告投放会话(session)中,服务器会分别打印推送日志(push)、展示日志(show)(如果广告成功展示)和点击日志(click)(如果广告被点击),一次广告会话由唯一id标记,一个广告可能被点击多次,也可能不被点击。由于广告服务器的并发处理,同一id对应的推送日志,展示日志,点击日志可能不会按照原本的顺序出现(原本顺序指先推送后展示最后点击)。设计算法在内存有限的情况下,统计每一次广告原创 2013-07-16 14:46:08 · 1854 阅读 · 0 评论