Sequences & Summations

Download Report

Transcript Sequences & Summations

Recursive Definitions
Rosen, 3.4
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 x+y  S if xS and yS
– Functions
• Example: f(n) = 2n, f(n) = 2f(n-1) and f(0) = 1
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.
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(n+1) = f(n)*a
• Fibonacci Numbers
 f0=0, f1=1, f n+1 = fn + f n-1
 {0,1,1,2,3,5,8,13,...}
Prove that the nth term in the Fibonacci
n 2
sequence is 1   f i when n2
i 0
Induction Proof:
2 2
Basic Step: Let n = 2, then f2 = 1 =
1   f i =1+0
i 0
Inductive Step: Consider k2 and assume that the expression is
true for 2  n  k. We must show
k1 that the expression is true for
 (1   f i )
n = k+1, i.e., that fk+1
i 0
fk+1
= fk +fk-1 by definition
k 2
 (1   f i )  f k 1
i 0
by the inductive hypothesis
Fibonacci Proof (cont.)
k 2
 (1   f i )  f k 1
i 0
k1
 (1   f i )
i 0
Since f2 is true and [fn is true for 2  n  k  fk+1] is
true, then fn is true for all positive integers n2.
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(2c0+c1)+c1 = 4c0+3c1
T(4) = 2T(3)+c1 = 2(4c0+3c1)+c1 = 8c0+7c1
T(5) = 2T(4)+c1 = 2(8c0+7c1)+c1 = 16c0+15c1
Guess that T(n) = 2n-1c0 + (2n-1-1)c1
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(n+1) =
2(n+1)-1c0 + (2(n+1)-1-1)c1 = 2nc0 + (2n-1)c1.
T(n+1) = 2T(n) + c1 = 2[2n-1c0 + (2n-1-1)c1]+
c1 = 2nc0 + (2n-2)c1 + c1 = 2nc0 + 2nc1 - c1 =
2nc0 + (2n-1)c1.
Basic Properties of Relations
Rosen 7.1
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.
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
Properties on Relations
•
•
•
•
Reflexive
Symmetric
Antisymmetric
Transitive
Reflexive
• A relation R on a set A is called reflexive
if (a,a)  R for every element a  A.
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.
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.
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.
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.
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.
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.
The powers of R,
n
R
• Let R be a relation on the set A. The
powers Rn, n = 1, 2, 3, …, are defined
inductively by
• R1 = R and Rn+1 = Rn  R
• Thus the definition shows that:
– R2 = R  R
– R3 = R2  R = (R  R)  R and so on.
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.
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, we’ll use induction.
Basis Step: R1  R is trivially true (R1 = R).
The Proof – Part 1 (continued)
Inductive Step: Assume that Rn  R.
We must show that this implies that Rn+1  R.
Assume (a,b)  Rn+1.
Then since Rn+1 = 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 Rn+1  R.
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.
Representing Relations
Rosen 7.3
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.
mij = 1 if (ai,bj) R
= 0 if (ai,bj) R
Example Zero-One Matrix
b1
a1
a2
a3
b2
b3
1 1 0
0 1 0


0 1 1
R = {(a1,b1), (a1,b2), (a2,b2), (a3,b2), (a3,b3)}
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.
1 1 0
0 1 0

0 1 1

Reflexive
1 1 0
1 1 0

0 1 0

Not Reflexive
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
a=b for a,b A is antisymmetric.
– If mij = 1, ij, mji = 0
1 1 0
1 1 1

0 1 0

Symmetric
1
1

0
0 1 1 0 1
0 0 1 0 0



1
1
1


1 1
Antisymmetric
Neither
Examples
1
0

1
0 1
1 0
0 1

1
1

0
0 1
1 1

0 1
Reflexive
Reflexive
Symmetric
Antisymmetric
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)}
1 0 1 
1 1 1 
M R1  1 0 0 ,M R2  0 1 1 


0 0 1 

1 0 0

R1R2, R1R2
1 0 1 
1 1 1 
M R1  1 0 0 ,M R2  0 1 1 




0
0
1
1
0
0




1 1 1
1 0 1 
M R1R 2  1 1 1,M R1R2  0 0 0 


1 0 1

0 0 0 

MR1R2 = MR1  MR2, MR1R2 = MR1  MR2
What is R2  R1?
R1 = {(1,1), (1,3), (2,1), (3,3)}
R2 = {(1,1), (1,2), (1,3), (2,2), (2,3), (3,1)}
M R1
1 0 1
1 1 1




 1 0 0, M R 2  0 1 1
0 0 1
1 0 0
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.
R2  R1 = {(1,1), (1,2), (1,3), (2,1), (2,2), (2,3),
(3,1)}
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).
What is R2  R1?
1 0 1 
1 1 1 
M R1  1 0 0 ,M R2  0 1 1 




0
0
1
1
0
0




R2  R1 = {(1,1), (1,2), (1,3), (2,1), (2,2),
(2,3), (3,1)}
MR2R1 =MR1 MR2
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
b
a
c
Reflexive (Loops at
all vertices)
Symmetric (All
edges both ways)
Relation R on a set A
R = {(a,b), (b,b), (b,c),
(c,a), (c,c)}
b
a
Transitive?
No
c
b
a
R = {(a,b), (b,b), (b,c),
(a,c), (c,c)}
Transitive?
Rosen, pp. 493-494
c
Yes
Relation R on a set A
b
a
R = {(a,a), (a,c), (b,b), (b,a),
(b,c), (c,c)}
Reflexive
c
Antisymmetric
Transitive
Equivalence Relations
Rosen 7.5
Equivalence Relation
• A relation on a set A is called an equivalence relation if it is
– Reflexive
– Symmetric
– Transitive
aMOD2 = aMOD2
aMOD2 = bMOD2 bMOD2=aMOD2
aMOD2=bMOD2,
bMOD2=cMOD2
aMOD2=cMOD2
• 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}
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.
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).
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).
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.
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
Basic Counting
Rosen 4.1
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B||A||B|
• In general if A1, A2 . . .An are disjoint sets, then |A1A2  . . .
 An| = |A1| + |A2| + . . . + |An|
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|
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
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 = 410
– 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 = 510
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!
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
= 27+26-25 = 25(4+2-1)
= 5*25 = 5*32 = 160
The Pigeonhole Principle
Rosen 4.2
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.
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
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
Permutations and Combinations
Rosen 4.3
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…
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)
4 * 3 * 2 *1 4!
4*3 
  12
2 *1
2!
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).
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)!
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)
n!
n!
(n  r )! n!(r  r )!



r!
(n  r )!r! r!(n  r )!
(r  r )!
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
15*52*214
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
Binomial Coefficient
n

 
Another notation for C(n,r) is r  . 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.
Binomial Theorem
Let x and y be variables and let n be a positive
integer. Then
n
(x  y) n   C(n, j)x n  j y j
j 0
n n 
n n1
n n 2 2
n  n 1 
n n









x 
x y
x y  ...
xy 
y
0
1
2
n  1
n
Discrete Probability
Rosen 5.1
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|
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