Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.

Similar presentations


Presentation on theme: "Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called."— Presentation transcript:

1

2 Recursive Definitions Rosen, 3.4

3 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called recursion. –Sequences {s 0,s 1,s 2, …} defined by s 0 = a and s n = 2s n-1 + b for constants a and b and n  Z+ –Sets 3  S and x+y  S if x  S and y  S –Functions Example: f(n) = 2 n, f(n) = 2f(n-1) and f(0) = 1

4 Recursively Defined Functions To define a function with the set of nonnegative integers as its domain 1.Specify the value of the function at zero (or sometimes, it first k terms). 2.Give a rule for finding its value at an integer from its values at smaller integers.

5 Examples of Recursively Defined Functions Factorial Function n!  n! = n(n-1)(n-2)….(1)  f(0) = 1, f(n) = n(f(n-1)) a n  f(0) = 1, f(n+1) = f(n)*a Fibonacci Numbers  f 0 =0, f 1 =1, f n+1 = f n + f n-1  {0,1,1,2,3,5,8,13,...}

6 Prove that the nth term in the Fibonacci sequence iswhen n  2 Induction Proof: Basic Step: Let n = 2, then f 2 = 1 = =1+0 Inductive Step: Consider k  2 and assume that the expression is true for 2  n  k. We must show that the expression is true for n = k+1, i.e., that f k+1 f k+1 = f k +f k-1 by definition by the inductive hypothesis

7 Fibonacci Proof (cont.) Since f 2 is true and [f n is true for 2  n  k  f k+1 ] is true, then f n is true for all positive integers n  2.

8 Find a closed form solution to T(1) = c 0, T(n) = 2T(n-1)+c 1 T(1) = c 0 T(2) = 2T(1) + c 1 = 2c 0 + c 1 T(3) = 2T(2)+c 1 = 2(2c 0 +c 1 )+c 1 = 4c 0 +3c 1 T(4) = 2T(3)+c 1 = 2(4c 0 +3c 1 )+c 1 = 8c 0 +7c 1 T(5) = 2T(4)+c 1 = 2(8c 0 +7c 1 )+c 1 = 16c 0 +15c 1 Guess that T(n) = 2 n-1 c 0 + (2 n-1 -1)c 1

9 Prove that T(1) = c 0, T(n) = 2T(n-1)+c 1 has closed form solution T(n) = 2 n-1 c 0 + (2 n-1 -1)c 1 Basis Step: T(1) = 2 1-1 c 0 + (2 1-1 -1)c 1 = c 0 Induction Step: Assume that T(n) = 2 n-1 c 0 + (2 n-1 -1)c 1. We must show that T(n+1) = 2 (n+1)-1 c 0 + (2 (n+1)-1 -1)c 1 = 2 n c 0 + (2 n -1)c 1. T(n+1) = 2T(n) + c 1 = 2[2 n-1 c 0 + (2 n-1 -1)c 1 ]+ c 1 = 2 n c 0 + (2 n -2)c 1 + c 1 = 2 n c 0 + 2 n c 1 - c 1 = 2 n c 0 + (2 n -1)c 1.

10 Basic Properties of Relations Rosen 7.1

11 Binary Relations Let A and B be sets. A binary relation from A to B is a subset of A x B. A binary relation from A to B is a set R of ordered pairs where the first element of each ordered pair comes from A and the second element comes from B. If (a,b)  R, then we say a is related to b by R. This is sometimes written as a R b.

12 Relations on a set A relation on the set A is a relation from A to A. A relation on a set is a subset of A x A

13 Properties on Relations Reflexive Symmetric Antisymmetric Transitive

14 Reflexive A relation R on a set A is called reflexive if (a,a)  R for every element a  A.

15 Symmetric A relation R on a set A is called symmetric if (b,a)  R whenever (a,b)  R, for some a,b  A. A relation R on a set A such that (a,b)  R and (b,a)  R only if a = b for a,b  A is called antisymmetric. Note that antisymmetric is not the opposite of symmetric. A relation can be both. A relation R on a set A is called asymmetric if (a,b)  R  (b,a)  R.

16 Transitive A relation R on a set A, is called transitive if whenever (a,b)  R and (b,c)  R, then (a,c)  R, for a, b, c  A.

17 List of Examples If R is a relation on Z where (x,y)  R when x  y. Is R reflexive? No, x  x doesn’t make sense. Is R symmetric? Yes, if x  y, then y  x. Is R antisymmetric? No, x  y and y  x does not imply x = y. Is R transitive? No, (1,2)  R and (2,1)  R but (1,1)  R.

