cs 23022 discrete mathematical structures

36
CS 23022 Discrete Mathematical Structures Mehdi Ghayoumi MSB rm 132 [email protected] Ofc hr: Thur, 9:30-11:30a

Upload: julian-rowe

Post on 02-Jan-2016

38 views

Category:

Documents


1 download

DESCRIPTION

CS 23022 Discrete Mathematical Structures. Mehdi Ghayoumi MSB rm 132 [email protected] Ofc hr: Thur, 9:30-11:30a. Announcements. Homework 4 available. Due Mon 06/23 , 8a. Midterm : Next Mon 06/30/14, location 121 . Chapter 2.3 in Rosen and some other articles And Chapter 3 in Rosen. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 23022 Discrete Mathematical Structures

CS 23022Discrete Mathematical Structures

Mehdi Ghayoumi

MSB rm 132

[email protected]

Ofc hr: Thur, 9:30-11:30a

Page 2: CS 23022 Discrete Mathematical Structures

Announcements

Homework 4 available. Due Mon 06/23, 8a.

Midterm : Next Mon 06/30/14, location 121.

Chapter 2.3 in Rosen and some other articles

And

Chapter 3 in Rosen

Page 3: CS 23022 Discrete Mathematical Structures

Familiar functionsPolynomials:

f(x) = a0xn + a1xn-1 + … + an-1x1 + anx0

constants (like 3, -20, or ½) variables (like x and y)

exponents (like the 2 in y2), but only 0, 1, 2, 3, ... etc. are allowed

A polynomial can have:

A polynomial can have constants, variables and exponents, but never division by a variable.

Page 4: CS 23022 Discrete Mathematical Structures

Familiar functions

Degree

Standard Form

Page 5: CS 23022 Discrete Mathematical Structures

Familiar functionsExponentials:

The exponential function with base b is defined by:                                                  

Page 6: CS 23022 Discrete Mathematical Structures

Familiar functionsNatural Exponential Function:

This function is simply a "version" of

where b >1.

Page 7: CS 23022 Discrete Mathematical Structures

Familiar functions

Inverse of f (x) = ex:

• set the equation equal to y• swap the x and y • solve for y by rewriting in log form• log base e is called the natural log, ln

Since  f (x) = ex is a one-to-one function, we know that its inverse will also be a function. 

But what is the equation of the inverse of f (x) = ex ?

To solve for an inverse algebraically:

Page 8: CS 23022 Discrete Mathematical Structures

Familiar functionsOther Exponential Inverses:

Y=2x or y= 0.5x

Page 9: CS 23022 Discrete Mathematical Structures

Familiar functionsLogarithms:

log2 x = y, where 2y = x.

In this course, log2 n is written lg n. If we write

log n, assume log2 n.

f(x) = loga(x)

a is any value greater than 0, except 1

Example: f(x) = log½(x) Example: f(x) = log2(x)

Page 10: CS 23022 Discrete Mathematical Structures

Familiar functions

loga(x) is the Inverse Function of ax (the Exponential Function)

Inverse

The Natural Logarithm Function

This is the "Natural" Logarithm Function:f(x) = loge(x)

Where e is "Eulers Number" = 2.718281828459 (and more ...)

Page 11: CS 23022 Discrete Mathematical Structures

Familiar functions

Ceiling:

f(x) = x the least integer y so that x y.

Ex: 1.2 = 2; -1.2 = -1; 1 = 1

Page 12: CS 23022 Discrete Mathematical Structures

Familiar functions

Floor:

f(x) = x the greatest integer y so that x y.

Ex: 1.8 = 1; -1.8 = -2; -5 = -5

Page 13: CS 23022 Discrete Mathematical Structures

Familiar functionsLinear Function

f(x) = mx + b

Square Function Cube Function

f(x) = x2 f(x) = x3

Page 16: CS 23022 Discrete Mathematical Structures

Familiar functionsDance Moves

Page 17: CS 23022 Discrete Mathematical Structures

Function typesDescribe these functions:

f(x)

x

Every unit increase in x results in the

same increase in f(x).

Linear functions

Page 18: CS 23022 Discrete Mathematical Structures

Function typesDescribe this function:

Very slow growing.

Logarithmic function

Page 19: CS 23022 Discrete Mathematical Structures

Function typesDescribe this function:

Very fast growing.

Exponential function

Page 20: CS 23022 Discrete Mathematical Structures

