- 125 Views
- Uploaded on
- Presentation posted in: General

O -Notation

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 - - - - - - - - - - - - - - - - - - - - - - - - - -

O-Notation

April 23, 2003

Prepared by Doug Hogan

CSE 260

- 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.

- 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

- 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).

- -M ∙ g(x) ≤ f(x) ≤ M ∙ g(x)
- But that’s absolute value…
- |f(x)| ≤ M ∙ |g(x)|

y

M ∙g

f

g

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

Before x0, nothing claimed about f’s growth

x

x0

- 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

- 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)

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

30x6

17x6 – 3x3 + 2x + 8

x6

- Use the definition of O-notationto express for all x > 6
- M = 45
- x0 = 6

M = 45; x0 = 6

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

12x3

x3

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

- Order of Power Functions:
- For any rational numbers r and s, if r < s,
xr is O(xs)

- For any rational numbers r and s, if r < s,
- 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

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

- 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”

- Find an order for

- 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)

- 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). □

- If a0, a1,…, anare real numbers and an ≠ 0
anxn+an-1xn-1 +… + a1x + a0is NOTO(xm) for all m<n

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)).

- 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.

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)

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)

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.