Recursive Definitions - PowerPoint PPT Presentation

1 / 69
About This Presentation
Title:

Recursive Definitions

Description:

Binomial Coefficient. Another notation for C(n,r) is . This number is also called a binomial coefficient. ... binomial expressions such as (a b)n. Binomial ... – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 70
Provided by: larryf74
Category:

less

Transcript and Presenter's Notes

Title: Recursive Definitions


1
Recursive Definitions
  • Rosen, 3.4

2
Recursive (or inductive) Definitions
  • Sometimes easier to define an object in terms of
    itself.
  • This process is called recursion.
  • Sequences
  • s0,s1,s2, defined by s0 a and sn 2sn-1
    b for constants a and b and n? Z
  • Sets
  • 3 ? S and xy ? S if x?S and y?S
  • Functions
  • Example f(n) 2n, f(n) 2f(n-1) and f(0) 1

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

4
Examples of Recursively Defined Functions
  • Factorial Function n!
  • n! n(n-1)(n-2).(1)
  • f(0) 1, f(n) n(f(n-1))
  • an
  • f(0) 1, f(n1) f(n)a
  • Fibonacci Numbers
  • f00, f11, f n1 fn f n-1
  • 0,1,1,2,3,5,8,13,...

5
Prove that the nth term in the Fibonacci sequence
is when n?2

Induction Proof Basic Step Let n 2, then f2
1 10 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 k1, i.e., that fk1 fk1 fk fk-1 by
definition by the inductive
hypothesis
6
Fibonacci Proof (cont.)
Since f2 is true and fn is true for 2 ? n ? k ?
fk1 is true, then fn is true for all positive
integers n?2.
7
Find a closed form solution to T(1) c0, T(n)
2T(n-1)c1
  • T(1) c0
  • T(2) 2T(1) c1 2c0 c1
  • T(3) 2T(2)c1 2(2c0c1)c1 4c03c1
  • T(4) 2T(3)c1 2(4c03c1)c1 8c07c1
  • T(5) 2T(4)c1 2(8c07c1)c1 16c015c1
  • Guess that T(n) 2n-1c0 (2n-1-1)c1

8
Prove that T(1) c0, T(n) 2T(n-1)c1has closed
form solution T(n) 2n-1c0 (2n-1-1)c1
  • Basis Step T(1) 21-1c0 (21-1-1)c1 c0
  • Induction Step Assume that T(n) 2n-1c0
    (2n-1-1)c1. We must show that T(n1)
    2(n1)-1c0 (2(n1)-1-1)c1 2nc0 (2n-1)c1.
  • T(n1) 2T(n) c1 22n-1c0 (2n-1-1)c1 c1
    2nc0 (2n-2)c1 c1 2nc0 2nc1 - c1 2nc0
    (2n-1)c1.

9
Basic Properties of Relations
  • Rosen 7.1

10
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.

11
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

12
Properties on Relations
  • Reflexive
  • Symmetric
  • Antisymmetric
  • Transitive

13
Reflexive
  • A relation R on a set A is called reflexive if
    (a,a) ? R for every element a ? A.

14
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.

15
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.

16
List of Examples
  • If R is a relation on Z where (x,y) ? R when x ?
    y.
  • Is R reflexive?
  • No, x ? x doesnt 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.

17
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 ? 21 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.

18
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.

19
Combining Relationsthe 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.

20
The powers of R, Rn
  • Let R be a relation on the set A. The powers Rn,
    n 1, 2, 3, , are defined inductively by
  • R1 R and Rn1 Rn ? R
  • Thus the definition shows that
  • R2 R ? R
  • R3 R2 ? R (R ? R) ? R and so on.

21
Theorem 1
  • Prove The relation R on a set A is transitive if
    and only if Rn ? R for n 1,2,3 . . .
  • Proof We must prove this in two parts
  • 1) R is transitive ? Rn ? R for n 1,2,3 . .
    .
  • 2) Rn ? R for n 1,2,3 . . . ? R is
    transitive.

22
The Proof Part 1
  • Assume R is transitive. We must show that this
    implies that Rn ? R for n 1,2,3 . . . .
  • To do this, well use induction.
  • Basis Step R1 ? R is trivially true (R1 R).

23
The Proof Part 1 (continued)
  • Inductive Step Assume that Rn ? R.
  • We must show that this implies that Rn1 ? R.
  • Assume (a,b) ? Rn1.
  • Then since Rn1 Rn ? R, there is an element x
    in A such that (a,x) ? R and (x,b) ? Rn.
  • By the inductive hypothesis, (x,b) ? R.
  • Since R is transitive and (a,x) ? R and (x,b) ?
    R, (a,b) ? R. Thus Rn1 ? R.

24
The Proof Part 2
  • Now we must show that
  • Rn ? R for n 1, 2, 3 . . . ? R is transitive.
  • Proof Assume Rn ? R for n 1, 2, 3 . . . .
  • In particular, R2 ? R.
  • This means that if (a,b) ? R and (b,c) ? R, then
    by the definition of composition, (a,c) ? R2.
    Since R2 ? R, (a,c) ? R.
  • Hence R is transitive.

25
Representing Relations
  • Rosen 7.3

26
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 AB
    we use the same ordering for A and B.
  • mij 1 if (ai,bj) ??R
  • 0 if (ai,bj) ?R