18 List of Examples If R is a relation on Z where (x,y)  R when x = y + 1 or x = y - 1 Is R reflexive? No, (2,2)  R. 2  2+1 and 2  2-1. Is R symmetric? Yes, if (x,y)  R, x = y + 1  y = x - 1 or x = y - 1  y = x + 1. So (y,x)  R. Is R antisymmetric? No, (2,1)  R and (1,2)  R, but 1  2. Is R transitive? No, (1,2) and (2,3)  R, but (1,3)  R. 1  3 + 1 and 1  3 - 1.

19 List of Examples If R is a relation on Z where (x,y)  R when x  y ( mod 7). (  indicates congruence) Is R reflexive? Yes, for all x, x  x ( mod 7). Is R symmetric? Yes, if (x,y)  R, x  y ( mod 7) which is equivalent to x mod 7 = y mod 7  y mod 7 = x mod 7. So (y,x)  R. Is R antisymmetric? No, (5,12)  R and (12,5)  R, but 5  12. Is R transitive? Yes, if (x,y)  R and (y,z)  R, x  y ( mod 7) and y  z ( mod 7). So x  z ( mod 7) and (x,z)  R.

20 Combining Relations the composite of R and S Let R be a relation from a set A to a set B and S a relation from set B to a set C. The composite of R and S is the relation consisting of ordered pairs (a,c) where a  A, c  C, and for which there exists an element b  B such that (a,b)  R and (b,c)  S. The composite of R and S is written S º R.

21 The powers of R, R n Let R be a relation on the set A. The powers R n, n = 1, 2, 3, …, are defined inductively by R 1 = R and R n+1 = R n  R Thus the definition shows that: –R 2 = R  R –R 3 = R 2  R = (R  R)  R and so on.

22 Theorem 1 Prove: The relation R on a set A is transitive if and only if R n  R for n = 1,2,3... Proof: We must prove this in two parts: 1) R is transitive  R n  R for n = 1,2,3... 2) R n  R for n = 1,2,3...  R is transitive.

23 The Proof – Part 1 Assume R is transitive. We must show that this implies that R n  R for n = 1,2,3.... To do this, we’ll use induction. Basis Step: R 1  R is trivially true (R 1 = R).

24 The Proof – Part 1 (continued) Inductive Step: Assume that R n  R. We must show that this implies that R n+1  R. Assume (a,b)  R n+1. Then since R n+1 = R n  R, there is an element x in A such that (a,x)  R and (x,b)  R n. By the inductive hypothesis, (x,b)  R. Since R is transitive and (a,x)  R and (x,b)  R, (a,b)  R. Thus R n+1  R.

25 The Proof – Part 2 Now we must show that R n  R for n = 1, 2, 3...  R is transitive. Proof: Assume R n  R for n = 1, 2, 3.... In particular, R 2  R. This means that if (a,b)  R and (b,c)  R, then by the definition of composition, (a,c)  R 2. Since R 2  R, (a,c)  R. Hence R is transitive.

26 Representing Relations Rosen 7.3

27 Using Matrices For finite sets we can use zero-one matrices. Elements of each set A and B must be listed in some particular (but arbitrary) order. When A=B we use the same ordering for A and B. m ij = 1 if (a i,b j )  R = 0 if (a i,b j )  R

28 Example Zero-One Matrix b1b2b3 a1 a2 a3 R = {(a1,b1), (a1,b2), (a2,b2), (a3,b2), (a3,b3)}

29 Matrix of a relation on a set, A Can be used to determine whether the relations has certain properties. Recall that R on A is reflexive if (a,a)  R for every element a  A. ReflexiveNot Reflexive

30 A relation R on a set A is called Symmetric if (b,a)  R whenever (a,b)  R for a,b  A. M R = (M R ) t is Antisymmetric if (a,b)  R and (b,a)  R only if a=b for a,b  A is antisymmetric. –If m ij = 1, i  j, m ji = 0 SymmetricAntisymmetricNeither

31 Examples Reflexive Symmetric Reflexive Antisymmetric

32 Let R1, R2 be relations on A A = {1,2,3} R1 = {(1,1), (1,3), (2,1), (3,3)} R2 = {(1,1), (1,2), (1,3), (2,2), (2,3), (3,1)}

33 R1  R2, R1  R2 M R1  R2 = M R1  M R2, M R1  R2 = M R1  M R2

34 What is R2  R1? The composite of R 1 and R 2 is the relation consisting of ordered pairs (a,c) where a  A, c  A, and for which there exists an element b  A such that (a,b)  R 1 and (b,c)  R 2. R2  R1 = {(1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1)} R1 = {(1,1), (1,3), (2,1), (3,3)} R2 = {(1,1), (1,2), (1,3), (2,2), (2,3), (3,1)}

