cse 373: asymptotic analysis · 2018-03-11 · lasttime twostepprocess:...

58
CSE 373: Asymptotic Analysis Michael Lee Wednesday, Jan 10, 2018 1

Upload: others

Post on 10-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

CSE 373: Asymptotic Analysis

Michael LeeWednesday, Jan 10, 2018

1

Page 2: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Warmup

Warmup: construct a mathematical function modeling theworst-case runtime of this method. Your model should be writtenin terms of q, the provided input integer.

Assume each println takes some constant c time to run.

public void mystery(int q)

for (int i = 0; i < q; i++)

for (int j = 0; j < q * q; j++)

System.out.println("Hello");

for (int j = 0; j < 10; j++)

System.out.println("World");

Answer: T (q) = q(cq2 + 10c) = cq3 + 10cq

2

Page 3: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Warmup

Warmup: construct a mathematical function modeling theworst-case runtime of this method. Your model should be writtenin terms of q, the provided input integer.

Assume each println takes some constant c time to run.

public void mystery(int q)

for (int i = 0; i < q; i++)

for (int j = 0; j < q * q; j++)

System.out.println("Hello");

for (int j = 0; j < 10; j++)

System.out.println("World");

Answer: T (q) = q(cq2 + 10c) = cq3 + 10cq

2

Page 4: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Last time

Two step process:

1. Model what we care about as a mathematical function2. Analyze that function using asymptotic analysis

Specifically: have a way to compare two functionsEven more specifically: define a “less then or equal to”operator for functions

3

Page 5: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Last time

Two step process:

1. Model what we care about as a mathematical function2. Analyze that function using asymptotic analysis

Specifically: have a way to compare two functions

Even more specifically: define a “less then or equal to”operator for functions

3

Page 6: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Last time

Two step process:

1. Model what we care about as a mathematical function2. Analyze that function using asymptotic analysis

Specifically: have a way to compare two functionsEven more specifically: define a “less then or equal to”operator for functions

3

Page 7: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

Question: Should we treat these two functions the same?

n

T (n)

4

Page 8: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

What about now?

n

T (n)

Intuition: our quadratic function is dominating the linear ones

Intuition: our linear functions (eventually) look the same

5

Page 9: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

What about now?

n

T (n)

Intuition: our quadratic function is dominating the linear ones

Intuition: our linear functions (eventually) look the same

5

Page 10: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

What about now?

n

T (n)

Intuition: our quadratic function is dominating the linear ones

Intuition: our linear functions (eventually) look the same

5

Page 11: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

Let’s zoom in...

n

T (n)

Intuition: quadratic function eventually dominates the linear ones

6

Page 12: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

Let’s zoom in...

n

T (n)

Intuition: quadratic function eventually dominates the linear ones

6

Page 13: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

Our goal:

I We want a way to say n2 eventually dominates n

I We want a way to treat n and 4n the same wayIntuition:I Model made simplifying assumptions about constant factorsI Can usually improve constant-factor differences by being clever

I We want a way to do this rigorously!

7

Page 14: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

Our goal:

I We want a way to say n2 eventually dominates nI We want a way to treat n and 4n the same way

Intuition:I Model made simplifying assumptions about constant factorsI Can usually improve constant-factor differences by being clever

I We want a way to do this rigorously!

7

Page 15: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

Our goal:

I We want a way to say n2 eventually dominates nI We want a way to treat n and 4n the same way

Intuition:I Model made simplifying assumptions about constant factorsI Can usually improve constant-factor differences by being clever

I We want a way to do this rigorously!

7

Page 16: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Function comparison: exercise

True or false?

I Is n “less then or equal to” 5n + 3?

True

I Is 5n + 3 “less then or equal to” n?

True

I Is 5n + 3 “less then or equal to” 1?

False

I Is 5n + 3 “less then or equal to” n2?

True

I Is n2 + 3n + 2 “less then or equal to” n3?

True

I Is n3 “less then or equal to” n2 + 3n + 2?

False

8

Page 17: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Function comparison: exercise

True or false?

I Is n “less then or equal to” 5n + 3? TrueI Is 5n + 3 “less then or equal to” n? TrueI Is 5n + 3 “less then or equal to” 1? FalseI Is 5n + 3 “less then or equal to” n2? TrueI Is n2 + 3n + 2 “less then or equal to” n3? TrueI Is n3 “less then or equal to” n2 + 3n + 2?False

8

Page 18: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Analysis: comparing functions

Our goal:

I We want a way to say n2 eventually dominates nI We want a way to treat n and 4n the same way

