Download Exploring N-Choose-K (and Pascal`s Triangle)

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

Addition wikipedia , lookup

Location arithmetic wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Transcript
Exploring N-Choose-K !
(and Pascal’s Triangle)"
CSCI 2824, Fall 2014"
"
!
Assignments
• To read this week: Sections 5.1-5.3 (Ensley/Crawley)
• PS 2 due today!
"
!
!
!!
Our example from last time:
In a room with 20 people in it, how many
distinct handshakes are there?
The answer is: 20 choose 2, also written
C(20,2) in the textbook, or more often:
20
2
N-Choose-K
The formula for C(n,k) is:
n!
-----------------
(n-k)! k! Note: This is the case where order doesn’t matter,
and repeats are not allowed.
A couple of notes about n-choose-k
•  N-choose-K is the same as N-choose-(N-K)
For instance: C(12,3) = C(12,9)
•  Note that it makes sense (given our
conventions) that 0! = 1
A practice problem
How many ways are there to get a full house
in poker? (Three of one kind of card, two of
the other.)
A couple of other poker
problems…
•  How many ways are there to get 4 of a kind
in a 5-card poker hand? (E.g., QH, QSp,
QCl, QD, 7D)
•  How many ways are there to get a flush?
(E.g., 2D, 5D, 7D, 8D, JD)
A practice problem with a new
wrinkle…
Assume that you’re a burglar,
and you come up to one of the
“standard” keypad alarms, which
you know takes a code of four
values. You see that only keys 1,
2, and 3 have been smudged
(indicating that the 4-number
code is something like 1123, or
1232, or something like that).
How many possible codes do you
have to try to gain entry?
Multiple subsets…
•  Suppose we need to split a group of twelve
people into three committees of 4. How
many ways are there of doing this?
There are C(12, 4) ways of choosing the first
committee. Then, once we’ve chosen that
first group, from the remaining 8 people,
there are C(8,4) ways of splitting into two
committees of four. So the total number of
ways of forming three committees is:
(12!/(8!4!)) * (8!/4!4!) = 12!/(4!4!4!) From poker to bridge…
In bridge, the entire deck is dealt to four
players, each of whom gets 13 cards. How
many possible bridge deals are there?
Let’s make a diagram of nchoose-k
•  We’ll make a table: for the nth row of the
table, we’ll list:
C(n,0), C(n,1), C(n,2) … C(n,n)
1!
1
1
1
1
1
1
1
!
1!
2
3
4
5
6
7
1!
3
6
10
15
21
1!
4
10
20
35
1!
5 1!
15 6 1!
35 21 7 1!
Pascal’s Triangle
1!
1
1
1
1
1
1
1
1!
2
3
4
5
6
7
1!
3
6
10
15
21
1!
4
10
20
35
1!
5 1!
15 6 1!
35 21 7 1!
Some quickie patterns…
•  The first column (and the final column) are
all 1s, because n-choose-0 is 1 and nchoose-n is 1.
•  The second column is the n-choose-1
column, which is just the natural numbers.
•  The third column is the n-choose-2 column,
which is also called the “triangular
numbers”
•  The fourth column is called “the tetrahedral
numbers”:
Pascal’s Triangle
1!
1
1
1
1
1
1
1
1!
2
3
4
5
6
7
1!
3
6
10
15
21
1!
4
10
20
35
1!
5 1!
15 6 1!
35 21 7 1!
Why is each number inside the
triangle (not at the edges) equal
to the sum of the two above it?
What we want to show is:
C(n, k) = C(n-1, k) + C(n-1, k-1)
Look at it this way:
I want to pick a committee of 4 people from a
set of 12. There are C(12, 4) ways of doing
this.
Suppose there’s one guy in the original group
of twelve named “Fred”. Now, I can make
my committee either by first choosing to
include Fred, or first choosing to exclude
him.
If I choose to include Fred, I’ll have:
C(11, 3) ways of creating the remaining part
of the committee.
If I choose to exclude Fred, I’ll have:
C(11,4) ways of creating the committee.
So the total number of possible committees must be
the same as the sum of those with Fred and those
without Fred. Or, in other words:
C(12, 4) = C(11,4) + C(11, 3) What happens if we add all the
elements in a row?
1!
1
1
1
1
1
1
1
1!
2
3
4
5
6
7
1!
3
6
10
15
21
1!
4
10
20
35
1!
5 1!
15 6 1!
35 21 7 1
This seems to suggest a pattern…
C(n,0) + C(n, 1) + … C(n, n) = 2n Why might this be true?
Think of it this way
•  In a set of n elements, how many possible
subsets are there?
•  One way of thinking about this is to say that
for each element we can either choose to
include or exclude the element in a given
subset. So the total number of subsets must
be equal to 2n. Another, equally good way to
approach the question…
•  Or, we could say that the total number of
subsets of a set of n elements is just the sum
of subsets of all possible sizes. It’s the sum
of all subsets of size 0, of size 1, of size 2,
etc.
C(n,0) + C(n, 1) + C(n, 2)… C(n, n)
Why are these values called the
“binomial coefficients”?
•  Start with the binomial (x + y) and raise it to
successive powers:
(x + y)0 = 1
(x + y)1 = x + y
(x + y)2 = x2 + 2xy + y2
(x + y)3 = x3 + 3x2y + 3xy2 + y3
(x + y)4 = x4 + 4x3y + 6x2y2 + 4xy3 + y4 So we end up with the binomial
theorem:
(x + y)n =
Σ0<=k<=n C(n,k) xk y(n-k)
Proving the binomial theorem
two ways:
•  The “giving n distinct pieces of candy to x
girls and y boys” version
•  The “multiply lots of (x + y) terms together
and see how many times you choose x and
how many times you choose y” version
Substitute 1 for x, 1 for y:
(x + y)n = Σ0<=k<=n C(n,k) xk y(n-k)
Now substitute -1 for x, 1 for y:
(x + y)n = Σ0<=k<=n C(n,k) xk y(n-k)
Alternating sums in a row…
1!
1
1
1
1
1
1
1
1!
2
3
4
5
6
7
1!
3
6
10
15
21
1!
4
10
20
35
1!
5 1!
15 6 1!
35 21 7 1
The Hockey Stick Identity
1!
1
1
1
1
1
1
1
1!
2
3
4
5
6
7
1!
3
6
10
15
21
1!
4
10
20
35
1!
5 1!
15 6 1!
35 21 7 1!
!
C(n,2) = C(n-1, 1) + C(n-2, 1) +… C(1, 1)
Using the Binomial Theorem to Answer
a Sports Gambling Problem
•  As of today, the Kansas City Royals are beating the
Baltimore Orioles in the ALCS, 2 games to 0 (it’s a bestof-seven series).
•  Suppose that in each given game, the Orioles and Royals
are evenly matched. In other words, for a single game, it’s
a 50-50 chance that either will win.
•  Suppose also that you and a friend each put down $50
before the series. You bet on the Orioles, and your friend
bet on the Royals. You have to end the bet today, however,
before the series is over. How much of the $100 pot should
you receive? •  Let the Orioles and Royals play out 5 more
games (even if the series is “determined”
before the 5 games are complete).
•  The Royals have to win any two games (or
more) out of 5 to win the series. The Orioles
have to win 4 or 5 games to win the series.
Of the 32 possible sequences of
wins and losses, the Royals win
in:
C(5,2) + C(5, 3) + (C5, 4) + C(5, 5) of them.
The Orioles win in:
C(5,0) + C(5, 1) of them.
Orioles/Royals
1!
1
1
1
1
1
1
1
1!
2
3
4
5
6
7
1!
3
6
10
15
21
1!
4
10
20
35
1!
5 1!
15 6 1!
35 21 7 1