Introduction to Database Systems

Download Report

Transcript Introduction to Database Systems

Discrete Mathematics
Ch. 6 Counting and Probability
Today we will review sections 6.4, 6.5
Instructor: Hayk Melikyan
[email protected]
Melikyan/DM/Fall09
1
Combinations
Definition: An r-combination of a set of n elements is
a subset of r elements. The symbol C(n, r), read
“ n choose r” denotes the number of r-combinations
•
•
Permutation is an ordered selection
Combination is an unordered selection
Example: Let S ={Ann, Bob, Cyd, Dan}.
List all 3- combinations of S
Melikyan/DM/Fall09
2
Relationship between Permutations and Combinations
Example: Write all two permutations of the set {1, 2, 3, 4}
Melikyan/DM/Fall09
3
Theorem: The Number of subset of size r ( r-combinations)
that can be chosen from a set of n elements, C(n, r), is given
by the formula
n  P ( n, r )

C(n, r) =   
 r
r!
or equivalently
n!
 n
C(n, r) =   
r
(n  r )! r !
where n and r are nonnegative integers with r  n
To form an r-permutation of a set of n elements first choose a
subset of r of the n elements ( there are C(n, r) you can
choose) then choose an ordering for the r elemets
Melikyan/DM/Fall09
4
Problems: There are 12 people, 5 men and 7 women, to work on a
project:
– How many 5-person teams can be chosen?
P(12, 5) = 792
– If two people insist on working together (or not working at all),
how many 5-person teams can be chosen?
Melikyan/DM/Fall09
5
• Suppose two members of the group do not get along and refuse to
work together on a team. How many 5-person teams can be formed?
Is there any alternatives to this solution?
Melikyan/DM/Fall09
6
Problem: Suppose the group consists of 7 women and 5 men.
1) How many 5-person teams contain at most 1 man?
Melikyan/DM/Fall09
7
How many 5-person teams contain at least 1 man?
Melikyan/DM/Fall09
8
Poker Hands:
There are 52 cards in a deck. Each card has a suit and a value.
4 suits
(♠ ♥ ♦ ♣)
13 values (2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A)
Five-Card Draw is a card game in which each player is initially
dealt a hand, a subset of 5 cards.
How many different hands?
Melikyan/DM/Fall09
9
Four of a Kind
A Four-of-a-Kind is a set of four cards with the same value.
How many different hands contain a Four-of-a-Kind?
A hand with a Four-of-a-Kind is completely described by a
sequence specifying:
1. The value of the four cards.
2. a card other than four cards selected in step 1.
By generalized product rule, there are 13x 48 = 624 hands.
Melikyan/DM/Fall09
10
What about Full House
A Full House is a hand with three cards of one value and two cards of another value.
How many different hands contain a Full House?
A Full Houses can be specified by selecting
1. The value of the triple, which can be chosen in 13 ways.
2. The suits of the triple, which can be selected in C(4,3) =4 ways.
3. The value of the pair, which can be chosen in 12 ways ( why12?).
4. The suits of the pair, which can be selected in C(4, 2) = 6 ways.
By generalized product rule, there are
Melikyan/DM/Fall09
11
How many hands have Two Pairs; that is, two cards of one value,
two cards of another value, and one card of a third value?
1. The value of the first pair, which can be chosen in 13 ways.
2. The suits of the first pair, which can be selected C(4, 2) = 6 ways.
3. The value of the second pair, which can be chosen in 12 ways.
4. The suits of the second pair, which can be selected in C(4, 2) = 6 ways
5. The fifth card, which can be chosen in 44 ways.
So, is the total number = 13x6x12x6x44 ?
Double
Counting
Melikyan/DM/Fall09
12
Problem: How many eight-bit strings have exactly three 1’s?
To solve the problem, imagine eight empty positions in to which the
0’s and 1’s of the bit strings will be placed
Once a subset of three positions has been chosen from the 8 to
contain 1’s the remaining places must contain 0’s. So, the number
of 8-bits containing exactly 3 1’s is
 8
8!
C(8, 3) = 54 =   
 3
Melikyan/DM/Fall09
5! 3!
13
Permutation of a Set with Repeated Elements
Problem: How many different ways can letters in the word MISSISSIPPI
be arranged.
Solution: Imagine placing the 11 letters of this word one after another into
11 positions
Melikyan/DM/Fall09
14
Solution (continue)
Note that constructing an ordering for these letters can be thought of as
four step process:
1.
2.
3.
4.
Select positions for the four S’s. C(11, 4)
Select positions for the four I’s out of remaining 7 positions . C(7, 4)
Select positions for the two P’s out of three positions. C(3, 2)
Select a position for the M. C(1, 1)
C(11, 4) C(7, 4) C(4, 3) C(1.1) =
11!
3!
1!
7!
7 ! 4 ! 4 ! 3! 2 ! 1! 1! 0!
11!
=
= 34650
4 ! 4 ! 2 ! 1!
Melikyan/DM/Fall09
15
Theorem: Suppose a collection consists of n objects of which:
.
.
.
n1 are type 1 and are indistinguishable from each other
n2 are of type 2 and are indistinguishable from each other
nk are of type k and are indistinguishable from each other
and suppose that n1 + n2 = … + nk = n.
Then the number of distinct permutations of the n objects is
C(n, n1)C(n - n1, n2)C(n – n1- n2, n3). . . C(nk, nk) =
n!
= n ! n !   n !
1
2
k
Melikyan/DM/Fall09
16
Combinations with Repetition
Definition: An r-combination with repetition allowed (or multiset of size r)
chosen from a set X of n elements is an unordered selection of elements
where some elements can be repeated
Example: Find the number of 3-combinations with repetitions
allowed from the set of4 elements {1, 2, 3, 4}
Melikyan/DM/Fall09
17
Theorem: The number of r-combinations with repetition allowed
that can be selected from a set of n elements is
 r  n  1 (n  r  1)!

C(r + n -1, r) =  r  (n  1)! r !
Example: How many monotone triples exist in a set of n
elements?
Same as in example 6.5.3 from textbook.
Here is the picture explaining for the case n = 5
Melikyan/DM/Fall09
18
Example (continue):
Thus any triple of integers (i, j, k) with 1  i  j  k  n can be
represented as a sting of n -1 vertical bars and three crosses. By theorem
The number of such triples is
 3  n  1
(n  2)! n(n  1)(n  2)



6
 3  (n  1)! 3!
Melikyan/DM/Fall09
19
Nice Example:
Consider the implementing the following algorithm:
for k := 1 to n
for j := 1 to k
for i := 1 to j
printf(“hello ”);
next I
next j
next k
How many times word hello will be printed if the program
implementing this algorithm is run?
n(n  1)(n  2)
6
Melikyan/DM/Fall09
20
Example: Integral solutions of an Equations
How many non-negative integral solutions are there
to the equation x1 + x2 + x3 + x4 = 10?
 3  10
(13)!
 286

 
 10  (10)! 3!
Melikyan/DM/Fall09
21
How many positive integral solutions are there for the
above equation?
 3  6
9!
 84

 
 6  6! 3!
Which Formula to Use?
Melikyan/DM/Fall09
22