- 博客(4)
- 收藏
- 关注
原创 Counting sort
The running time of counting sort is O(n), and usually, the running time of sorting algorithms will be either O(n^2) or O(n lgn), the reason why counting sort is O(n) is that it doesn't have the comp
2013-03-27 07:12:04 687
原创 Trie + recursion + pruning to implement Boggle
If you want to know what Boggle is, please wiki or google it. Or refer to http://goo.gl/GythQ In this implementation, we need to use a dictionary. Go to http://goo.gl/vaq4Z to download it and as it
2013-03-18 04:00:10 1411
原创 数组中找出第k大的值
最简单的办法,就是先排序,然后把第K个值找出来,这样算法的复杂度为 O(nlgn). 其实还有一种更简单的方法,其平均复杂度 为 O(lgn),当然,最坏是 O(n^2). 这种算法就是利用了 quicksort 和二分查找 的做法。先把数组分成两个部分,左边一个部分比pivot小,另一边比pivot大。然后再观察pivot的位置,如果pivot的位置比 K大,那么那个第K个值就一定在pivot
2013-03-13 23:48:31 1220
原创 快速找出2到n所有的素数
public static ArrayList primeNumbers(int n) { if (n < 2) return null; ArrayList list = new ArrayList(); boolean[] prime = new boolean[n + 1]; for (int i = 2; i < n + 1; i++) { prime[i] = tr
2013-03-11 12:29:40 2653
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人