The Old Hats Problem: Solution by Binomial Inversion

advertisement
The Old Hats Problem: Solution by Binomial Inversion
I. Introduction
The old hats problem goes by many names, (originally described by Montmort in 1713),
but generally runs like this: a group of n men enter a restaurant, and check their hats. The
hat-checker is absent minded, and upon leaving, she redistributes the hats back to the men
at random. What is the probability Pn that no man gets his correct hat, and how does this
behave as n approaches infinity?
This problem is just a standard question about derangementsi. Three solutions are
presented. The first two of these are standard:
1) The usual approach using the inclusion-exclusion principle
2) Developing a recursive relationship such that if Pn is the probability that none of the
n men gets his correct hat (that there is a derangement), then it is shown that
Pn = Pn-1 - 1/n (Pn-1 - Pn-2 ) ; this then proceeds to the answer in series formii.
Finally, and the main point of interest in this paper, a relatively different approach using
the technique of binomial inversion is presented. This gives a chance both to derive the
binomial inversion formula, as well as to apply it to an interesting problem.
II. Solution by the Inclusion-Exclusion
Let us define the total number of permutations of n hats as N.
To calculate the number of derangements, D, we want to exclude all permutations
possessing any of the attributes (1,2,3, …n), where attribute 1 is that man #1 gets his
correct hat, attribute 2 is that man #2 gets his correct hat, etc.
To do this, we use the inclusion-exclusion principle, with N(1) being the number of
permutations possessing attribute 1, N(1,2) being the number of permutations possessing
attributes 1 and 2, etc.
D  N  N (1)  N ( 2)  ... N (i )
 N (1,2)  N (1,3)  ... N (i , j )
 N (1,2,3)  N (1,2,4)  ... N (i , j , k )
... N (1,2,3.... n)
Now, we take advantage of symmetry, realizing that
N(1) = N(2) = … N(i)
N(1,2) = N(1,3) = …. N(i,j)
N(1,2,3) = N(1,3,4) = … N(i,j,k)
Therefore, we can write
 n
 n
 n
D  N    N (i )    N ( i , j )    N (i , j , k )
 1
 2
 3
 n
 n
   N (i , j , k , l )....   N (1,2,3,... n)
 4
 n
Now, we see that N(i), i.e. the number of permutations where man #i gets his correct hat
is simply (n-1)!, while N(i,j), i.e. the number of permutations where man #i and man #j
both get their correct hats is (n-2)!, and so forth. Therefore, we can write:
 n
 n
 n
D  N    (n  1)!   (n  2)!   (n  3)!
 1
 2
 3
 n
 n
   (n  4)!....  (n  n)!
 4
 n
Replacing N, the total permutations for n hats by n!, and simplifying the above
expression, we obtain:
D  n!(1 
1 1 1 1
1
   ...( 1) n )
1! 2! 3! 4!
n!
To generate Pn, the probability of a derangement occurring for n hats, we simply divide
the total number of derangements D by the total permutations of the n hats, n!, to get:
Pn  (1 
1 1 1 1
1
   ...( 1) n )
1! 2! 3! 4!
n!
We easily recognize this series as approaching 1/e as n approaches infinity.
III. Solution by Bijection and Recursion
We can calculate the number of derangements for n hats, Dn, by setting up a recursive
formula as follows:
If there is a derangement, then man #1 will not have his correct hat. We begin by looking
at the case where man #1 gets hat #2. This can be bijected into two subcases:
a) man #2 gets hat #1, or
b) man #2 does not get hat #1
In case (a), for a derangement to occur, we need the remaining n-2 men to get the wrong
hats. Therefore, the total number of derangements in this subcase is simply Dn-2.
In case (b), for a derangement to occur, man #2 cannot get hat #1 (that’s case a), man #3
cannot get hat #3, man #i cannot get hat #i, etc. In this subcase, the number of
derangements is Dn-1. The fact that in this subcase man #2 cannot get hat #1 rather than
hat #2 is inconsequential.
We can treat the cases where man #1 receives hat #3, or hat #4, or hat #i, in exactly the
same way. Therefore, to account for all possible derangements, there are (n-1) such
possibilities for all the different incorrect hats which man #1 can get. Therefore,
Dn = (n-1) (Dn-1 + Dn-2)
The probability of a derangement then becomes the number of derangements Dn, divided
by all possible outcomes, n!,
Pn 
Dn (n  1)

( Dn  1  Dn  2 )
n!
n!
Dn  2 
1
 1 Dn  1
