Download 4.4-5

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Selections, Orderings, Assignments -
Sections 4.4-4.5
Ordered Selections
How do we count the number of ways of selecting m items out of a set of n items where different orderings of the
same selected items are considered different selections? We denote this number by Π (n,m).
e.g. Set of n=4 items {a,b,c,d} How many different ordered selections of m=1 items?
a
b
c
Π (4,1)=4
d
e.g. Set of n=4 items {a,b,c,d} How many different ordered selections of m=2 items?
ab
ac
ad
ba
bc
bd
ca
cb
cd
da
db
dc
Π (4,2)=12 = Π (4,1)*3 = Π (4,1)*(4-1)
e.g. Set of n=4 items {a,b,c,d} How many different ordered selections of m=3 items?
abc
acb
adb
bac
bca
bda
cab
cba
cda
dab
dba
dca
abd
acd
adc
bad
bcd
bdc
cad
cbd
cdb
dac
dbc
dcb
Π (4,2)=24 = Π (4,2)*2 = Π (4,2)*(4-2)
e.g. Set of n=4 items {a,b,c,d} How many different ordered selections of m=4 items?
abcd
acbd
adbc
bacd
bcad
bdac
cabd
cbad
cdab
dabc
dbac
dcab
abdc
acdb
adcb
badc
bcda
bdca
cadb
cbda
cdba
dacb
dbca
dcba
Π (4,4)=24 = Π (4,3)*1 = Π(4,3)*(4-3)
Notice that, to get the ordered selections of 2 items, we can just take the ordered selections of 1 item and append all
possible (3 for our example) remaining items. Thus, for each of the 4 selections of 1 item in our example there are
3 selections of 2 items.
a
ab
b
ac
ad
ba
bc
c
bd
ca
cb
d
cd
da
db
dc
Likewise, to get the ordered selections of 3 items, we can just take the ordered selections of 2 items and append all
possible (2 for our example) remaining items. Thus, for each of the 12 selections of 2 items in our example there
are 2 selections of 3 items.
ab
ac
ad
ba
bc
bd
ca
cb
cd
da
db
dc
abc abd acb acd adb adc bac bad bca bcd bda bdc cab cad cba cbd cda cdb dab dac dba dbc dca dcb
This leads us to the following general formula
Sections 4.4-4.5
1/4
Π (n,m)=n(n-1)(n-2)...(n-m+1)
Notice that another way to write π(n,m) is n!/(n-m)! because
n(n − 1)(n − 2)...( n − m + 1)(n − m)...( 1)
n!
=
(n − m)...( 1) and the last n-m factors in the numerator are
(n − m)!
canceled by the denominator.
Assignments of values to items in a list is similar to these ordered selection problems. The difference is that
assignment of values allows the values to be “reused” so it is like selection with replacement.
How many 3 digit decimal integers are there? This is an assignment problem with 3 places and 10 values and the
answer is 103 = 1000.
But how many 3 digit decimal numbers in which no digit appears more than once? This is an ordered selection
problem and the answer is Π (10,3)=10!/7!=10X9X8=720.
Unordered Selections
Sometimes we want to count the number of ways of selecting m items out of a set of n items and we are not
concerned with the order.
e.g. Set of n=4 items {a,b,c,d} How many different unordered selections of m=1 items?
a
b
c
d
4
e.g. Set of n=4 items {a,b,c,d} How many different unordered selections of m=2 items?
same
ab
ac
same
ad
ba
bc
bd
same
ca
cb
cd
da
db
dc
same
same
same
ab
ac
ad
bc
bd
cd
so only 6
Notice that the number of unordered selections of m items from a set of n items is the number of ordered selections
Π (n,m) divided by the number of permutations Π (m) of m items. That is, the number of unordered selections of m
items from a set of n items, which we denote
 n
  , is
 m
n!
 n  Π(n, m)
=
 =
 m
Π( m )
(n − m)!m!
So, how many unordered selections of 2 items out of a set of 4 items (a,b,c,d)?
Sections 4.4-4.5
2/4
4!
4!
4 X3
 4 Π(4,2)
=
=
=
=6
 =
 2
2
Π(2)
( 4 − 2)!2! 2!2!
ab ac ad bc bd cd
Example: How many different poker hands? How many ways of dealing 5 cards from a 52 card deck. We don’t care
the order of the cards.
 52 52X51X50X49X48
= 2,598,960
 =
 5
1X2X3X4X5
Example: How many different study groups of 5 students can be chosen from a class of 25 students?
 25 25X24X23X22X21
= 53,130
 =
 5
1X2X3X4X5
A Recursive Definition of n Choose m
Let N be a set with n elements. Let S be the set of all subsets of N that have exactly m elements. Let ε be any element of N.
Divide S into two sets:
S1 = {x | x ∈ S and ε ∈ x}
S2 = S – S1 = {x | x ∈ S and ε not∈ x}
The number in S1 is
 n − 1


 m 
 n − 1

.
 m − 1
 5
, So S contains   =10 elements.
 3
and the number S2 is
Example: N={a,b,c,d,e} n = 5, m = 3.
Let ε = a.
S1 is all combinations that include an a:
{abc}, {abd}, {abe}, {acd}, {ace}, {ade}
and the number of those is
 4
  =6
 2
S2 is all combinations that don’t include a:
{bcd}, {bce}, {bde}, {cde}
and the number of those is
So,
 4
  =4
 3
 5
 4  4
  +   = 4 + 6 = 10 =  
 3  2
 3
Sections 4.4-4.5
3/4
A recursive definition is, then,
Basis:
 n
  =1, because there is only way to choose nothing from a set and
 0
 n
  =1, because there is only one way to choose all items from a set.
 n
Induction:
 n   n − 1  n − 1 
  =
 +

 m  m   m − 1
This recursion can displayed in Pascal’s Triangle, where borders are the basis cases.
 n
  is in the (m+1)st entry of
 m
the (n+1)st row.
1
1
1
1
2
1
3
1
4
10
6
1
6
5
1
3
4
1
1
1
10
15
5
20
1
15
6
1
The interior entries are the sums of the two numbers above them as defined by the induction part of the recursive
definition.
1
1
1
+
+
2
6
4
15
1
+
10
+
20
5
+
+
+
+
+
+
10
+
+
+
1
+
5
+
1
6
+
15
1
+
+
4
+
1
+
+
+
1
3
+
+
3
+
+
1
1
+
+
+
+
1
6
1
Another useful recurrence relation is:
 n n − i + 1  n 
 =


 i
 i − 1
i
Sections 4.4-4.5
4/4