Discrete mathematics summer 2006
This presentation is the property of its rightful owner.
Sponsored Links
1 / 35

Discrete Mathematics Summer 2006 PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on
  • Presentation posted in: General

Discrete Mathematics Summer 2006. By Dan Barrish-Flood originally for Fundamental Algorithms For use by Harper Langston in D.M. What is an Algorithm?. A problem is a precise specification of input and desired output

Download Presentation

Discrete Mathematics Summer 2006

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Discrete mathematics summer 2006

Discrete Mathematics Summer 2006

By Dan Barrish-Flood originally for Fundamental Algorithms

For use by Harper Langston in D.M.


What is an algorithm

What is an Algorithm?

  • A problem is a precise specification of input and desired output

  • An algorithm is a precise specification of a method for solving a problem.


What we want in an algorithm

What We Want in an Algorithm

  • Correctness

    • Always halts

    • Always gives the right answer

  • Efficiency

    • Time

    • Space

  • Simplicity


A typical problem

A Typical Problem

Sorting

  • Input:

    • A sequence b1, b2, ... bn

  • Output:

    • A permutation of that sequence b1, b2, ... bnsuch that


A typical algorithm

A Typical Algorithm


Running time

Running Time

tJ is the number of times the “while” loop test in line 5 is executed for that value of j. Total running time is

c1 (n) + c2(n-1) +…+c8(n-1)


A better way to estimate running time

A Better Way to Estimate Running Time

  • Trying to determine the exact running time is tedious, complicated and platform-specific.

  • Instead, we’ll bound the worst-case running time to within a constant factor for large inputs.

  • Why worst-case?

    • It’s easier.

    • It’s a guarantee.

    • It’s well-defined.

    • Average case is often no better.


Insertion sort redux

Insertion Sort, Redux

  • Outer loop happens about n times.

  • Inner loop is done j times for each j, worst case.

  • j is always < n

  • So running time is upper-bounded by about

“Insertion sort runs in q(n2) time, worst-case.”


Discrete mathematics summer 2006

  • We’ll make all the “about”s and “rough”s precise.

  • These so-called asymptotic running times dominate constant factors for large enough inputs.


Functions

Functions

  • constants

  • polynomials

  • exponentials

  • logarithms and polylogarithms

  • factorial


Polynomials

Polynomials


Discrete mathematics summer 2006

f(n) is monotonically increasing iff

I.e. It never “goes down” — always increases or stays the same.

For strictly increasing, replace £ in the above with <.

I.e. The function is always going up.


Discrete mathematics summer 2006

Are constant functions monotonically increasing?

Yes! (But not strictly increasing.)

If , then is strictly increasing.

So even increases forever to


Exponentials

Exponentials


Logarithms

Logarithms


Log facts

n = b log b n (definition)

logb(xy)=logbx + logby

logban= nlogba

logbx = logcx / logcb

logb(1/a) = -logba

logba = 1/(logab)

alogbc= clogba

if b > 1, then logbn is strictly increasing.

Log Facts


More about logs

More About Logs

A polylogarithm is just


Factorial

Factorial


More about monotonically increasing functions

More About Monotonically Increasing Functions


Bounding functions

Bounding Functions

  • We are more interested in finding upper and lower bounds on functions that describe the running times of algorithms, rather than finding the exact function.

  • Also, we are only interested in considering large inputs: everything is fast for small inputs.

  • So we want asymptotic bounds.

  • Finally, we are willing to neglect constant factors when bounding. They are tedious to compute, and are often hardware-dependent anyway.


Example

Example


Notation for function bounds

Notation for Function Bounds


Big oh facts

Big-Oh Facts

  • The “=” is misleading. E.g

  • It denotes an upper bound, not necessarily a tight bound. Thus,

is meaningless.

  • Transitivity:


Examples

Examples

We’ve seen that 3n + 8 = O(n).

Is 10n = O(3n + 8)?

Yes: choose c = 10, n0 = 1:

10n£ 30n+ 80


More examples

More Examples

2n2 + 5n - 8 = O(n2)?

Yes:

2n2 + 5n - 8 £ cn2

¸n2: 2 + 5/n - 8/n2£c

Choose c = 3; subtracting 2:

5/n - 8/n2£ 1

Choose no = 5


More examples1

More Examples


Lower bound notation

Lower Bound Notation


Tight bound notation

“Tight” Bound Notation


More facts

More Facts


Examples1

Examples


Another upper bound notation

Another Upper-Bound Notation


Functions and bounds

Functions and Bounds


Logarithms1

Logarithms


Polynomials1

Polynomials


Comparing functions

Comparing Functions


  • Login