Pn  (n  1) 


 n (n  1)! n(n  1) (n  2)!
that is,
1
1
Pn  (1  ) Pn  1  Pn  2 ;
n
n
1
Pn  Pn  1  ( Pn  1  Pn  2 )
n
Now, we know that P1= 0, and P2= 1/2. Now, using our formula, we can calculate
successively
1
1 1 1 1
1
P3  P2  ( P2  P1 )   .  
3
2 3 2 2 23
1
1
1
1
1
1
1
1
P4  P3  ( P3  P2 )  
 (
) 

4
2 2  3 4 2  3 2 2  3 2  3 4
.............................................
1
Pn  Pn  1  ( Pn  1  Pn  2 )
n
1
1
( 1) n  1
1
( 1) n  1
 
....

2 23
2  3  4    (n  1) n 2  3  4    (n  1)
1 1 1
( 1) n  1 ( 1) n
   ......

2! 3! 4!
(n  1)!
n!
Once again, we recognize this as approaching 1/e, as demonstrated before.
More formally, we can rearrange our equation as follows:
1
Pn  Pn  1  ( Pn  1  Pn  2 ) , leads to
n
1
Now, we let:
Pn  Pn  1   ( Pn  1  Pn  2 ) .
n
Qn  Pn  Pn  1 , thus
1
Qn   Qn  1 , or
n
1 1 
Qn   
 Qn  2
n  n  1
1  1   1 
 

 Qn  3 ;
n  n  1  n  2 
1  1   1   1
 ( 1) n  2 

      Q2
n  n  1  n  2   3
Now, our base case is Q2, which equals P2-P1= 1/2-0 = 1/2. Thus,
1
n!
Qn  ( 1) n
Now, we can set up a telescoping sum to calculate Pn:
Qn  Pn  Pn  1
Qn  1  Pn  1  Pn  2

Q2  P2  P1
Therefore, summing both sides, we get,
Pn  P1 
n
 Qi ; and since P1=0, we get
i 2
Pn 
n
1
 (1)i i! .
i 2
IV. Solution by Binomial Inversion
Our problem can also be solved by using binomial inversion. If we know that,
bn 
n
 n
  i ai
i 0
This can be inverted to retrieve the ai coefficients as follows:
an 
n
 n
 ( 1) n  i  i bi
i 0
This is the binomial inversion formula. For now, we assume it to be true, and use it to
solve our problem. Finally, we will conclude by deriving this formula.
In our case, the total number of permutations of the hats can be expressed as the sum of
n+1 non-overlapping subsets of permutations: where none of the n men gets his right hat
back, (call this Sn ), where only 1 of the men gets his right hat back, Sn-1,
where only two of the men get their right hat back, Sn-2, ... to where all the men get their
right hat, S0.
If we take for example subset Sn-2, we see that if the two men who get the correct hats are
man #1 and man #2, then the number of possible arrangements is just Dn-2, the number of
derangements for the remaining n-2 men. However, there are C(n,2) possible pairings of
the two men who get their correct hats. Therefore, the number of permutations within set
Sn-2 is:
n
Sn2    Dn2 .
2
Proceeding with a similar logic, and using the fact that
 n  n 
  
 , we may now write our total permutations as:
 i   n  i
 n
 n 
 n 
 n 
 n
n!    Dn  
 Dn  1  
 Dn  2  
 Dn  3 ...  D0
 n
 n  1
 n  2
 n  3
 0
i.e., n!  bn 
n
 n
  i  Di .
i 0
We can now use binomial inversion to obtain Dn:
Dn 
Dn 
n  i  n
(

1
)
 bi , where each bi = i! . Therefore,

 i
i 0
n
n
n!
 (1) n  i (n  i )!i!  i!
.
i 0
Dividing by n!, and letting j = n-i , and reversing the order of summation, we get once
again:
Pn 
n
 ( 1) j
j 0
1
j!
V.
The Expected Value of Correct Hats
A nice application to show the utility of this “binomial” approach is the calculation of the
expected value of the correct number of hats. In other words, if n men walk into the
restaurant and check their hats, and then walk out, receiving their hats at random, any
number from 0 to n (with the exception of n-1) men may have their correct hat. If this
experiment is repeated numerous times, how many men on average would have gotten
their correct hat? The answer to this question can be defined to be E(n), the expected
number of correct hats for n men. If we let Pj be the probability that when n men walk
into the restaurant, j men have their correct hats, then
n
E ( n )   Pj ( j )
j 0
Let us use P2 as an example to better understand the form of Pj. This is simply the
number of ways in which two men may receive their correct hat, divided by the total
number of possible arrangements of the hats, n!. From the foregoing, we see that this can
be written as
n
  Dn2
