You are on page 1of 6

300699 Discrete Structures and Complexity, Spring 2011Answers to Tutorial Week 3 Questions

1. Let X = {1, 2, 3, . . . , 10}, let A = {x X| x is even}, and let B = {x X|x < 6}. Calculuate the following sets, listing all their elements. (a) A Answers: (a) {2, 4, 6, 8, 10} (b) {1, 2, 3, 4, 5} (c) {1, 2, 3, 4, 5, 6, 8, 10} (d) {2, 4} (e) {6, 8, 10} (b) B (c) A B (d) A B (e) A \ B

2. Let A = {0, 1, 2, 3}, let B = {0, 2, 4, 6}, and let C = {1, 1}. What are (A B) C and A (B C)? Why is it OK to write A B C without brackets, but not OK to write A B C? Answers: (A B) C = {1} and A (B C) = A = {0, 1, 2, 3}. While AB C appears ambiguous because it could mean A(B C) or (AB)C, these are in fact equal because the operation is associative. On the other hand, mixing operations requires care (just as with + and ), and as can be seen from the example, it is usually not the case that (A B) C = A (B C). 3. List all the subsets of {a, b, c}. (Hint: there are 8). Answers: The empty set is a subset of every set, so we must include it in our list of all subsets: , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} [We call the set of all subsets the power set. So the power set of {a, b, c} is P({a, b, c}) = {, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}. If a set X has n elements, then its power set will have 2n elements.] 4. In computing, it is common to need to deal with sets that have other sets as elements. Let A = {a, {b, c}, d} and B = {b, c, d}. Calculuate the following sets, listing all their elements. (a) A B Answers: (a) {a, b, c, {b, c}, d} (b) {d} (c) {a, {b, c}} (d) {b, c}. (b) A B (c) A \ B (d) B \ A

5. Consider the set X = {0, 1, 2, 3}. (a) List all the subsets of X which are disjoint from {0, 1}. (b) List all the subsets of X which contain {0, 1}. (c) How many subsets did you nd in the previous two parts? What do you notice? Can you explain why this might be? Answers: (a) , {2}, {3}, {2, 3}. (b) {0, 1}, {0, 1, 2}, {0, 1, 3}, {0, 1, 2, 3}. (c) In each case there are 4. In each case we are counting possibilities excluding 0 and 1 (in the rst case because they are not there, in the second because they are already there). There is a natural bijection between these sets of sets. 6. For each positive integer n, let An = {x R | 0 x
1 n }.

What are

(a) A1 (b) A2 Answers: (a) [0, 1] (b) [0,


1 2]

(c) A1 A2 (d) A1 A2

(e) (f)

10 k=1 10 k=1

Ak Ak

(g) (h)

10 k=5 10 k=5

Ak Ak

(c) A1 (d) A2

(e) A1 (f) A10

(g) A5 (h) A10

7. Which of the following arrow diagrams represent functions? If not, why not? (a) 1 2 3 x y z t (b) 1 2 3 x y z t (c) 1 2 3 x y z t

(d)

1 2 3

x y z

(e)

1 2 3

x y z

(f)

1 2 3

x y

Only (a) and (e) do not represent functions. In (a) there is an element of the domain mapped to two dierent elements of the codomain. The diagram (e) doesnt represent a function because there is an element in the domain that is not mapped to any element of the codomain. 8. In the previous question, (a) which of the functions are (i) one-to-one (injective)? (ii) onto (surjective)? (iii) bijective? (b) For each function describe the domain, the codomain, and the image. (c) Given any function F : X Y , and b Y , the preimage of b, denoted F 1 (b), is the set F 1 (b) := {a X | F (a) = b}. That is, the set of elements of the domain that are mapped to b under F . For each of the functions in Question 7, nd F 1 (y). (d) Can you rephrase the denition of onto (that the image of the function equals the codomain) using the notion of preimage? Answers: (a) (b) i. (c) and (d) ii. (d) iii. (d)

