Discrete Math Quiz

Only available on StudyMode
  • Topic: Sorting algorithm, Insertion sort, Big O notation
  • Pages : 8 (1651 words )
  • Download(s) : 290
  • Published : February 18, 2012
Open Document
Text Preview
Quiz 6
1. Determine whether f is a function from R to N if f (x) = x No, negative integers are possible. 2. Determine whether g is a function from R to N if g(x) = x Yes. 3. Give the value of g(−2.2) −2.2 2 2

= −22 = 4

The next two should have been g(x) instead of f (x). 4. Is g(x) one-to-one? No. g(2.2) = g(2.4) 5. Is g(x) onto? Yes.

1

Homework 6
2. Determine whether each of these function is O(x2 ). To do this type of problem, try to alter each function so that it is either in the Cx2 form or is clearly less than a function in Cx2 form while only making it larger. a) f (x) = 17x + 11. Yes. 17x + 11 ≤ 17x + x = 18x ≤ 18x2 when x > 11. Here, C = 18 and k = 11. b) f (x) = x2 + 1000. Yes. x2 + 1000 ≤ x2 + x2 = 2x2 when x2 > 1000 or x > sqrt1000. C = 2, k = √ 1000

c) f (x) = x log x x2 isx ∗ x. x is larger than logx for all x. So, x log x ≤ x ∗ x = x2 C = 1, k = 0

2

d) f (x) = x4 /2 No. x4 is not comparable to x2 . There is no C such that x4 /2 ≤ Cx2 for large x. e) f (x) = 2x No. 2x grows really fast for large x. It is certainly not comparable to x2 .

f) f (x) = x ∗ x Yes.

x ∗ x ≤ 2x2

3

6. Show that (x3 + 2x)/(2x + 1) is O(x2 ) If we can alter this function so that it is in the Cx2 form while only making it larger, we show that it is O(x2 ) a) Remove the 1 from the denominator. Making the denominator of a fraction smaller will make the fraction larger. b) Change the 2x to 2x3 . Now we have (x3 + 2x)/2x c) So divide through by 2x to get f rac32x2 . The witnesses are C = 3/2 and k = 1.

4

8. Find the least integer n such that f (x) is O(xn ) for each of these functions. a) f (x) = 2x2 +x3 log x logx grows at a lesser rate than x, but it still grows without bound. So, this is not O(x3 ). The answer is 4. b) f (x) = 3 x5 +(log x)4 5 c) f (x) = (x4 +x2 + 1)/(x4 +1) The x4 terms are dominant here, as x increases this becomes closer to x4 x4 , or 1. So, the answer is 0. d) f (x) = (x3 + 5logx)/(x4 +1) At large x, this is close to 1/x. This is O(1/x) or O(x− 1).

5

20. Give a big-O estimate for each of these functions. For the function g in your estimate f (x) is O(g), use a simple function g of smallest order. They ask to use a function of smallest order. All these functions are O(1000x ), but that’s a bit much. All you have to do here is take the largest growing term from each sum and get rid of everything else. a) (n3 +n2 log n)(log n +1) + (17log n +19)(n3 +2) O(n3 ∗ log n + log n ∗ n3 ) is the same as O(n3 ∗ log n b) (2n +n2 )(n3 +3n ) O(2n ∗ 3n ) is the same as O(6n ) c) (nn +n2n + 5n )(n!+5n ) O(nn n!)

6

22. For each function, determine whether that function is Ω(x) (is Cx a lower bound?) and whether it is Θ(x) (is it order x?). a) f (x) = 10 Neither. b) f (x) = 3x+7 Both. c) f (x) =x2 +x + 1 Not Θ(x), but it is Ω(x). d) f (x) = 5 log x Since log x grows more slowly than x, it’s neither. e) f (x) = x This is, for all practical purposes, equal to x. Both. f) f (x) = x/2 Same as part (e). Both

7

24. Here, we can just use two constants - one for the lower bound and one for the upper bound.

a) Show that 3x + 7 is Θ(x) x ≤ 3x + 7 ≤ 4x for all x > 7 b) Show that 2x2 + x − 7 is Θ(x2 ) For large x (to ignore all the lower order terms), x2 ≤ 2x2 + x − 7 ≤ 3x2

c) Show that x + 1/2 is Θ(x) For x > 2, 1/2x ≤ x + 1/2 ≤ 2x d) Show that log2 x2 + 1 is Θ(log2 x) Since x < x2 + 1 for all positive x, log2 x ≤ log2 x2 + 1 You need to know the properties of logs here. log2 x2 + 1 ≤ log2 2x2 = log2 2 + 2log2 x = 1 + 2log2 x ≤ 3log2 x e) Show that log10 x is T heta(log2 x) The formula for changing log base: log1 0x = C(log2 x) where C = 1/log2 10. So, just pick a constant that is smaller than 1/log2 10 and one that is larger.

8

6. procedure bit count(S:bit string) count = 0 while S = 0 count = count + 1 S = S ∩ (S − 1) end S − 1 is the string obtained by changing the rightmost 1 of S to a 0 and all 0 bits to the right of that to 1. a) Show that count is the number of 1...
tracking img