2012年2月18日

Median

摘要: 我们知道排序的开销是nlogn,证明如下:n 个节点的permutation是n!binary tree的高度至少是 logn!logn! >nlogn [这儿实际上是log2n ]现在我们要找到n个元素中的median,通过排序肯定是可以的,缺点是O(nlogn).而我们的理想算法是接近线性的。应该是可以的,因为排序明显是做的有点过了。我只需要找到median,我可不管你最后是不是排序的。randomized divide-and-conquer algorithm for selectionfor any number u, image splitting the list U in 阅读全文

posted @ 2012-02-18 22:29 grepp 阅读(278) 评论(0) 推荐(0) 编辑

RSA Reloaded

摘要: pick two large (n-bit) random prime p and q.public key is (N,e) where N=pq and e is a (2n-bit) number relatively prime to (p-1)(q-1).A common choice is e =3 because it permits fast encoding.secret key is d, the inverse of e modulo (p-1)(q-1), computed using the extended euclid algorithm.Instances:pu 阅读全文

posted @ 2012-02-18 20:25 grepp 阅读(143) 评论(0) 推荐(0) 编辑

乘法的算法

摘要: 两种思路一个是Divide and conquer(recursive)另一个是binary 算法def multiply(x,y): if y ==0: return 0 z = multiply(x,y/2) if y%2 ==0: return 2*z else: return x +2*z#就是小时候学的叠罗汉的乘法#multiply2(x,y)def multiply2(x,Y): if(y==0): return 0 r = 0 while(x !=0): if(x%2 !=0 ): r +=y x = x/... 阅读全文

posted @ 2012-02-18 15:32 grepp 阅读(226) 评论(0) 推荐(0) 编辑

导航