Você está na página 1de 7

EECS 203 W14 HW # 6 ALEX LAU February 26 2014 Lecture Section: 001 COMPTON Discussion Section: 016 WELCH

Section 3.2 12. Show that x log x is O(x2) but that x2 is not O(x log x) Proof from definition, for all x > 0 log(x) < x. Hence x log x < x2 for all x > 0. Since the rate of growth for polynomial functions > logarithmic functions If x2 is O(x log x) For C > 0 and k for any x > k Therefore So This is a contradiction as the term on the LHS goes to infinity as x goes to infinity. Thus x is not O(x log x)

20. Determine whether each of the functions log(n + 1) and log(n2 + 1) is O(log n). log(n + 1) is O(log n) for k = 2 and C = 2 log(n2 + 1) is not O(log n).

22. Arrange the function (1.5)n, n100, (log n)3, log n, 10n, (n!)2, and n99 + n98 in a list so that each function is big-O of the next function. (log n)3, log n, n99 + n98,n100, (1.5)n, 10n, (n!)2

24. Suppose that you have two different algorithms for solving a problem. To solve a problem of size n, the first algorithm uses exactly n22n operations and the second algorithm uses exactly n! operations. As n grows, which algorithm uses fewer operations? n22n uses fewer operations. For n = 1, 1! = 1, 12*21 = 2 But for n = 50, 50! = 3.04 X 1064, 502*250 = 2.8118

This is because growth rate of Factorials > exponential > power functions.

44. Suppose that f (x), g(x), and h(x) are functions such that f(x) is (g(x)) and g(x) is (h(x)). Show that f (x) is (h(x)). ( ) ( ( )) and ( ) ( ( )).

Since ( ) | ( )|

( ( )), there exists C1 > 0 and C2 > 0 such that | ( )| | ( )|, for any x > ( ( )), there exists C3 > 0 and C4 > 0 such that | ( )|, for any x > and | ( )| | ( )| | ( )| | ( )| , since is always positive is always positive

Similarly, since ( ) | ( )| | ( )|

Let k be the larger of | ( )|

| ( )| implies that

Similarly | ( )| Therefore Hence And ( )

| ( )| implies that | ( )|

| ( )| , since

| ( )| | ( )|

| ( )| | ( )|

| ( )| for all x > k

| ( )|

( ( )) (shown)

Section 3.3 2. Give a big-O estimate for the number additions used in this segment of an algorithm. t := 0 for i := 1 to n for j := 1 to n t := t + i + j The two loops both run n times, thus the total number of times is n 2 Thus the complexity is O(n2)

4. Give a big-O estimate for the number of operations, where an operation is an addition or a multiplication, used in this segment of an algorithm (ignoring comparisons used to test the conditions in the while loop). i := 1 t := 0 while i <= n t := t + i i := 2i The number of operations is O(n) Section 5.1 10a. Find a formula for 1 by examining the values of this expression for small values of n. ( = + + ... + =1= b. Let P(n) be the proposition that: ( Base step: n = 1 P(1): = , LHS = RHS Hence P(1) is true. Assume that P(k) is true Then ( ) ) )

We want to show that P(k+1) is also true P(k+1): ( LHS = ( = =( =( =( =(


( ( )( ) ) ) )( ) ) ( )( )

)(

)(

)(

= RHS (shown) Therefore P(k+1) is true Since P(1) is true, P(k) is true -> P(k+1) is also true, using the principle of mathematical induction, the formula is true.

12. Let P(n) be the statement

for all non negative integer n.

We want to prove that P(0) is true. LHS = ( RHS =


(

)
)

Since LHS = RHS, P(0) is true Assume that P(k) is true i.e assume that ( )
( )

is true

Now we want to show that P(k+1) is also true i.e we want to show that LHS = = =
( ( )

is true

+(
( )

+
)

= RHS (shown)

Since P(0) is true, P(k) is true -> P(k+1) also true, the equation is valid for all non negative integer n.

20. Prove that 3n<n! if n is an integer greater than 6. Let P(n) be the proposition that 3n<n! for any integer greater 6. We want to prove that the base case P(7) is true 37 < 7! 2187 < 5040, thus P(7) is true.

Assume that P(k) is true for all k > 6 i.e 3k < k! We want to prove that P(k+1) is true i.e. We want to prove that 3k+1 < (k+1)! LHS = 3k+1 = 3(3k) < 3 k! (according to assumption of P(k)) < (k+1)k! (since k > 6. k+1 is always > 3) < (k+1)! Thus P(k+1) is also true. Since P(7) is true, P(k) is true -> P(k+1) is also true, the inequality is true for all n > 6.

38. Basis step P(1): is true because is true, is also true

Assume that

Now we want to show that Let So Thus ( ( ) ) , since

(assumption)

Since it is given that Therefore Thus ( ( ) )

and

Hence we can conclude that

(shown)

Você também pode gostar