27
Example Zero-One Matrix
b1 b2 b3
a1 a2 a3
R (a1,b1), (a1,b2), (a2,b2), (a3,b2), (a3,b3)
28
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.

Reflexive Not Reflexive
29
A relation R on a set A
  • is called Symmetric if (b,a) ?R whenever (a,b) ?R
    for a,b ?A. MR (MR)t
  • is Antisymmetric if (a,b) ?R and (b,a) ?R only
    if ab for a,b ?A is antisymmetric.
  • If mij 1, i?j, mji 0

Symmetric Antisymmetric Neither
30
Examples
Reflexive Symmetric
Reflexive Antisymmetric
31
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)

32
R1?R2, R1?R2
MR1?R2 MR1 ? MR2, MR1?R2 MR1 ? MR2
33
What is R1 ? R2?
  • The composite of R1 and R2 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) ? R1 and (b,c) ? R2.
  • R1 ? R2 (1,1), (1,2), (1,3), (2,1), (2,2),
    (2,3), (3,1)

34
Boolean Product
  • Let A aij be an m by k zero-one matrix and B
    bij 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 cij where
  • cij (ai1?b1j) ? (ai2 ? b2j) ?... ? (aik ? bkj).

35
What is R1 ? R2?
  • R1 ? R2 (1,1), (1,2), (1,3), (2,1), (2,2),
    (2,3), (3,1)
  • MR1?R2 MR1 MR2

36
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

Reflexive (Loops at all vertices) Symmetric (All
edges both ways)
b
a
c
37
Relation R on a set A
R (a,b), (b,b), (b,c), (c,a),
(c,c) Transitive? No
b
a
c
R (a,b), (b,b), (b,c), (a,c),
(c,c) Transitive? Yes
b
a
c
Rosen, pp. 493-494
38
Relation R on a set A
R (a,a), (a,c), (b,b), (b,a), (b,c),
(c,c) Reflexive Antisymmetric Transitive
b
a
c
39
Equivalence Relations
  • Rosen 7.5

40
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 ?bMOD2aMOD2 aMOD2bMO
D2, bMOD2cMOD2 ?aMOD2cMOD2
41
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 0m, so a-a is divisible by m.

42
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).

43
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) jmkm (jk)m
  • Since jk is an integer, then m divides (a-c) so
    a?c(MOD m).

44
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 aR. I.e., aR s (a,s) ? R
  • Note that an equivalence class is a subset of A
    created by R.
  • If b ? aR, b is called a representative of this
    equivalence class.

45
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

46
Basic Counting
  • Rosen 4.1

47
Sum Rule
  • If a first task can be done in n1 ways and a
    second task can be done in n2 ways, and if these
    tasks cannot be done at the same time (i.e., the
    tasks are either/or), then there are n1 n2 ways
    to do either task.
  • If A and B are disjoint sets then AÈ BAB
  • In general if A1, A2 . . .An are disjoint sets,
    then A1?A2 ? . . . ? An A1 A2 . . .
    An

48
Product Rule
  • Suppose that a procedure can be broken down into
    two tasks. If there are n1 ways to do the first
    task and n2 ways to do the second task after the
    first task has been done, then there are n1n2
    ways to do the procedure.
  • If A and B are disjoint sets then A ? B A
    B
  • In general if A1, A2 . . .An are disjoint sets,
    then
  • A1 ? A2 ? . . . ? An A1 A2 . . . An

49
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?
  • 18325 5850
  • How many ways are there to pick one
    representative who is either a math major or a
    computer science major?
  • 18325 343

50
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?
  • 4444444444 410
  • How many ways can a student answer the questions
    on the test if the student can leave answers
    blank?
  • 5555555555 510

51
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È BAB-AÇB
  • Don't count objects in the intersection of two
    sets more than once!

52
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)
  • 122 2 2 2 2 2 2 2 2 2 2 211
    12222211
  • 2726-25 25(42-1)
  • 525 532 160

53
The Pigeonhole Principle
  • Rosen 4.2

54
Pigeonhole Principle
If k1 or more objects are placed into k boxes,
then there is at least one box containing two or
more objects.
55
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 gradesA,B,C,D,F)
  • Smallest integer N such that ?N/5? 6, 551 26

56
Example
  • Whats the minimum number of students, each of
    whom comes from one of the 50 states must be
    enrolled in a university to guarantee that there
    are at least 100 who come from the same state?
  • 5099 1 4951
  • ?4951/50? 100

57
Permutations and Combinations
  • Rosen 4.3

58
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

59
Counting Permutations
  • Using the product rule we can find P(n,r)
  • n(n-1)(n-2) (n-r1)
  • n!/(n-r)!
  • How many 2-permutations are there for the set
    1,2,3,4? P(4,2)

60
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 A1,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).

61
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)!

62
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)

63
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 52
  • Each of the other 4 positions can contain any of
    21 consonants.
  • 214
  • 1552214

64
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.
  • 266 - 216

65
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 (ab)n.

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

67
Discrete Probability
  • Rosen 5.1

68
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

69
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 66 36
  • E 6, namely
  • (1,6), (2,5), (3,4), (4,3), (5,2), (6,1)
  • E/S 6/36 1/6
Write a Comment
User Comments (0)
About PowerShow.com