section 9.1 real-valued functions of a real variable and their graphs

40
Section 9.1 Real-Valued Functions of a Real Variable and Their Graphs

Post on 21-Dec-2015

222 views

Category:

Documents


3 download

TRANSCRIPT

Section 9.1

Real-Valued Functions of a Real Variable and Their Graphs

Let f be a real valued function of a real variable. The graph of f is the set of all points (x,y) in the Cartesian coordinate plane with the property that x is in the domain of f and y = f(x)

For application in computer science, we are almost invariably concerned with situations where x and a are nonnegative.

The Linear Function f(x) = x

2 4 6 8 10

2

4

6

8

10

The Quadratic Function f(x) = x2

2 4 6 8 10

20

40

60

80

100

The Cubic Function f(x) = x3

2 4 6 8 10

100

200

300

400

500

600

Power Functions xa, a 1

• The higher the power of x, the faster the function grows.– xa grows faster than xb if a > b.

The Square-Root Function

2 4 6 8 10

0.5

1

1.5

2

2.5

3

The Cube-Root Function

2 4 6 8 10

0.5

1

1.5

2

The Fourth-Root Function

2 4 6 8 10

0.25

0.5

0.75

1

1.25

1.5

1.75

Power Functions xa, 0 < a < 1

• The lower the power of x, the more slowly the function grows.– xa grows more slowly than xb if a < b.

• This is the same rule as before, stated in the contrapositive.

0.5 1 1.5 2

1

2

3

4

Power Functions

x3x2

x

x

Multiples of Functions

1 2 3 4

2.5

5

7.5

10

12.5

15 x2

x

2x

3x

Multiples of Functions

• Notice that x2 eventually exceeds any constant multiple of x.

• Generally, if f(x) grows faster than g(x), then f(x) also grows faster than cg(x), for any real number c.

• In other words, we think of g(x) and cg(x) as growing at the “same rate.”

• If the growth rate of one function is a constant time the growth rate of another then they’re said to’ve the same growth rate

The Logarithmic Function f(x) = log2 x

10 20 30 40 50 60

-2

2

4

6

Growth of the Logarithmic Function

• The logarithmic functions grow more and more slowly as x gets larger and larger.

f(x) = log2 x vs. g(x) = x1/n

5 10 15 20 25 30

-2

2

4 log2 x

x1/2

x1/3

Logarithmic Functions vs. Power Functions

• The logarithmic functions grow more slowly than any power function xa, 0 < a < 1.

f(x) = x vs. g(x) = x log2 x

0.5 1 1.5 2 2.5 3

1

2

3

4

x

x log2 x

f(x) vs. f(x) log2 x

• The growth rate of log x is between the growth rates of 1 and x.

• Therefore, the growth rate of f(x) log x is between the growth rates of f(x) and x f(x).

2 4 6 8

10

20

30

40

50

f(x) vs. f(x) log2 x

x2x2 log2 x

x log2 x

x

The Exponential Function f(x) = 2x

1 2 3 4

2.5

5

7.5

10

12.5

15

Growth of the Exponential Function

• The exponential functions grow faster and faster as x gets larger and larger.

• Every exponential function grows faster than every power function.

f(x) = 2x vs. Power Functions (Small Values of x)

0.5 1 1.5 2

1

2

3

4

5

2x

f(x) = 2x vs. Power Functions (Large Values of x)

5 10 15 20

500

1000

1500

2000

2500

3000

3500

2x

x3

Section 9.2

O-Notation

“Big-Oh” Notation: O(f)

• Let g : R R be a function.

• A function f : R R is “of order g,” written “f(x) is O(g(x)),” if there exist constants M, x0 R such that

f(x) Mg(x)for all x x0.

Growth Rates

• If f(x) is O(g(x)), then the growth rate of f is no greater than the growth rate of g.

• If f(x) is O(g(x)) and g(x) is O(f(x)), then f and g have the same growth rate.

Common Growth Rates

Growth Rate Example

O(1) Access an array element

O(log2 x) Binary search

O(x) Sequential search

O(x log2 x) Quick sort

O(x2) Bubble sort

O(2x) Factor an integer

O(x!) Traveling salesman problem

Estimating Run Times

• Suppose a program has growth rate O(f), for a specific function f(x).

• Then the run time is of the formt = cf(x)

for some real number c.• Suppose the program runs in t0 seconds when

the input size is x0. Then

c = t0/f(x0).

Estimating Run Times

• Thus, the run time is given by

t = (t0/f(x0)) f(x)

= t0 (f(x)/f(x0)).

Comparison of Growth Rates

• Consider programs with growth rates of O(1), O(log x), O(x), O(x log x), and O(x2).

• Assume that each program runs in 1 second when the input size is 100.

• Calculate the run times for input sizes 102, 103, 104, 105, 106, and 107.

Comparison of Growth Rates

x O(1) O(log x) O(x) O(x log x) O(x2)

102 1 sec 1 sec 1 sec 1 sec 1 sec

103 1 sec 1.5 sec 10 sec 15 sec 17 min

104 1 sec 2 sec 1.7 min 3.3 min 2.8 hrs

105 1 sec 2.5 sec 17 min 42 min 11 days

106 1 sec 3 sec 2.8 hrs 8.3 hrs 3.2 yrs

107 1 sec 3.5 sec 1.2 days 4.1 days 320 yrs

Comparison with O(2n)

• Now consider a program with growth rate O(2x).

• Assume that the program runs in 1 second when the input size is 100.

• Calculate the run times for input sizes 100, 110, 120, 130, 140, and 150.

Comparison with O(2n)

x O(x2) O(2x)

100 1 sec 1 sec

110 1.2 sec 17 min

120 1.4 sec 12 days

130 1.7 sec 34 yrs

140 2.0 sec 35,000 yrs

150 2.3 sec 36,000,000 yrs

Comparison with O(n!)

• Now consider a program with growth rate O(x!).

• Assume that the program runs in 1 second when the input size is 100.

• Calculate the run times for input sizes 100, 101, 102, 103, 104, and 105.

Comparison with (n!)

x O(2x) O(x!)

100 1 sec 1 sec

101 2 sec 1.7 min

102 4 sec 2.9 hrs

103 8 sec 12 days

104 16 sec 3.5 yrs

105 32 sec 367 yrs

Comparing Orders

• Let f and g be two functions.

• Define O(f) O(g) to mean that f is O(g).

• Define O(f) = O(g) to mean that f is O(g) and g is O(f).

• Define O(f) < O(g) to mean that f is O(g), but g is not O(f).

Comparing Orders

• Theorem:– O(xa) < O(xb) if 0 < a < b.

– O(loga x) = O(logb x) for all a, b > 1.

– O(1) < O(log x) < O(xa) for all a > 0.– O(ax) < O(bx) if 1 < a < b.– O(xa) < O(bx) for all a > 0, b > 1.– O(ax) < O(x!) for all a > 1.

Comparing Orders

• Theorem: For all functions f(x), g(x), and h(x), if

O(f) < O(g),

then

O(f h) < O(g h).

Feasible vs. Infeasible

• Algorithms with polynomial growth rates or less are considered feasible.

• Algorithms with growth rates greater than polynomial are considered infeasible.

• Of course, all algorithms are feasible for small input sizes.– It is feasible to factor small integers (< 50 digits).

– It is infeasible to factor large integers (> 200 digits).