(b) Domain = {1, 2, 3}, Codomain= {x, y, z, t}, Image= {y, t} (c) Domain = {1, 2, 3}, Codomain= {x, y, z, t}, Image= {x, y, z} (d) Domain = {1, 2, 3}, Codomain= {x, y, z}, Image= {x, y, z} (f) Domain = {1, 2, 3}, Codomain= {x, y}, Image= {x}

(c) {1, 2} {1} {3}

(b)

(c)

(d)

(f)

(d) A function is onto if the preimage of every element in the codomain is non-empty. 9. Find all functions from X to Y where (a) (b) (c) (d) X X X X = {a, b, c} and Y = {0}; = {a} and Y = {1, 2, 3}; = {a, b} and Y = {1, 2}; = {a, b, c} and Y = {1, 2};

Answers: (a) (b) (c) (d) f (a) = f (b) = f (c) = 0 f (a) = 1 OR f (a) = 2 OR f (a) = 3 f (a) = 1, f (b) = 2 OR f (a) = 2, f (b) = 1 OR f (a) = f (b) = 1 OR f (a) = f (b) = 2 f (a) = f (b) = 1, f (c) = 2 OR f (a) = f (b) = 2, f (c) = 1 OR f (a) = f (c) = 1, f (b) = 2 OR f (a) = f (c) = 2, f (b) = 1 OR f (b) = f (c) = 1, f (a) = 2 OR f (b) = f (c) = 2, f (a) = 1 OR f (a) = f (b) = f (c) = 1 OR f (a) = f (b) = f (c) = 2.

10. Which of the following are functions? If not, why not? (a) X is the set of students in our DSC class. For x X, dene g(x) to be the youngest cousin of x. (b) X is the set of members of parliament (MPs) in 2011. For x X, dened g(x) to the number of terms an MP has served. (c) Let f : N N be dened by f (n) = n + 1. Is f one-to-one? Is it onto? (Recall, N is the set of natural numbers N = {0, 1, 2, . . . }.) Answers: (a) Not a function since some students may not have any cousins, so not all of the domain (DSC students) would be mapped to the codomain (cousins.) (b) This is a function since every MP has served for some period of time (its codomain might be rational numbers, since some MPs might serve fractional terms). (c) The function f is one-to-one but not onto, since the element 0 in the codomain does not have an element mapped to it. 11. Each of the following sets of pairs may or may not represent a function from {1, 2, 3} to {a, b, c, d}: {(1, d), (2, b), (3, d)} {(1, c), (2, a), (3, b)} {(1, a), (3, b)} {(1, a), (1, c), (3, d)} {(2, b), (3, c), (1, d)}. (a) Which sets represent functions? Why/why not? Answer: Only the third and fourth sets do not represent functions. The third set does not include the entire domain and the fourth set has the element 1 mapped to two elements of the codomain. (b) Which sets represent one-to-one functions? Why/why not? Answer: Only the second and fth sets represent one-to-one functions since each element of the codomain has only one element of the domain mapped to it. (c) None of them could possibly be onto. Why? Answer: The codomain has more elements that the domain, so it is impossible to nd a function that maps each element of the domain to every element of the codomain. 12. A function F : X X Y is called a binary function from X 2 to Y . For example, the addition function Add : R R R dened by Add(a, b) := a + b, is a binary function. Can you represent other familiar operations on numbers (subtraction, multiplication, division) as binary functions? If so, identify the domains and codomains in each case. Answer: We can represent subtraction and multiplication in the same way as addition. However, division by 0 is not dened, so div(a, b) = a b is a function div : R R \ {0} R. 3

