Guure

Winter Is Coming.
算法(第4版)-1.4.2 观察

总结:本小节讲述了观察的方法和步骤。

 

重点:

1. 定量观察:计算性任务的困难程度可以用问题的规模(输入的大小或是某个命令行参数的值)来衡量。

 

2. Stopwatch数据类型的elapsedTime()方法能够返回自它创建以来所经过的时间,以秒为单位。

public class Stopwatch {
    private final long start;
    public Stopwatch() {
        start = System.currentTimeMillis();
    }
    public double elapsedTime() {
        long now = System.currentTimeMillis();
        return (now - start) / 1000.0;
    }
}

 

3. 有说服力的猜想:程序在不同的计算机上运行时间之比通常是一个常数。

 

4. 幂次法则:T(N) = aN^b

许多自然和人工的现象都符合幂次法则,因此假设程序的运行时间符合幂次法则也是合情合理的。

posted on 2016-11-03 16:12  Guure  阅读(379)  评论(0)    收藏  举报