35 Boolean Product Let A = [a ij ] be an m by k zero-one matrix and B = [b ij ] be a k by n zero-one matrix. Then the Boolean Product of A and B denoted by A B is the m by n matrix with i,j entry c ij where c ij = (a i1  b 1j )  (a i2  b 2j ) ...  (a ik  b kj ).

36 What is R2  R1? R2  R1 = {(1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1)} M R2  R1 =M R1 M R2

37 Directed Graphs (Digraph) A directed graph consists of a set V of vertices together with a set E of ordered pairs of elements of V called edges. –(a,b), a is initial vertex, b is the terminal vertex a b c Reflexive (Loops at all vertices) Symmetric (All edges both ways)

38 Relation R on a set A a b c R = {(a,b), (b,b), (b,c), (c,a), (c,c)} Transitive? No a b c R = {(a,b), (b,b), (b,c), (a,c), (c,c)} Transitive? Yes Rosen, pp. 493-494

39 Relation R on a set A a b c R = {(a,a), (a,c), (b,b), (b,a), (b,c), (c,c)} Reflexive Antisymmetric Transitive

40 Equivalence Relations Rosen 7.5

41 Equivalence Relation A relation on a set A is called an equivalence relation if it is –Reflexive –Symmetric –Transitive Two elements that are related by an equivalence relation are called equivalent. Example A = {2,3,4,5,6,7} and R = {(a,b) : a MOD 2 = b MOD 2} aMOD2 = aMOD2 aMOD2 = bMOD2  bMOD2=aMOD2 aMOD2=bMOD2, bMOD2=cMOD2  aMOD2=cMOD2