13. In computer programming, it is common for a desired function to only work on part of the natural domain perhaps it loops on some elements of the domain, or perhaps it is simply not dened for all elements of the domain. In this case, it is not a function. To deal with such functions, we use the concept of partial function. A partial function F with domain of denition X and codomain Y is a subset of X Y such that for each x X there is at most one y Y such that (x, y) F . (Saying at most one means each element of the domain is mapped to either 0 or 1 element of the codomain. Genuine functions require each element of the domain to be mapped to exactly one element of the codomain). Equivalently, a partial function F : X Y is a function from X to Y for some subset X X. (Note, functions are also partial functions, because X X). (a) Find all partial functions from {a, b} to {a, b}. (Hint: there are 9) Answer: We write the partial functions using relation notation: OR {(a, a)} OR {(a, b)} OR {(b, a)} OR {(b, b)} OR {(a, a), (b, a)} OR {(a, a), (b, b)} OR {(a, b), (b, a)} OR {(a, b), (b, b)} (b) Find all functions from {a, b} to {a, b}. (Hint: there are 4) Answer: {(a, a), (b, a)} OR {(a, a), (b, b)} OR {(a, b), (b, a)} OR {(a, b), (b, b)} (c) Without listing them all, can you count how many functions there are from {a, b, c} to {a, b, c}? Answer: 3 3 3 = 27 since each element of the domain could be mapped to one of three elements in the codomain. (d) How about partial functions {a, b, c} to {a, b, c}? Answer: 4 4 4 = 64 since we are now including the possibility of being mapped to nothing. (e) Can you generalize these to guess formulas for the number of functions and partial functions from an n-element set to an n-element set? Answer: Number of functions= nn , number of partial functions= (n + 1)n . 14. A recursively dened function is one whose domain is the natural numbers N, and whose value on any n is given in terms of its value on smaller integers. For example, dene f : N N by setting f (0) = 3 and f (n) = 2f (n 1) + 3. Then f (1) = 2f (0) + 3 = 9. (a) Find f (2), f (3), f (4) and f (5). Answer: f (2) = 21, f (3) = 45, f (4) = 93, f (5) = 189. (b) Change the denition of f by setting f (0) = 2. Now repeat the above with the new denition. Why do the values of f (n) all end in 7? Answer: f (2) = 17, f (3) = 37, f (4) = 77, f (5) = 157. Doubling a number that ends in 7 leaves a number that ends in 4; then adding 3 to this leaves a number that ends in 7; so if f (n 1) ends in 7, then so too does f (n) = 2f (n 1) + 3. 15. Find f (1), f (2), f (3), f (4) when f is dened recursively by setting f (0) = 1 and (a) f (n) = f (n 1) + 2. Answer: f (1) = 3, f (2) = 5, f (3) = 7, f (4) = 9. (b) f (n) = 2f (n 1). Answer: f (1) = 2, f (2) = 4, f (3) = 8, f (4) = 16. (c) f (n) = 2f (n1) . Answer: f (1) = 2, f (2) = 4, f (3) = 16, f (4) = 65536. (d) f (n) = f (n 1)2 + f (n 1) + 1. Answer: f (1) = 3, f (2) = 13, f (3) = 183, f (4) = 33673. 16. How would you dene the factorial function F actorial(n) = n! recursively? Answer: F (n) = nF (n 1), for n 1 where F (0) = 1. 17. (a) Dene g recursively by setting g(0) = 1 and g(n) = 2g(n 2) + 4. What is wrong with this denition? (Hint: try to calculate values of g(n)). Answer: We cannot work out g(1) without knowing g(1), which is not dened.

