[princeton/Algotithm I/week1](4) Analysis of Algorithms

1.4 Analysis of Algorithms

  • introduction

  • observations 

  • mathematical models 

  • order-of-growth classifications

  • theory of algorithms

  • memory

 

1.4.1 Introduction:

1. the cast of characters:

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

2.Focus on the running time:

Babbage machine - how many times do you have to turn the crank?

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

3. Algorithms performance

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

4. better performance (success algorithms)

minimize the running time

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

In the 1970s, Kanoof, use the scientific method to understand the performance of algorithms in operation.

 

5. Scientific method applied to analysis algorithms 

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

1.4.2 Observations

1. running time of the program 

Examples: 3-sum problem 

[princeton/Algotithm I/week1](4) Analysis of Algorithms

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

2. measuring the running time 

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Plot running time T(N), input size N

[princeton/Algotithm I/week1](4) Analysis of Algorithms

3. log-log scale

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Fit the line: [princeton/Algotithm I/week1](4) Analysis of Algorithms

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

4. prediction and validation

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

5. ratios 

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

6. Key factors determine the running time 

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

1.4.3 Mathematical models

Cost of basic operations

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Example: 1-Sum

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Simplifying the calculation

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Tilde notation

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Example: 2-Sum

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Example: 3-Sum                                                                                                                       

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Estimating a discrete sum(calculus)

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Mathematical models for running time 

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

1.4.4 Order-of-growth classifications

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

Common order-of-growth classifications

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Binary search demo

[princeton/Algotithm I/week1](4) Analysis of Algorithms

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Mathematical analysis: Binary search

[princeton/Algotithm I/week1](4) Analysis of Algorithms

An [princeton/Algotithm I/week1](4) Analysis of Algorithms algorithm for 3-Sum

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Compare running time 

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

1.4.5 Theory of Algorithms

[princeton/Algotithm I/week1](4) Analysis of Algorithms

notations

[princeton/Algotithm I/week1](4) Analysis of Algorithms

example 1: 1-sum

[princeton/Algotithm I/week1](4) Analysis of Algorithms

example 2: 3-sum

[princeton/Algotithm I/week1](4) Analysis of Algorithms

The GAP between lower and upper bound

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

 

1.4.6 Memory

[princeton/Algotithm I/week1](4) Analysis of Algorithms

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

[princeton/Algotithm I/week1](4) Analysis of Algorithms

Typical memory usage summary

[princeton/Algotithm I/week1](4) Analysis of Algorithms

 

[princeton/Algotithm I/week1](4) Analysis of Algorithms