我们生活在大数的时代

培养数量级的敏感!

Tip:见招拆招

  • 作为工程师,你先要能实现出来。
  • 充实基础,没有什么不好意思
  • 哪怕不完美。但是有时候完成比完美更重要。
  • 之后再去想优化

P.S.作者Robert Sedgewick的导师是Knuth(高德纳!)

Conclusion First

1.Running Time

  • Operation table

2.Memory

1 SOP - Analysis

2 Observations

  • Measuring the running time - automatic

public class Stopwatch(part of stdlib.jar/algs4.course)


public static void main(String[] args) {
In in = new In(args[0]);
int[] a = in.readAllInts(); Stopwatch timer = new Stopwatch();
int count = count(a);
StdOut.println("elapsed time = " + timer.elapsedTime());//time since creation (in seconds)
StdOut.println(count);
}

3 Mathematical Model - Knuth(高德纳!)

Simplification 1: cost model

Simplification 2: tilde notation

approximate

工程近似

  • Bottom line. Use cost model and tilde notation to simplify counts.

4 Order of growth

  • Operation table

5 Binary Search - code 二分搜索

不看代码自己写

public static int binarySearch(int[]a,int key)
{
int lo=0;
int hi=a.length-1;
while(lo<=hi){
int mid=lo+(hi-lo)/2;
if(key>a[mid])lo=mid+1;
else if(key<a[mid])hi=mid-1;
else return mid;
}
return-1;
}

6 Memory

Typical memory usage of Java

Object overhead - 对象开销

QuickUnion

612.1.002 ALGS4 | Analysis of Algorithms的更多相关文章

  1. 算法分析 Analysis of Algorithms -------GeekforGeeker 翻译

    算法分析 Analysis of Algorithms 为什么要做性能分析?Why performance analysis? 在计算机领域有很多重要的因素我们要考虑 比如用户友好度,模块化, 安全性 ...

  2. 6.046 Design and Analysis of Algorithms

    课程信息 6.046 Design and Analysis of Algorithms

  3. "Mathematical Analysis of Algorithms" 阅读心得

    "Mathematical Analysis of Algorithms" 阅读心得 "Mathematical Analysis of Algorithms" ...

  4. 《Mathematical Analysis of Algorithms》中有关“选择第t大的数”的算法分析

    开头废话 这个问题是Donald.E.Knuth在他发表的论文Mathematical Analysis of Algorithms中提到的,这里对他的算法分析过程给出了更详细的解释. 问题描述: 给 ...

  5. 612.1.003 ALGS4 | Stacks and Queues

    Algorithm | Coursera - by Robert Sedgewick Type the code one by one! 不要拜读--只写最有感触的!而不是仅仅做一个笔记摘录员,那样毫 ...

  6. 612.1.004 ALGS4 | Elementary Sorts - 基础排序算法

    sublime编辑器写代码,命令行编译 减少对ide的依赖//可以提示缺少什么依赖import 所有示例代码动手敲一遍 Graham's Scan是经典的计算几何算法 shffule 与 map-re ...

  7. Analysis of Algorithms

    算法分析 Introduction 有各种原因要求我们分析算法,像预测算法性能,比较不同算法优劣等,其中很实际的一条原因是为了避免性能错误,要对自己算法的性能有个概念. 科学方法(scientific ...

  8. Analysis of algorithms: observation

    例子: 3-Sum 给定N个整数,这里面有多少个三元组,使其三个整数相加为0,如上面的例子为有4个三元组. 这个问题是许多问题如计算机几何,图形学等的基础. 用简单粗暴的方式来解决3-Sum问题 通过 ...

  9. Time complexity analysis of algorithms

    时间复杂性的计算一般而言,较小的问题所需要的运行时间通常要比较大的问题所需要的时间少.设一个程序P所占用的时间为T,则 T(P)=编译时间+运行时间. 编译时间与实例特征是无关的,且可假设一个编译过的 ...

随机推荐

  1. <context:component-scan>详解 转发 https://www.cnblogs.com/fightingcoding/p/component-scan.html

    <context:component-scan>详解   默认情况下,<context:component-scan>查找使用构造型(stereotype)注解所标注的类,如@ ...

  2. eclipseGUI的可视化开发工具插件

    一   各种GUI开发插件的特色 Eclipse并不自带GUI的可视化开发工具,那么如果要在Eclipse进行可视化的GUI开发,就需要依靠第三方的插件. 1. Visual Editor Eclip ...

  3. 关于Class中的Signature属性

    1.Signature属性:https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.9 2.ClassSigna ...

  4. C/C++ -- Gui编程 -- Qt库的使用 -- 使用自定义类

    1.新建空Qt工程 2.新建C++类HelloQt 3.新建ui文件,添加部件,重命名主窗体(对话框)类名HelloQt,构建生成ui头文件 4.修改头文件helloqt.h #ifndef HELL ...

  5. 《垃圾回收的算法与实现》——GC标记-压缩算法

    基本算法 Mark-Compact与Mark-Sweep的第一阶段均为标记活跃对象,第二阶段则不同,压缩算法则是将活跃对象逻辑上移到一起. Lisp2算法 对象头中增加forwarding指针,其用法 ...

  6. Python的Django框架中forms表单类的使用方法详解

    用户表单是Web端的一项基本功能,大而全的Django框架中自然带有现成的基础form对象,本文就Python的Django框架中forms表单类的使用方法详解. Form表单的功能 自动生成HTML ...

  7. jQuery操纵cookie(原生javascript处理cookie)

    jQuery也是可以操作cookie的 1.首先下载jQuery.js 以及 jquery.cookie.js 这两个文件 2.安装(其实就是引用) <html>       <he ...

  8. crontab的用法

    转载于:点击打开链接   cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业. 由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动.关闭这个服务: / ...

  9. JS的作用域和声明提前

    首先介绍下Javascript的函数作用域的概念,然后了解下什么是作用域和声明提前,最后通过一个例子剖析Javascript的作用域链. 1.变量的作用域 稍微有些编程背景的都知道,变量的作用域分为两 ...

  10. Firebird 获取用户表及字段

    select rdb$relation_fields.rdb$relation_name table_name, rdb$relations.rdb$description table_des, rd ...