2012年3月16日

Java Puzzler

摘要: puzzler 1:does the following code compile?public class Puzzler { <T> T cast(T t, Class<T> clazz) { return clazz.cast(t); } <T> T nop(T t) { return cast(t, t.getClass()); }} 阅读全文

posted @ 2012-03-16 23:44 grepp 阅读(77) 评论(0) 推荐(0) 编辑

2012年3月12日

notes

只有注册用户登录后才能阅读该文。 阅读全文

posted @ 2012-03-12 13:55 grepp 阅读(3) 评论(0) 推荐(0) 编辑

2012年2月21日

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 阅读(333) 评论(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 阅读(115) 评论(0) 推荐(0) 编辑

2012年2月20日

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 阅读(122) 评论(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 阅读(188) 评论(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 阅读(90) 评论(0) 推荐(0) 编辑

2012年2月19日

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 阅读(179) 评论(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 阅读(116) 评论(0) 推荐(0) 编辑

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 阅读(275) 评论(0) 推荐(0) 编辑

导航