42 Prove that R = a  b(MOD m) is an equivalence relation on the set of integers. Proof: We must show that R is reflexive, symmetric and transitive. (Remember that a  b(MOD m) means that (a-b) is divisible by m. First we will show that R is reflexive. a-a = 0 and 0*m, so a-a is divisible by m.

43 Prove that R = a  b(MOD m) is an equivalence relation on the set of integers. We will show that R is symmetric. Assume that a  b(MOD m). Then (a-b) is divisible by m so (a-b) = qm for some integer q. -(a-b) = (b-a) = -qm. Therefore b  a(MOD m).

44 Prove that R = a  b(MOD m) is an equivalence relation on the set of integers. We will show that R is transitive. Assume that a  b(MOD m) and that b  c(MOD m). Then  integers j,k such that (a-b) = jm, and (b-c) = km. (a-b)+(b-c) = (a-c) = jm+km = (j+k)m Since j+k is an integer, then m divides (a-c) so a  c(MOD m).

45 Equivalence Class Let R be an equivalence relation on a set A. The set of all elements that are related to an element of A is called the equivalence class of a. The equivalence class of a with respect to R is denoted [a] R. I.e., [a] R = {s | (a,s)  R} Note that an equivalence class is a subset of A created by R. If b  [a] R, b is called a representative of this equivalence class.

46 Example Let A be the set of all positive integers and let R = {(a,b) | a MOD 3 = b MOD 3} How many distinct equivalence classes (rank) does R create? 3

47 Basic Counting Rosen 4.1

48 Sum Rule If a first task can be done in n 1 ways and a second task can be done in n 2 ways, and if these tasks cannot be done at the same time (i.e., the tasks are either/or), then there are n 1 + n 2 ways to do either task. If A and B are disjoint sets then |A  B|  |A|  |B| In general if A 1, A 2...A n are disjoint sets, then |A 1  A 2 ...  A n | = |A 1 | + |A 2 | +... + |A n |

49 Product Rule Suppose that a procedure can be broken down into two tasks. If there are n 1 ways to do the first task and n 2 ways to do the second task after the first task has been done, then there are n 1 n 2 ways to do the procedure. If A and B are disjoint sets then | A  B | = | A | | B| In general if A 1, A 2...A n are disjoint sets, then |A 1  A 2 ...  A n | = |A 1 | |A 2 |... |A n |

50 Examples There are 18 math majors and 325 computer science majors at a college –How many ways are there to pick two representatives, so that one is a math major and the other is a computer science major? 18*325 = 5850 –How many ways are there to pick one representative who is either a math major or a computer science major? 18+325 = 343

51 Examples A multiple choice test contains 10 questions. There are four possible answers for each question. –How many ways can a student answer the questions on the test if every question is answered? 4*4*4*4*4*4*4*4*4*4 = 4 10 –How many ways can a student answer the questions on the test if the student can leave answers blank? 5*5*5*5*5*5*5*5*5*5 = 5 10

52 Principle of Inclusion-Exclusion When two tasks can be done at the same time we add the number of ways to do each of the two tasks, then subtract the number of ways to do both tasks. If A and B are not disjoint |A  B|  |A|  |B|  |A  B| –Don't count objects in the intersection of two sets more than once!

53 How many bit strings of length eight either start with 1 or end with the two bits 00? Add (number of bit strings that look like 1xxxxxxx) to the (number of bit strings that look like xxxxxx00) minus the (number of bit string that look like 1xxxxx00) 1*2*2 *2 *2 *2 *2 *2 + 2* 2* 2* 2* 2* 2*1*1 – 1*2*2*2*2*2*1*1 = 2 7 +2 6 -2 5 = 2 5 (4+2-1) = 5*2 5 = 5*32 = 160

54 The Pigeonhole Principle Rosen 4.2

55 Pigeonhole Principle If k+1 or more objects are placed into k boxes, then there is at least one box containing two or more objects.

56 Generalized Pigeonhole Principle If N objects are placed into k boxes, then there is at least one box containing at least  N/k  objects Examples –Among any 100 people there must be at least  100/12  = 9 who were born in the same month. –What is the minimum number of students needed in a class to be sure that at least 6 to get the same grade? (5 choices for grades:A,B,C,D,F) Smallest integer N such that  N/5  = 6, 5*5+1 = 26

57 Example What’s the minimum number of students, each of whom comes from one of the 50 states, who must be enrolled in a university to guarantee that there are at least 100 who come from the same state? 50*99 + 1 = 4951  4951/50  = 100

58 Permutations and Combinations Rosen 4.3

59 Permutations A permutation of a set of distinct objects is an ordered arrangement these objects. An ordered arrangement of r elements of a set is called an r-permutation. The number of r-permutations of a set with n elements is denoted by P(n,r). A = {1,2,3,4} 2-permutations of A include 1,2; 2,1; 1,3; 2,3; etc…

60 Counting Permutations Using the product rule we can find P(n,r) = n*(n-1)*(n-2)* …*(n-r+1) = n!/(n-r)! How many 2-permutations are there for the set {1,2,3,4}? P(4,2)

61 Combinations An r-combination of elements of a set is an unordered selection of r element from the set. (i.e., an r-combination is simply a subset of the set with r elements). Let A={1,2,3,4} 3-combinations of A are {1,2,3}, {1,2,4}, {1,3,4}, {2,3,4}(same as {3,2,4}) The number of r-combinations of a set with n distinct elements is denoted by C(n,r).

62 Example Let A = {1,2,3} 2-permutations of A are: 1,2 2,1 1,3 3,1 2,3 3,2 6 total.Order is important 2-combinations of A are: {1,2}, {1,3}, {2,3} 3 total. Order is not important If we counted the number of permutations of each 2-combination we could figure out P(3,2)!

63 How to compute C(n,r) To find P(n,r), we could first find C(n,r), then order each subset of r elements to count the number of different orderings. P(n,r) = C(n,r)P(r,r). So C(n,r) = P(n,r) / P(r,r)

64 The English alphabet contains 21 consonants and 5 vowels. How many strings of six lower case letters of the English alphabet contain: exactly 2 vowels? Choose position for the vowels. C(6,2) = 6!/2!4! = 15 Choose the two vowels. 5 choices for each of 2 positions = 5 2 Each of the other 4 positions can contain any of 21 consonants. 21 4 15*5 2 *21 4

65 The English alphabet contains 21 consonants and 5 vowels. How many strings of six lower case letters of the English alphabet contain: at least 1 vowel Count the number of strings with no vowels and subtract this from the total number of strings. 26 6 - 21 6

66 Binomial Coefficient Another notation for C(n,r) is. This number is also called a binomial coefficient. These numbers occur as coefficients in the expansions of powers of binomial expressions such as (a+b) n.

67 Binomial Theorem Let x and y be variables and let n be a positive integer. Then

68 Discrete Probability Rosen 5.1

69 Finite Probability An experiment is a procedure that yields one of a given set of possible outcomes. The sample space of the experiment is the set of possible outcomes. An event is a subset of the sample space. The probability of an event E, which is a subset of a finite sample space S of equally likely outcomes, is p(E) = |E|/|S|

70 Dice What is the probability that when two dice are rolled, the sum of the numbers on the two dice is 7? By the product rule |S| = 6*6 = 36 |E| = 6, namely –(1,6), (2,5), (3,4), (4,3), (5,2), (6,1) |E|/|S| = 6/36 = 1/6


Download ppt "Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called."

Similar presentations


Ads by Google