9

Page 19: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Let’s formalize this...

Idea 1A function f (n) is “less then or equal to” g(n) when f (n) ≤ g(n)is true for all values of n ≥ 0.

Does this work?

Remember this?

n

T (n)

Problem: incorrectly handlesthe quadratic function!

10

Page 20: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Let’s formalize this...

Idea 1A function f (n) is “less then or equal to” g(n) when f (n) ≤ g(n)is true for all values of n ≥ 0.

Does this work? Remember this?

n

T (n)

Problem: incorrectly handlesthe quadratic function!

10

Page 21: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Let’s formalize this...

Idea 1A function f (n) is “less then or equal to” g(n) when f (n) ≤ g(n)is true for all values of n ≥ 0.

Does this work? Remember this?

n

T (n)

Problem: incorrectly handlesthe quadratic function!

10

Page 22: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Let’s formalize this...

Idea 2A function f (n) is “less then or equal to” g(n) when f (n) ≤ g(n)is true for all values of n ≥ n0.

...where n0 > 0 is some constant value.

Does it work now?

We previously said we want to treat n and 4n as being the “same”.Do we?

Problem: No, we don’t!

11

Page 23: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Let’s formalize this...

Idea 2A function f (n) is “less then or equal to” g(n) when f (n) ≤ g(n)is true for all values of n ≥ n0.

...where n0 > 0 is some constant value.

Does it work now?

We previously said we want to treat n and 4n as being the “same”.Do we?

Problem: No, we don’t!

11

Page 24: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Let’s formalize this...

Idea 2A function f (n) is “less then or equal to” g(n) when f (n) ≤ g(n)is true for all values of n ≥ n0.

...where n0 > 0 is some constant value.

Does it work now?

We previously said we want to treat n and 4n as being the “same”.Do we?

Problem: No, we don’t!

11

Page 25: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Let’s formalize this...

Idea 3A function f (n) is “less then or equal to” g(n) whenf (n) ≤ c · g(n) is true for all values of n ≥ n0.

...where n0 > 0 is some constant value.

...where c > 0 is some constant value.

Does it work now?

Yes!

12

Page 26: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Let’s formalize this...

Idea 3A function f (n) is “less then or equal to” g(n) whenf (n) ≤ c · g(n) is true for all values of n ≥ n0.

...where n0 > 0 is some constant value.

...where c > 0 is some constant value.

Does it work now?

Yes!

12

Page 27: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definition: Dominated by

Definition: Dominated byA function f (n) is dominated by g(n) when...

I There exists two constants c > 0 and n0 > 0...I Such that for all values of n ≥ n0...I f (n) ≤ c · g(n) is true

The formal definition (not necessary to know this):Formal definition: Dominated byA function f (n) is dominated by g(n) when

∃(c > 0, n0 > 0). ∀(n ≥ n0). (f (n) ≤ cg(n))

...is true.

13

Page 28: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definition: Dominated by

Definition: Dominated byA function f (n) is dominated by g(n) when...

I There exists two constants c > 0 and n0 > 0...

I Such that for all values of n ≥ n0...I f (n) ≤ c · g(n) is true

The formal definition (not necessary to know this):Formal definition: Dominated byA function f (n) is dominated by g(n) when

∃(c > 0, n0 > 0). ∀(n ≥ n0). (f (n) ≤ cg(n))

...is true.

13

Page 29: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definition: Dominated by

Definition: Dominated byA function f (n) is dominated by g(n) when...

I There exists two constants c > 0 and n0 > 0...I Such that for all values of n ≥ n0...

I f (n) ≤ c · g(n) is true

The formal definition (not necessary to know this):Formal definition: Dominated byA function f (n) is dominated by g(n) when

∃(c > 0, n0 > 0). ∀(n ≥ n0). (f (n) ≤ cg(n))

...is true.

13

Page 30: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definition: Dominated by

Definition: Dominated byA function f (n) is dominated by g(n) when...

I There exists two constants c > 0 and n0 > 0...I Such that for all values of n ≥ n0...I f (n) ≤ c · g(n) is true

The formal definition (not necessary to know this):Formal definition: Dominated byA function f (n) is dominated by g(n) when

∃(c > 0, n0 > 0). ∀(n ≥ n0). (f (n) ≤ cg(n))

...is true.

13

Page 31: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definition: Dominated by

Definition: Dominated byA function f (n) is dominated by g(n) when...

I There exists two constants c > 0 and n0 > 0...I Such that for all values of n ≥ n0...I f (n) ≤ c · g(n) is true