(b) Dene h recursively by setting h(0) = 17 and h(n) = 3h(n 1) 2h(n 2). What is wrong with this denition? Answer: We cannot work out h(1) without knowing h(1) which is not dened. (c) Is there a general principle about dening recursively-dened functions that can be drawn from this? Answer: We must always dene an appropriate number of initial values from which all higher values can be calculated. 18. Find a recursive denition for the function f (n) = an for some xed integer a. Answer: f (n) = af (n 1) n 1 where f (0) = 1. 19. The Fibonacci numbers are dened recursively by setting F (0) = F (1) = 1 and F (n) = F (n1)+F (n2). Calculate F (6). Answer: F (6) = 13. 20. Recall the function n : Z {0, 1, 2, . . . , n 1} dened by setting n (a) to be the remainder left after a is divided by n. Dene a relation Rn by setting (x, y) Rn if n (x) = n (y). (a) Show that Rn is an equivalence relation. (Recall, this means it is reexive, symmetric and transitive). Answer: Obviously n (x) = n (x) and so (x, x) Rn for any x Z. This means that Rn is reexive. Next note that (x, y) Rn = n (x) = n (y) = n (y) = n (x) = (y, x) Rn , so that Rn is symmetric. Finally, (x, y) Rn and (y, z) Rn together imply that n (x) = n (y) and n (y) = n (z), from which it follows that n (x) = n (z), i.e. (x, z) Rn . Thus Rn is transitive. Since we have shown that Rn is reexive, symmetric and transitive, we have in fact shown that Rn is an equivalence relation. [This is a special case of a more general phenomenon. For any function f : X Y we may dene a relation R on X by (x, y) R if and only if f (x) = f (y). In the same way as above, we may show that R is an equivalence relation. This relation is sometimes called the kernel of f .] (b) If (a, b) Rn we will say a and b are congruent modulo n. This is often written a b (mod n). Show that a b (mod n) if and only if n divides a b. (You need to show two directions here). Answer: First suppose a b (mod n). Let r = n (a). Then n (b) = r also, since (a, b) Rn . So a = pn + r and b = qn + r for some p, q Z. Thus a b = (pn + r) (qn + r) = (p q)n, so that n divides a b. Conversely, suppose n divides a b, so a b = kn for some k Z. Put r = n (a) and s = n (b), so a = pn + r and b = qn + s for some p, q Z. We will show that r = s. Now, we must have either r s or s r. Well consider only the case r s (you should check the other case yourself). Note that r s implies r s 0. Now kn = a b = (pn + r) (qn + s) = (p q)n + (r s). Rearranging kn = (p q)n + (r s) gives r s = (k p + q)n, so that r s is divisible by n. But 0 r s r n 1, so it follows that r s = 0, i.e. r = s, i.e. n (a) = n (b), i.e. (a, b) Rn , i.e. a b (mod n). (c) Determine whether 17 5 (mod 6) and whether 24 14 (mod 6). Answer: Since 17 5 = 12 is divisible by 6, it follows that 17 5 (mod 6). Since 24 14 = 10 is not divisible by 6, it follows that 24 14 (mod 6). (d) The set of elements that are related by an equivalence relation is called an equivalence class. In this case, the equivalence classes are often called congruence classes. Find the elements of the congruence classes when n = 4. (Note: these are innite sets, so you will not be able to list all elements!). Answer: There are 4 congruence classes; the class of elements congruent to 0 modulo 4, 1 modulo 4, 2 modulo 4 and 3 modulo 4: [0] = {. . . , 8, 4, 0, 4, 8, 12, . . .} [1] = {. . . 7, 3, 1, 5, 9, 13, . . .} [2] = {. . . , 6, 2, 2, 6, 10, 14, . . .} [3] = {. . . , 5, 1, 3, 7, 11, 15, . . .}

21. Functions from R R are often able to be graphed on a pair of axes. For example: f (x)

x f (x) = sin x One can check whether such a graph represents a function using a vertical line test : if any vertical passes through the graph exactly one, then it represents a function. (a) Is the function shown, f (x) = sin x, one-to-one or onto? Answer: This function is neither one-to-one nor onto. There are elements of the codomain that have more than one element of the domain mapped to them, and not every element of the codomain is covered (only values of y from 1 to 1 are covered.) (b) Can you describe features of the graph that show you whether a function like this is one-to-one or onto? Answer: If a function is one-to-one then every horizontal line should intersect the function once at most. If a function is onto then every horizontal line should intersect the function at least once.

You might also like