Algorithms Notes (1) - Analysis of Algorithms

转载请注明出处:http://blog.csdn.net/cxsydjn/article/details/70464287

普林斯顿 《算法》第四版, Coursera公开课,by Prof. Robert Sedgewick。

The note focuses on analyzing the performance of algorithms with the scientific method.

The note corresponds to Chapter 1.4 of Algorithms, (@Princeton) and Week 1 of Algorithms, Part I, (@Coursera).

Analysis of Algorithms Introduction

Scientific method

Insight. [Knuth 1970s] Use scientific method to understand performance.

  • Scientific method, which is a framework for predicting performance and comparing algorithms.
    • Observe some feature of the natural world.
    • Hypothesize a model that is consistent with the observations.
    • Predict events using the hypothesis.
    • Verify the predictions by making further observations.
    • Validate by repeating until the hypothesis and observations agree.
  • Principles
    • Experiments must be reproducible.
    • Hypotheses must be falsifiable.

Experimental Algorithmics

  • Run the program for various input sizes and measure running time.

  • Data analysis

    • Standard plot. Plot running time T (N) vs. input size N.
    • Log-log plot. Plot running time T (N) vs. input size N using log-log scale.
  • Regression. Fit straight line through data points
  • Hypothesis. The running time is about XXX seconds

  • Doubling hypothesis. Quick way to estimate b in a power-law relationship. Run program, doubling the size of the input.

ExperAlgo

Mathematical Models

Mathematical models for running time.

  • Total running time: sum of cost × frequency for all operations.

    • Need to analyze program to determine set of operations.
    • Cost depends on machine, compiler.- Frequency depends on algorithm, input data.
  • Simplification 1: cost model

    • Cost model. Use some basic operation as a proxy for running time.
    • cost model = array accesses (we assume compiler/JVM do not optimize array accesses away!)
  • Simplification 2: tilde notation

    • Estimate running time (or memory) as a function of input size N. Ignore lower order terms.

      • when N is large, terms are negligible
      • when N is small, we don’t care
    • Technical definition.

f(N)g(N)limNf(N)g(N)=1

egAlgo

mathmodel

Order-of-Growth Classifications

  • Determine the order of growth of the running time of a program as a function of the input size.
  • Formulate a hypothesis for the running time of a program as a function of the input size by performing computational experiments.

class1

class2

Binary search: Java implementation

binsearch

Binary search: mathematical analysis

binsearchmath

Binary search application: 3-SUM

3SUM

Theory of Algorithms

  • Define tilde and order-of-growth notations.

types

notation

design

Memory

  • Calculate the amount of memory that a Java program uses a function of the input size.

basics

memory

memory2

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值