The formal definition (not necessary to know this):Formal definition: Dominated byA function f (n) is dominated by g(n) when

∃(c > 0, n0 > 0). ∀(n ≥ n0). (f (n) ≤ cg(n))

...is true.13

Page 32: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Exercise

Demonstrate that 5n2 + 3n + 6 is dominated by n3 by finding a cand n0 that satisfy the above definition.

Idea: pick c = 10000 and n0 = 10000. (It probably works )

Better idea: show that 5n2 + 3n + 6 is dominated by an easierfunction to analyze. E.g. note that:

5n2 + 3n + 6 ≤ 5n2 + 3n2 + 6n2 for all n ≥ 1

= 14n2

≤ 14n3

So, what value of c makes 14n3 ≤ cn3 true (when n ≥ 1)?

One possible choice: n0 = 1 and c = 14.

So, since we know 5n2 + 3n + 6 ≤ 14n3 for n ≥ n0 and also know14n3 ≤ cn3, we conclude 5n2 + 3n + 6 ≤ cn3.

14

Page 33: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Exercise

Demonstrate that 5n2 + 3n + 6 is dominated by n3 by finding a cand n0 that satisfy the above definition.

Idea: pick c = 10000 and n0 = 10000. (It probably works )

Better idea: show that 5n2 + 3n + 6 is dominated by an easierfunction to analyze. E.g. note that:

5n2 + 3n + 6 ≤ 5n2 + 3n2 + 6n2 for all n ≥ 1

= 14n2

≤ 14n3

So, what value of c makes 14n3 ≤ cn3 true (when n ≥ 1)?

One possible choice: n0 = 1 and c = 14.

So, since we know 5n2 + 3n + 6 ≤ 14n3 for n ≥ n0 and also know14n3 ≤ cn3, we conclude 5n2 + 3n + 6 ≤ cn3.

14

Page 34: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Exercise

Demonstrate that 5n2 + 3n + 6 is dominated by n3 by finding a cand n0 that satisfy the above definition.

Idea: pick c = 10000 and n0 = 10000. (It probably works )

Better idea: show that 5n2 + 3n + 6 is dominated by an easierfunction to analyze. E.g. note that:

5n2 + 3n + 6 ≤ 5n2 + 3n2 + 6n2 for all n ≥ 1

= 14n2

≤ 14n3

So, what value of c makes 14n3 ≤ cn3 true (when n ≥ 1)?

One possible choice: n0 = 1 and c = 14.

So, since we know 5n2 + 3n + 6 ≤ 14n3 for n ≥ n0 and also know14n3 ≤ cn3, we conclude 5n2 + 3n + 6 ≤ cn3.

14

Page 35: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Exercise

Demonstrate that 5n2 + 3n + 6 is dominated by n3 by finding a cand n0 that satisfy the above definition.

Idea: pick c = 10000 and n0 = 10000. (It probably works )

Better idea: show that 5n2 + 3n + 6 is dominated by an easierfunction to analyze. E.g. note that:

5n2 + 3n + 6 ≤ 5n2 + 3n2 + 6n2 for all n ≥ 1

= 14n2

≤ 14n3

So, what value of c makes 14n3 ≤ cn3 true (when n ≥ 1)?

One possible choice: n0 = 1 and c = 14.

So, since we know 5n2 + 3n + 6 ≤ 14n3 for n ≥ n0 and also know14n3 ≤ cn3, we conclude 5n2 + 3n + 6 ≤ cn3.

14

Page 36: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Exercise

Demonstrate that 5n2 + 3n + 6 is dominated by n3 by finding a cand n0 that satisfy the above definition.

Idea: pick c = 10000 and n0 = 10000. (It probably works )

Better idea: show that 5n2 + 3n + 6 is dominated by an easierfunction to analyze. E.g. note that:

5n2 + 3n + 6 ≤ 5n2 + 3n2 + 6n2 for all n ≥ 1

= 14n2

≤ 14n3

So, what value of c makes 14n3 ≤ cn3 true (when n ≥ 1)?

One possible choice: n0 = 1 and c = 14.

So, since we know 5n2 + 3n + 6 ≤ 14n3 for n ≥ n0 and also know14n3 ≤ cn3, we conclude 5n2 + 3n + 6 ≤ cn3. 14

Page 37: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Exercise

Demonstrate that 2n3 − 3 + 9n2 +√

n is dominated by n3

(again by finding a c and n0).

Do the same thing. Note that:

2n3 − 3 + 9n2 +√

n ≤ 2n3 + 9n2 + n for all n ≥ 1

