Computer Algorithms II Lecture Notes

11 September 2008 • Asymptotic Analysis


Outline

An Algorithm

Another Algorithm

Comparing Algorithms

Measuring Performance

Measuring Problems

Estimated Performance

Estimation Advantages

Estimate What?

Modeling Estimates

Functional Model

Sorting Example

Database Example

Estimate Comparisons

Bounding Functions

Upper-Bounds

Big-Oh Notation

Known Estimates

Constant Behavior

constant behavior

Logarithmic Behavior

log behavior

Linear Behavior

linear behavior

Log-Linear Behavior

log-linear behavior

Quadratic Behavior

quadratic behavior

Exponential Behavior

Exponential behavior

Factorial Behavior

Factorial behavior

A Behavior Hierarchy

A Family Portrait

Comments

Asymptotic Estimate Properties

Producing Estimates

Structural Analysis

Running Example

Statements

if Statement

if Example

Statement Sequence

Sequence Example

Loops

Loop Overhead

Loop Example

To Finish.

To Finish..

Subroutines

Be Wary

Constants

Input and Output

Remember This?

string read

while getline(cin, str)
  read += str

for i = 0 to read.size()
  if read[i] == '<'
    // process tag

And This?

string read

while getline(cin, str)
  read += str
  for i = 0 to read.size()
    if read[i] == '<'
      // process tag
      read[i] = ' '

Let's Estimate!

while getline(cin, str)
  read += str

for i = 0 to read.size()
  if read[i] == '<'
    // process tag

Basic Statements

while getline(cin, str) : O(1)
  read += str : O(1)

for i = 0 to read.size() : O(1)
  if read[i] == '<' : O(1)
    // process tag : O(1)

Compound Statements

while O(1) : O(n)
  O(1)

for O(1)
  if O(1) : O(1)
    O(1)

Iteration Statements

O(n)

for O(1) : O(1)
  O(1)

Statement Sequences

O(n)

O(n)

Second Program

while getline(cin, str) : O(1)
  read += str : O(1)
  for i = 0 to read.size() : O(1)
    if read[i] == '<' : O(1)
      // process tag : O(1)
      read[i] = ' ' : O(1)

Compound Statements

while O(1)
  O(1)
  for O(1)
    if O(1)
      O(1)
      O(1)

while O(1)
  O(1)
  for O(1)
    O(1)

while O(1)
  O(1)
  O(n)

Finishing Up

while O(1) : O(n)
  O(n)

Does It?

Points to Remember


This page last modified on 11 September 2008.

Creative
    Commons License