You are on page 1of 1

216

3/ Algorithms

One useful fact is that the leading term of a polynomial detennines its order. For example, if f(x) = 3x 5 + x4 + 17x 3 + 2, then f(x) is of order x 5 . This is stated in Theorem 4, whose proof is left as Exercise 50.

THEORE M 4

Let f(x) = anx n + an_lX n- 1 + ... an :f. O. Then f (x) is of order xn.

+ alX + aO, whereao, ai,

... , an are real numbers with

EXAMPLE 13

The polynomials 3x 8 + lOx 7 + 221x2 + 1444, x 19 - 18x 4 - 10,112, and _x 99 + 100,003x are of orders x 8 , x 19 , and x 99 , respectively.

+ 40,001x 98

Unfortunately, as Knuth observed, big-O notation is often used by careless writers and speakers as if it had the same meaning as big-Theta notation. Keep this in mind when you see big-O notation used. The recent trend has been to use big-Theta notation whenever both upper and lower bounds on the size of a function are n~yded.

Exercises
In Exercises 1-14, to establish a big- 0 relationship, find witnesses C and k such that !f(x)! :::: C\g(x)! whenever x> k. 1. Determine whether each of these functions is 0 (x).
c) f(x)=x 2 +x+l

12. Show that x log x is 0 (x 2 ) but that x 2 is not 0 (x log x). 13. Show that 2 n is 0 (3") but that 3" is not 0 (2"). (Note that
this is a special case of Exercise 60.)

a) f(x) = 10

b) f(x) = 3x

+7

d) f(x)=510gx

2.

3.

4. 5.

f(x) = LxJ f) f(x) = rx/21 Determine whether each of these functions is 0 (x 2 ). a) f(x) = 17x + 11 b) f(x) = x 2 + 1000 c) f(x)=xlogx d) f(x)=x 4/2 e) f(x) = 2 x f) f(x) = LxJ . rxl Use the definition of "f(x) is O(g(x)" to show that x4 + 9x 3 + 4x + 7 is 0(x 4). Use the definition of "f(x) is O(g(x))" to show that 2X + 17 is O(3X). Show that (x 2 + 1)/(x + 1) is O(x).

e)

14. Determine whether x 3 is 0 (g (x for each of these functions g(x) . b) g(x) =x 3 a) g(x) = x 2 d) g(x) = x 2 + x4 c) g(x) = x 2 +x 3 e) g(x)=3 x f) g(x) = x 3 /2
15. Explain what it means for a function to be 0(1).

16. Show that if f(x) is O(x), then f(x) is 0(x 2 ).


17. Suppose that f(x), g (x), and hex) are functions such that f(x) is O(g(x and g(x) is O(h(x). Show that f(x) is O(h(x). 18. Let k be a positive integer. Show that I k + 2k + . .. + n k is 0 (n k+ 1). 19. Determine whether each of the functions 2,,+1 and 2211 is 0(2"). 20. Determine whether each of the functions log(n + I) and log(n2 + 1) is o (log n). 21. Arrange thefunctions.Jn, 1000 log n, n log n, 2nl, 2",3", and n 2 / 1, 000, 000 in a list so that each function is big- 0 of the next function. 22. Arrange thefunction (1.5)", n100, (log n)3, .Jnlog n, 10", (n 1)2, and n 99 + n 98 in a list so that each function is big- 0 of the next function. 23. Suppose that you have two different algorithms for solving a problem. To solve a problem of size 11, the first algorithm uses exactly n (log n) operations and the second algorithm uses exactly n 3/ 2 operations. As n grows, which algorithm uses fewer operations? 24. Suppose that you have two different algorithms for solving a problem. To solve a problem of size n, the first algorithm uses exactly /122 n operations and the second algorithm uses exactly n! operations. As n grows, which algorithm uses fewer operations?

6. Show that (x 3 + 2x)/(2x + 1) is 0(x2).


7. Find the least integer n such that f (x) is 0 (x") for each of these functions. a) f(x)=2x 3 +x 2 10gx b) f(x) = 3x 3 + (logx)4 c) f(x) = (x 4 + x 2 + 1)/(x 3 + 1) d) f(x) = (x 4 + 510gx)/(x 4 + 1) 8. Find the least integer n such that f(x) is O(x n ) for each of these functions . a) f(x) = 2x2 + x 3 10gx b) f(x) = 3x 5 + (logx)4 c) f(x) = (x 4 + x 2 + 1)/(x 4 + I) d) f(x) =(x 3 +510gx)/(x 4 +1) 9. Show that x 2 + 4x + 17 is 0(x 3 ) but that x 3 is not 0(x 2 + 4x + 17). 10. Show that x 3 is 0 (X4) but that x4 is not 0 (x 3 ). 11. Show that 3x 4 + I is 0(x 4/2) and x 4 /2 is 0(3x 4 + 1).

You might also like