02 2012 档案

loop invariant for Iterative algorithm {make progress: i-1 --> i?}
摘要:Repetition is an opportunity.Reconsidering Simple ExamplesA good martial arts student will attentively repeat each fundamental technique many times.In contrast, many college students tune out when a concept (eg. depth first search) is taught more than once.The better students listen carefully in ord 阅读全文

posted @ 2012-02-21 19:45 grepp 阅读(359) 评论(0) 推荐(0)

Math basic
摘要:Constant5Poly logarithmetic(logn)5Polynomialn5Exponential25nExp2n5Double Exp225nlinearO(n)QuadraticO(n2)CubicO(n3)高斯求和 wiki link12345......n=n(n+1)/2nn-1n-2n-3n-4......1=几何求和wiki link1248...2n=2(n+1)-11qq2q3...qn=(qn+1-1)/(q-1):proof:1+q+q2+q3+...+qn = Sn q+q2+q3+...+qn+qn+1 = qSn-qn+1 - 1 = (... 阅读全文

posted @ 2012-02-21 12:54 grepp 阅读(117) 评论(0) 推荐(0)

Recursive : Divide and Conquer
摘要:Consider your input instanceAllocate workconstruct one or more sub-instances 1assume by magic your friends give you the answer for these,trust your friends to sovle sub problem. 2 each sub-instance must be a smaller instance of the same problem.Use this help to solve your own instance.Do NOT... 阅读全文

posted @ 2012-02-20 22:17 grepp 阅读(130) 评论(0) 推荐(0)

Gauss's complex multiplication algorithm
摘要:wiki link for gauss multipilicationmulti(x,y)if |x| = |y| =1, then returen xybreak X into a,b and Y into c,de=multi(a,c) and f=multi(b,d)return e* 10n +(multi(a+b,c+d)-e-f)10n/2+fO(nlog23) < O(n2)stack of frames list as below:X=2133X=2133x=2133x=2133x=2133Y=2312Y=2312y=2312y=2312y=2312ac=ac=ac=ac 阅读全文

posted @ 2012-02-20 20:39 grepp 阅读(198) 评论(0) 推荐(0)

OS
摘要:resources:CPU+RAM+IO+DISKkernel: manages all the physical resources of the computer.File systems and structures.Device management,such as storing data to the hard disk.Process management or CPU functions.Memory management.virtual memory operating system: enable execution of programs as if more memor 阅读全文

posted @ 2012-02-20 10:17 grepp 阅读(93) 评论(0) 推荐(0)

Reference API
摘要:Reference typessoft: for cachingweak: for fast cleanup (pre-finalizer)phantom: for safe cleanup (post-finalizer)Reference queues: for notificationsSoft references: for quick-and-dirty caching onlyCleared when the VM runs low on memoryHopefully in LRU fashionTuned with -XX:SoftRelLRUPolicyMSPerMBhow 阅读全文

posted @ 2012-02-19 01:28 grepp 阅读(188) 评论(0) 推荐(0)

java7
摘要:try with resources: new with java7try(FileInputStream in = new FileInputStream(file)){//blabla}//不要再写下面的这个玩意了。//finally{//in.close();//} 阅读全文

posted @ 2012-02-19 00:30 grepp 阅读(118) 评论(0) 推荐(0)

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 阅读(298) 评论(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 阅读(146) 评论(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 阅读(259) 评论(0) 推荐(0)

导航