≤ 2n3 + 9n3 + n3

= 12n3

So, one possible choice of n0 and c is n0 = 1 and c = 12.

15

Page 38: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Exercise

Demonstrate that 2n3 − 3 + 9n2 +√

n is dominated by n3

(again by finding a c and n0).

Do the same thing. Note that:

2n3 − 3 + 9n2 +√

n ≤ 2n3 + 9n2 + n for all n ≥ 1

≤ 2n3 + 9n3 + n3

= 12n3

So, one possible choice of n0 and c is n0 = 1 and c = 12.

15

Page 39: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Families of functions

Observation:

I n, 5n + 3, 100n, etc... all dominate each otherI These three functions are the “same”

Idea: can we give a name to this “family” of functions?

Definition: Big-OO (f (n)) is the “family” or “set” of all functions that aredominated by f (n)

Question: are O (n), O (5n + 3), and O (100n) all the same thing?

Yes! By convention, we pick the “simplest” way of writing this andrefer to this “family” as O (n).

16

Page 40: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Families of functions

Observation:

I n, 5n + 3, 100n, etc... all dominate each otherI These three functions are the “same”

Idea: can we give a name to this “family” of functions?

Definition: Big-OO (f (n)) is the “family” or “set” of all functions that aredominated by f (n)

Question: are O (n), O (5n + 3), and O (100n) all the same thing?

Yes! By convention, we pick the “simplest” way of writing this andrefer to this “family” as O (n).

16

Page 41: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Families of functions

Observation:

I n, 5n + 3, 100n, etc... all dominate each otherI These three functions are the “same”

Idea: can we give a name to this “family” of functions?

Definition: Big-OO (f (n)) is the “family” or “set” of all functions that aredominated by f (n)

Question: are O (n), O (5n + 3), and O (100n) all the same thing?

Yes! By convention, we pick the “simplest” way of writing this andrefer to this “family” as O (n).

16

Page 42: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Families of functions

Observation:

I n, 5n + 3, 100n, etc... all dominate each otherI These three functions are the “same”

Idea: can we give a name to this “family” of functions?

Definition: Big-OO (f (n)) is the “family” or “set” of all functions that aredominated by f (n)

Question: are O (n), O (5n + 3), and O (100n) all the same thing?

Yes! By convention, we pick the “simplest” way of writing this andrefer to this “family” as O (n).

16

Page 43: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Families of functions

Observation:

I n, 5n + 3, 100n, etc... all dominate each otherI These three functions are the “same”

Idea: can we give a name to this “family” of functions?

Definition: Big-OO (f (n)) is the “family” or “set” of all functions that aredominated by f (n)

Question: are O (n), O (5n + 3), and O (100n) all the same thing?

Yes! By convention, we pick the “simplest” way of writing this andrefer to this “family” as O (n).

16

Page 44: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Families of functions

A question: Do the following two sentences mean the same thing?

I f (n) is dominated by g(n)I f (n) is contained inside O (g(n))

Yes!

We can write this more concisely as f (n) ∈ O (g(n)).

An aside: some people write this as f (n) = O (g(n))

This is wrong (but common, so we reluctantly accept this)

17

Page 45: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Families of functions

A question: Do the following two sentences mean the same thing?

I f (n) is dominated by g(n)I f (n) is contained inside O (g(n))

Yes!

We can write this more concisely as f (n) ∈ O (g(n)).

An aside: some people write this as f (n) = O (g(n))

This is wrong (but common, so we reluctantly accept this)

17

Page 46: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Families of functions

A question: Do the following two sentences mean the same thing?

I f (n) is dominated by g(n)I f (n) is contained inside O (g(n))

Yes!

We can write this more concisely as f (n) ∈ O (g(n)).

An aside: some people write this as f (n) = O (g(n))

This is wrong (but common, so we reluctantly accept this)

17

Page 47: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

A few more questions

True or false:

I 5n + 3 ∈ O (n)

True

I n ∈ O (5n + 3)

True

I 5n + 3 = O (n)

True (by convention)

I O (5n + 3) = O (n)

True

I O(n2)= O (n)

False

I n2 ∈ O (1)

False

I n2 ∈ O (n)

False

I n2 ∈ O(n2)

True

I n2 ∈ O(n3)

True

I n2 ∈ O(n100

)

True

18

Page 48: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

A few more questions

True or false:

I 5n + 3 ∈ O (n) TrueI n ∈ O (5n + 3) TrueI 5n + 3 = O (n) True (by convention)I O (5n + 3) = O (n) TrueI O

(n2)= O (n) False