2
P2   
. Proceeding analogously, we can then write
n!
n
  Dn  j ( j )
n  j
E (n)    
.
n!
j 0
n  n  n
Now, we let j=n-i, and recall that    
   ,
j
n i  i 
and we can write
n
  Di (n  i )
n i 
. When this is simplified, we get
E (n)    
n!
i 0
  
  
n
E (n)  
i 0
n
Di (n  i )
Di
, or E (n)  
.
(n  i )!i!
i 0 ( n  i  1)! i!
Now, if we multiply both sides by (n-1)!, we get
n
 n  1
Di (n  1)!
, or (n  1)! E (n )   
 Di .
i 
i 0 ( n  1  i )! i!
i 0 
n
(n  1)! E (n)  
Since the term in the summation will equal 0 for i=n, we can rewrite this equation as
n 1 n  1


(n  1)! E (n)   
 Di . Comparing this to our result from above, we recognize
i 
i 0 
the right hand side of the equation immediately as (n  1)! , yielding the amazing result
that E(n) = 1, and is independent of n.
VI. Derivation of the Binomial Inversion Formula
If we know that bn 
 n
  ai (Eq 1) , we wish to show that this can be inverted to
i  0 i 
n
retrieve the ai coefficients as follows:
an 
 n
n
 ( 1) n  i  i bi
(Eq 2)
i 0
This can be done by introducing exponential generating functions as follows. Let

ak x k
A( x )  
k  0 k!
(Eq 3)

bk x k
B( x )  
k  0 k!
(Eq 4)
Now, by substituting for bk from (Eq 1) into (Eq 4), we get
 k  k  x k
B( x)       ai 
k  0  i  0 i   k !


k

k
(Eq 5)
k!
xk
=  
(Eq 6)
ai
i
!(
k

i
)!
k
!
k  0i  0
a
  i!( k i i)!x k
=
(Eq 7)
k  0i  0
 ai x i   x k  i 
   i!   ( k  i )! (Eq 8)


k  0 i  0

=
k
Now, we interchange the order of summation, still summing over the same half-plane.
Hence, (Eq 8) can be rewritten as,
 ai x i   x k  i 
B(x) =   


i  0 k  i i !   ( k  i )!


(Eq 9)
Now, since the things indexed with an i can be considered constant with respect to the
summation over k, the equation can be rearranged as follows:
 ai x i    x k  i 
B(x) =  


i  0 i !  k  i ( k  i )!

(Eq 10)
Now, letting j = k-i, we can rewrite (Eq 10) as:
 ai x i    x j 
  i!    j! 
 j  0 
i  0

B(x) =
(Eq 11)
The left-hand summation is recognized as A(x), while the right-hand summation is ex.
Therefore, we can now write
B(x) = A(x) ex
(Eq 12),
from which we get that
A(x) = e-xB(x)
(Eq 13),

bi x i
x
Now, we can introduce that B( x )  
, and that e 
i  0 i!
  ( 1) j x j    x i 
A( x)   
   bi

j
!
 j  0
 i  0 i ! 

( 1) j x j
 j! to get
j 0
(Eq 14)
Now, because the indexes are constant with respect to each other, we can write this as
A( x) 
 

j  0i  0
( 1) j x j x i
bi
j!
i!
(Eq 15)
Now, we can introduce n = i + j, and once again re-index to change the order in which
we sum over the i-j plane:
A( x) 

n

n  0i  0
( 1) n  i x n  i x i
bi
(n  i )!
i!
(Eq 16)
Now, we simplify, rearrange the variables, and multiply numerator and denominator by
n! to get
A( x) 

n

n  0i  0
n
n!
n i x
( 1)
bi
(n  i )!i !
n!
(Eq 17)
This is again rearranged to give
A( x ) 

xn

n  0 n!
n

i 0
 n
n i
  (  1) bi
 i
(Eq 18)
Now, comparing (Eq 18) with (Eq 3),

an x n
(written with n instead of k as the summation label), we see that
A( x )  
n
!
n 0
an 
i
n
 n
 ( 1) n  i  i bi
(QED)
i 0
Mathematics of Choice. Ivan Niven. Mathematical Association of America, 1965, p. 78.
Challenging Mathematical Problems with Elementary Solutions, Volume I. A.M. Yaglom and I.M.
Yaglom. Dover Publications, New York, 1964, p.158.
ii
Download