Function typesDescribe this function:

f(x)

x

Polynomial

Page 21: CS 23022 Discrete Mathematical Structures

Two example algorithms

Suppose we wish to find the maximum

number in a sequence of n numbers.

How long should we spend doing this?

We say the algorithm has

“order n” running time.

In this case our algorithm takes about n

time units.Suppose it takes 1 time unit to make a

comparison between two numbers.

Page 22: CS 23022 Discrete Mathematical Structures

Two example algorithmsI have a number between 0 and 63.

You ask a question, I’ll tell you yes or no.

How long will it take you to find my secret number?

Suppose it takes 1 time unit to answer a

query about my number.

In this case the algorithm takes about lg

n time units.

We say the algorithm has “order log n” running time.

Page 23: CS 23022 Discrete Mathematical Structures

Who wins the race?The following graph gives times for completing races

of length x, for 4 different competitors.

Who is the tortoise?

time

distance

Who is the hare?

How would you describe blue’s performance?

At each distance, who

wins?

Page 24: CS 23022 Discrete Mathematical Structures

Growth of functionsAlgorithm analysis is concerned with:

•Type of function that describes run time

(we ignore constant factors since different

machines have different speed/cycle)

•Large values of x

Page 25: CS 23022 Discrete Mathematical Structures

Growth of functionsImportant definition:

For functions f and g we write

f(x) = O(g(x))

to denote

c,k so that x>k, f(x) c·g(x)

We say “f(x) is big O of g(x)”

Recipe for proving f(x) = O(g(x)): find a c and k so that the

inequality holds.

Page 26: CS 23022 Discrete Mathematical Structures

Growth of functionsf(x) = O(g(x)) iff

c,k so that x>k, f(x) c·g(x)

x

f(x)

g(x)c·g(x)

k

We give an eventual upper bound on f(x)

Page 27: CS 23022 Discrete Mathematical Structures

Growth of functions (examples)f(x) = O(g(x))

Iff

c,k so that x>k, f(x) c·g(x)

3n = O(15n) since n>0, 3n 1·15n

There’s k There’s c

Page 28: CS 23022 Discrete Mathematical Structures

Growth of functions (examples)f(x) = O(g(x))

iff

c,k so that x>k, f(x) c·g(x)

15n = O(3n) since n>__, 15n __·3n 5 80 5

Page 29: CS 23022 Discrete Mathematical Structures

Growth of functions (examples)f(x) = O(g(x))

iff

c,k so that x>k, f(x) c·g(x)

x2 = O(x3) since x> __, x2 x3 1

Page 30: CS 23022 Discrete Mathematical Structures

Growth of functions (examples)f(x) = O(g(x))

iff

c,k so that x>k, f(x) c·g(x)

1000x2 = O(x2) since x> __, 1000x2 ____·x2 0 1000

Page 31: CS 23022 Discrete Mathematical Structures

Growth of functions (examples)

f(x) = O(x4).

Page 32: CS 23022 Discrete Mathematical Structures

Growth of functions (examples)

Prove that 5x + 100 = O(x/2)

Nothing works for k

Need x> ___, 5x + 100 ___ · x/2

Try c = 10 x> ___, 5x + 100 10 · x/2

k = 200, c = 11

Try c = 11

x> ___, 5x + 100 5x + x/2

x> ___, 100 x/2 200

Page 33: CS 23022 Discrete Mathematical Structures

Growth of functionsGuidelines:

In general, only the largest term in a sum matters.

a0xn + a1xn-1 + … + an-1x1 + anx0 = O(xn)

n5lg n = O(n6)

List of common functions in increasing O() order:

1 (lg n ) n (n lg n) n2 … 2n n!

Page 34: CS 23022 Discrete Mathematical Structures

Growth of functions (more examples)

Then

log n!log nn n log n,

log n!O(n log n)

nnnnnnnnnn 123)1(!

n!O(nn )

So

Page 35: CS 23022 Discrete Mathematical Structures

Growth of functions - a corollaryIf f1(x) = O(g1(x)) and f2(x)=O(g2(x)), then

f1(x) + f2(x) = O(max{g1(x),g2(x)})

This is just the case where g1(x) = g2(x) = g(x)

If f1(x) = O(g(x)) and f2(x)=O(g(x)), then

f1(x) + f2(x) = O(g(x)).

Page 36: CS 23022 Discrete Mathematical Structures