O notation
This presentation is the property of its rightful owner.
Sponsored Links
1 / 23

O -Notation PowerPoint PPT Presentation


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

O -Notation. April 23, 2003 Prepared by Doug Hogan CSE 260. O -notation: The Idea. Big-O notation is a way of ranking about how much time it takes for an algorithm to execute How many operations will be done when the program is executed?

Download Presentation

O -Notation

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


O notation

O-Notation

April 23, 2003

Prepared by Doug Hogan

CSE 260


O notation the idea

O-notation: The Idea

  • Big-O notation is a way of ranking about how much time it takes for an algorithm to execute

  • How many operations will be done when the program is executed?

  • Find a bound on the running time, i.e. functions that are on the same order.

    • We care about what happens for large amounts of data  asymptotic order.


O notation the idea1

O-notation: The Idea

  • Use mathematical tools to find asymptotic order.

    • Real functions to approximate integer functions.

    • Depends on some variable, like n or X, which is usually the size of an array or how much data is going to be processed


O notation the complicated math behind it all

O-notationThe complicated math behind it all…

  • Given f and g, real functions of variable x…

  • First form:

    • g provides an upper bound for f ≡ graph of f lies closer to the x axis than g

  • More general form:

    • g provides an upper bound for f ≡ graph of f lies closer to the x axis than some positive multiple (M) of g after some minimum value of x(x0).


O notation a graphical view

O-notation: A graphical view


So what does closer to the x axis mean

So what does “closer to the x-axis” MEAN?

  • -M ∙ g(x) ≤ f(x) ≤ M ∙ g(x)

  • But that’s absolute value…

  • |f(x)| ≤ M ∙ |g(x)|


Another graphical view

Another graphical view

y

M ∙g

f

g

After x0, |f(x)| ≤ M ∙ |g(x)|

Before x0, nothing claimed about f’s growth

x

x0


Formal definition

Formal Definition

  • Let f and g be real-valued functions defined on the same set of reals.

  • f is of order g, written f(x) = O(g(x)), iff there exists

    • a positive real number M (multiple)

    • a real number x0 (starting point)

      such that for all x in the domain of f and g, |f(x)| ≤ M ∙ |g(x)| when x > x0


Example

Example

  • Use the definition of O-notationto express|17x6 – 3x3 + 2x + 8| ≤ 30|x6| for all x > 1

  • M = 30

  • x0 = 1

  • 17x6 – 3x3 + 2x + 8 is O(x6)


Graphically

Graphically…

17x6 – 3x3 + 2x + 8 is O(x6); M = 30; x0 = 1

30x6

17x6 – 3x3 + 2x + 8

x6


Problem

Problem

  • Use the definition of O-notationto express for all x > 6

  • M = 45

  • x0 = 6


Graphically1

Graphically…

M = 45; x0 = 6


Another graphical example

Another graphical example

f(x) = 7x3 - 2x + 3

12x3

x3

M = 12, x0 = 1 7x3 - 2x + 3 is O(x3)


Using o notation

Using O-notation…

  • Order of Power Functions:

    • For any rational numbers r and s, if r < s,

      xr is O(xs)

  • Order of Polynomial Functions:

    • If a0, a1,…, anare real numbers and an ≠ 0

      anxn+an-1xn-1 +… + a1x + a0is O(xm) for all m ≥ n


Examples

Examples

  • Example:

    • Find an order for

      • f(x) = 7x5 + 5x3 – x + 4 (all reals x)

    • O(x5)

    • Is that the only answer?

      • No…

      • But it’s the “best”


Showing that a function is not big o of another

Showing that a function is NOT Big-O of another…

  • Show that x2 is not O(x).

  • [Arguing by contradiction.] Suppose not, that x2 is O(x).

  • By definition of O(…), then there exist

    • a positive real number M

    • a real number x0

      such that |x2| ≤ M ∙ |x| for all x > x0 (1)


Showing that a function is not big o of another ctd

Showing that a function is NOT Big-O of another…, ctd.

  • Let x be a positive real number greater than both M and x0, i.e. x>M and x>x0.

  • Then by multiplying both sides of x>M by x, x∙x>M∙x.

  • Since x is positive, |x2|>M∙|x|.

  • So there is a real number x>x0 s.t. |x2|>M∙|x|.

  • This contradicts (1) above. So, the supposition is false and thus x2 is not O(x). □


Generalization

Generalization

  • If a0, a1,…, anare real numbers and an ≠ 0

    anxn+an-1xn-1 +… + a1x + a0is NOTO(xm) for all m<n


Best approximation

Best approximation

Definition

  • Suppose S is a set of functions from a subset of RtoR and fis a R->R function.

  • Function gis a best big-Oapproximation for f in Siff

    • f(x) is O(g(x))

    • for any h in S, if f(x) is O(h(x)), then g(x) is O(h(x)).


Problem1

Problem

  • Find best big-O approx for f(x) = 5x3 – 2x + 1

  • By thm. on polynomial orders,

    • f(x) is O(xn) for all n ≥ 3

  • By previous property,

    • f(x) is NOT O(xm) for all m < 3

  • So O(x3) is the best approximation.


O arithmetic

O-Arithmetic

Let f and g be functions and k be a constant.

  • O(k*f) = O(f)

  • O(f *g) = O(f) * O(g)

  • O(f/g) = O(f) / O(g)

  • O(f) ≥ O(g) iff f dominates* g

  • O(f + g) = Max[O(f), O(g)]

(Headington 546)


Dominance

Dominance

Let f and g be functions and a,b,m,n be constants.

  • xxdominates x!

  • x!dominates ax

  • axdominates bxif a > b

  • ax dominates xnif n > m

  • x dominates logaxif a > 1

  • logax dominateslogbxif b > a > 1

  • logax dominates1if a > 1

(Headington 547)


Works cited

Works Cited

Epp, Susanna. Discrete Mathematics with Applications. 2nd Ed. Belmont, CA: Brooks, 1995.

Headington, Mark A., and David Riley. Data Abstraction and Structures using C++. Lexington, MA: Heath, 1994.


  • Login