612.1.002 ALGS4 | Analysis of Algorithms
我们生活在大数的时代
培养数量级的敏感!
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的更多相关文章
- 算法分析 Analysis of Algorithms -------GeekforGeeker 翻译
算法分析 Analysis of Algorithms 为什么要做性能分析?Why performance analysis? 在计算机领域有很多重要的因素我们要考虑 比如用户友好度,模块化, 安全性 ...
- 6.046 Design and Analysis of Algorithms
课程信息 6.046 Design and Analysis of Algorithms
- "Mathematical Analysis of Algorithms" 阅读心得
"Mathematical Analysis of Algorithms" 阅读心得 "Mathematical Analysis of Algorithms" ...
- 《Mathematical Analysis of Algorithms》中有关“选择第t大的数”的算法分析
开头废话 这个问题是Donald.E.Knuth在他发表的论文Mathematical Analysis of Algorithms中提到的,这里对他的算法分析过程给出了更详细的解释. 问题描述: 给 ...
- 612.1.003 ALGS4 | Stacks and Queues
Algorithm | Coursera - by Robert Sedgewick Type the code one by one! 不要拜读--只写最有感触的!而不是仅仅做一个笔记摘录员,那样毫 ...
- 612.1.004 ALGS4 | Elementary Sorts - 基础排序算法
sublime编辑器写代码,命令行编译 减少对ide的依赖//可以提示缺少什么依赖import 所有示例代码动手敲一遍 Graham's Scan是经典的计算几何算法 shffule 与 map-re ...
- Analysis of Algorithms
算法分析 Introduction 有各种原因要求我们分析算法,像预测算法性能,比较不同算法优劣等,其中很实际的一条原因是为了避免性能错误,要对自己算法的性能有个概念. 科学方法(scientific ...
- Analysis of algorithms: observation
例子: 3-Sum 给定N个整数,这里面有多少个三元组,使其三个整数相加为0,如上面的例子为有4个三元组. 这个问题是许多问题如计算机几何,图形学等的基础. 用简单粗暴的方式来解决3-Sum问题 通过 ...
- Time complexity analysis of algorithms
时间复杂性的计算一般而言,较小的问题所需要的运行时间通常要比较大的问题所需要的时间少.设一个程序P所占用的时间为T,则 T(P)=编译时间+运行时间. 编译时间与实例特征是无关的,且可假设一个编译过的 ...
随机推荐
- A Node Influence Based Label Propagation Algorithm for Community detection in networks 文章算法实现的疑问
这是我最近看到的一篇论文,思路还是很清晰的,就是改进的LPA算法.改进的地方在两个方面: (1)结合K-shell算法计算量了节点重重要度NI(node importance),标签更新顺序则按照NI ...
- 剑指offer二十九之最小的K个数
一.题目 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. 二.思路 详解代码. 三.代码 import java.util. ...
- 【数组】Sort Colors
题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same ...
- NLP 装桶(Bucketing)和填充(padding)
翻译模型也是用了装桶(bucketing)和填充(padding),这两种方法是用于高效地处理不同长度句子的情况.我们首先来弄清楚是怎么一回事.当我们从英语翻译成法语的时候,假设我们的输入英语的长度为 ...
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
什么是ApplicationContext? 它是spring的核心,Context我们通常解释为上下文环境,但是理解成容器会更好些. ApplicationContext则是应用的容器. Sprin ...
- ruby 中的 module
Module是Class的父类: >> Class.superclass => Module module 没有实例变量 module 没有new不能生成实例对象 module内可以 ...
- 【LeetCode题解】21_合并两个有序链表
目录 21_合并两个有序链表 描述 解法一:迭代 思路 Java 实现 Python 实现 解法二:递归 思路 Java 实现 Python 实现 21_合并两个有序链表 描述 将两个有序链表合并为一 ...
- [Codeforces 925C]Big Secret
Description 题库链接 给出 \(n\) 个数,让你生成这 \(n\) 个数的一个排列 \(A\) .定义 \(B_i = \bigoplus\limits_{j=1}^i A_j\) , ...
- const 指针
使用指针时要涉及两个目标,即指针本身和指针所指的对象.关于const指针变量,可归结为以下三种: 1.指向常量的指针变量: 2.常指针变量: 3.指向常量的常指针变量. 一.指向常量的指针变量:声明格 ...
- [转][C#] 对List<T>取交集、连集及差集
本文转自:http://www.cnblogs.com/shuibin/archive/2012/04/19/2457867.html 最近在專案中,剛好遇到這個需求, 需要比對兩個List,進行一些 ...