I n2 ∈ O (1) FalseI n2 ∈ O (n) FalseI n2 ∈ O

(n2)

TrueI n2 ∈ O

(n3)

TrueI n2 ∈ O

(n100

)True

18

Page 49: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definitions: Dominates

f (n) ∈ O (g(n)) is like saying “f (n) is less then or equal to g(n)”.

Is there a way to say “greater then or equal to”?

Yes!

Definition: DominatesWe say f (n) dominates g(n) when:

I There exists two constants c > 0 and n0 > 0...I Such that for all values of n ≥ n0...I f (n) ≥ c · g(n) is true

Definition: Big-ΩΩ(f (n)) is the family of all functions that dominates f (n).

19

Page 50: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definitions: Dominates

f (n) ∈ O (g(n)) is like saying “f (n) is less then or equal to g(n)”.

Is there a way to say “greater then or equal to”? Yes!

Definition: DominatesWe say f (n) dominates g(n) when:

I There exists two constants c > 0 and n0 > 0...I Such that for all values of n ≥ n0...I f (n) ≥ c · g(n) is true

Definition: Big-ΩΩ(f (n)) is the family of all functions that dominates f (n).

19

Page 51: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definitions: Dominates

f (n) ∈ O (g(n)) is like saying “f (n) is less then or equal to g(n)”.

Is there a way to say “greater then or equal to”? Yes!

Definition: DominatesWe say f (n) dominates g(n) when:

I There exists two constants c > 0 and n0 > 0...I Such that for all values of n ≥ n0...I f (n) ≥ c · g(n) is true

Definition: Big-ΩΩ(f (n)) is the family of all functions that dominates f (n).

19

Page 52: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

A few more questions...

True or false?I 4n2 ∈ Ω(1)

True

I 4n2 ∈ Ω(n)

True

I 4n2 ∈ Ω(n2)

True

I 4n2 ∈ Ω(n3)

False

I 4n2 ∈ Ω(n4)

False

I 4n2 ∈ O (1)

False

I 4n2 ∈ O (n)

False

I 4n2 ∈ O(n2)

True

I 4n2 ∈ O(n3)

True

I 4n2 ∈ O(n4)

True

20

Page 53: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

A few more questions...

True or false?I 4n2 ∈ Ω(1) TrueI 4n2 ∈ Ω(n) TrueI 4n2 ∈ Ω

(n2)

TrueI 4n2 ∈ Ω

(n3)

FalseI 4n2 ∈ Ω

(n4)

False

I 4n2 ∈ O (1) FalseI 4n2 ∈ O (n) FalseI 4n2 ∈ O

(n2)

TrueI 4n2 ∈ O

(n3)

TrueI 4n2 ∈ O

(n4)

True

20

Page 54: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definition: Big-Θ

Definition: Big-ΘWe say f (n) ∈ Θ(g(n)) when both:

I f (n) ∈ O (g(n)) and...I f (n) ∈ Ω(g(n))

...are true.

Note: in industry, it’s common for many people to ask for thebig-O when they really want the big-Θ!

21

Page 55: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Definition: Big-Θ

Definition: Big-ΘWe say f (n) ∈ Θ(g(n)) when both:

I f (n) ∈ O (g(n)) and...I f (n) ∈ Ω(g(n))

...are true.

Note: in industry, it’s common for many people to ask for thebig-O when they really want the big-Θ!

21

Page 56: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Takeaways

Important things to know:

I Intuition behind the definitions of “dominated by” and big-O

I The precise definitions of:I “Dominated by” and big-OI “Dominates” and big-ΩI Big-Θ

I How to demonstrate that one function is dominated byanother by finding c and n0 and applying the correct definition

22

Page 57: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Takeaways

Important things to know:

I Intuition behind the definitions of “dominated by” and big-OI The precise definitions of:

I “Dominated by” and big-OI “Dominates” and big-ΩI Big-Θ

I How to demonstrate that one function is dominated byanother by finding c and n0 and applying the correct definition

22

Page 58: CSE 373: Asymptotic Analysis · 2018-03-11 · Lasttime Twostepprocess: 1.Modelwhatwecareaboutasamathematicalfunction 2.Analyzethatfunctionusingasymptoticanalysis Specifically:haveawaytocomparetwofunctions

Takeaways

Important things to know:

I Intuition behind the definitions of “dominated by” and big-OI The precise definitions of:

I “Dominated by” and big-OI “Dominates” and big-ΩI Big-Θ

I How to demonstrate that one function is dominated byanother by finding c and n0 and applying the correct definition

22