Random Permutation
Random Permutation
Modules in
Undergraduate The Probability
Mathematics
and Its
That a Queen Sits
Applications Beside a King:
Juxtapositions and Runs
Published in
cooperation with
in a Random Permutation
The Society for John M. Holte
Industrial and Mark M. Holte
Applied Mathematics, Kenneth A. Suman
The Mathematical
Association of America,
The American
Mathematical
Association of
Two-Year Colleges,
The American
Statistical Association.
Applications of Combinatorics
and Probability to Statistics,
Applied Probability and
Recreational Mathematics
COMAP, Inc., Suite 210, 57 Bedford Street, Lexington, MA 02420 (781) 862–7878
110 Tools for Teaching 1998
60C05
Mark M. Holte
1410 Krause Pl.
Mt. Vernon, WA 98274
Kenneth A. Suman
Department of Mathematics and Statistics
Winona State University
Winona, MN 55987
[email protected]
MATHEMATICAL FIELD: Combinatorics, probability
Tools for Teaching 1998, 109–130. Reprinted from The UMAP Journal 19 (4) (1998): 373–394.
°Copyright
c 1998, 1999 by COMAP, Inc. All rights reserved.
Permission to make digital or hard copies of part or all of this work for personal or classroom use
is granted without fee provided that copies are not made or distributed for profit or commercial
advantage and that copies bear this notice. Abstracting with credit is permitted, but copyrights
for components of this work owned by others than COMAP must be honored. To copy otherwise,
to republish, to post on servers, or to redistribute to lists requires prior permission from COMAP.
Table of Contents
1. INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2. THE PROBABILITY THAT A QUEEN IS NEXT TO A KING . . . . . . . . 1
3. JUXTAPOSITIONS AND RUNS . . . . . . . . . . . . . . . . . . . . . . . 4
4. ORDERED JUXTAPOSITIONS . . . . . . . . . . . . . . . . . . . . . . . 7
5. MEAN AND VARIANCE . . . . . . . . . . . . . . . . . . . . . . . . . 8
6. RELATED PROBLEMS . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
8. SOLUTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
REFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1. Introduction
Suppose that you thoroughly shuffle a deck of ordinary playing cards and
then deal them out in one long row. What is the probability that somewhere
in the row you will find a Queen next to a King? Or a club next to a diamond?
Or a face card next to an Ace? More generally, in a random permutation of n
objects of various kinds, what is the probability of finding j instances where an
object of a given kind is adjacent to one of another given kind?
At first glance, you may conclude that an explicit solution would be quite
difficult. Indeed, an earlier published solution [Singmaster 1991] for the special
case of no Queen–King juxtapositions relied entirely on a recurrence-relation
calculation. But in fact, explicit solutions to such problems turn out to be
elementary and accessible to undergraduate students who have studied com-
binatorics or discrete probability. Furthermore, the juxtaposition problem turns
out to be closely related to the problem of determining the distribution of runs,
which is studied in many undergraduate mathematical statistics courses and
whose solution has been known at least since 1886 (Whitworth [1886, Exercises
193, 194]; Barton and David [1957, 168]). In fact, the solution of the juxtaposi-
tion problem to be given here provides a natural follow-up to the solution of
the runs problem.
In the special case of Ace-King juxtapositions, an explicit solution for j
juxtapositions was given by Holte and Holte [1993]. An explicit solution for
the general problem of no adjacencies between any objects of k different kinds
was given by Suman [1993]. In this Module, we extend the techniques of these
papers to find the probability of exactly j juxtapositions occurring between
objects of two different kinds in a random permutation of any number of objects
of two or more kinds.
In addition, we find the mean and variance of the number of juxtapositions.
Doing this provides a nice illustration of techniques for dealing with moments
of sums of dependent random variables.
1
114 Tools for Teaching 1998
|K|KK|K.
¡4¢
There are m ways to choose these places. With these choices, the string of Qs
and Ks is determined; it would be QQKQKKQK in our example. There are
µ ¶2
4
m
possible arrangements.
Next, let’s count the number of ways that we can insert the Ns so as to
achieve j actual juxtapositions. Think of the nine spaces before, between, and
after the four Qs and four Ks as urns. To achieve j actual
¡m¢juxtapositions, choose
j of the m QK urns to be empty; this can be done in j ways. To make sure
that there are no more than j juxtapositions, place one N in each of the other
(m − j) QK urns. Then distribute the remaining 44 − (m − j) Ns into the (9 − j)
urns that do not have to be empty.
We need to know here and later that
the number of ways to place r identical balls into u urns without restriction is
µ ¶
r+u−1
.
u−1
2
The Probability That a Queen Sits Beside a King 115
µ ¶ µ ¶
(44 − (m − j)) + (9 − j) − 1 52 − m
= .
(9 − j) − 1 8−j
j 0 1 2 3 4
qj 0.7187 0.2556 0.0250 0.0007 4 × 10−6
Exercises
¡ ¢2
1. List the 43 possible sequences of four Qs and four Ks having exactly 3 QK
juxtapositions.
2. Suppose that the deck is reduced to two Qs, two Ks, and one Ace. Adapt
the analysis in the text to complete the following table. Find the probability
qj of j QK juxtapositions for each j.
3
116 Tools for Teaching 1998
4
The Probability That a Queen Sits Beside a King 117
¡ ¢¡b−1¢
ways. Together, we have a−1 i i−1 ways to achieve the A B A · · · B A
+ + + + +
pattern.
The remaining patterns can be counted by switching A and B (and, corre-
spondingly, a and b) and applying the formulas just derived. The result is that
¡ ¢¡a−1¢
the number of B + A+ B + · · · A+ B + patterns is b−1 i−1 , and the number of
¡b−1¢¡a−1¢ i
B A B · · · B A patterns is i−1 i−1 .
+ + + + +
5
118 Tools for Teaching 1998
Finally, assuming that all n! permutations are equally likely and taking
into account the possible permutations of the As, Bs, and Cs, we find that
the probability pj of getting exactly j instances where an A-object is next to a
B-object (in either order) is
X µ ¶µ ¶
m n − m a!b!c!
pj = Rm+1 (a, b) (2)
m
j a+b−j n!
X
2 min{a,b}
pj = r(m + 1; a, b)h(j; a + b, m, n − m).
m=max{j,1}
j 0 1 2 3 4 5 6 7
pj .514 .372 .100 .013 .001 3 × 10−5 4 × 10−7 2 × 10−9
j 2 3 4 5 6 7 8 9 10 11 12
pj .01 .04 .10 .16 .19 .19 .14 .09 .04 .02 .01
Example 3. The probability that there are j instances where an Ace is next
to a face card is given by (2) with n = 52, a = 4, and b = 12. Approximate
values are given in the following table.
j 0 1 2 3 4 5 6 7 8
pj .114 .296 .320 .189 .066 .014 .002 .000 .000
6
The Probability That a Queen Sits Beside a King 119
Exercises
3. Consider the 5!/(2!2!1!) five-letter “words” that can be formed using two
As, two Bs, and one C. For each i (the smaller of the number of A- and
B-runs) and for each pattern in the table of possibilities, list the five-letter
words that give each number j of AB and BA juxtapositions. Confirm that
p0 = 1/15, p1 = p2 = 2/5, and p3 = 2/15.
4. Three contagious people, four susceptible people, and five immune people
line up randomly. What is the probability that a contagious person stands
next to a susceptible person in the queue?
5. Six bar magnets and six bars of metal are inserted at random and pushed
together in a horizontal plastic pipe. Suppose that the orientation of three of
the bar magnets is N-S, and for the other three it is S-N. When like magnetic
poles are adjacent, the magnets will repel. For j = 0, . . . , 5, what is the
probability that there are j gaps?
4. Ordered Juxtapositions
The preceding analysis can be adapted to the case where we count juxta-
positions only if they occur in a particular order, A to the left of B, say. If we
replace i by i + 1 in the B + A+ B + · · · B + A+ row of the table of patterns, so that
the number of AB juxtapositions stipulated there is i (as it is in all the other
rows), then we find that the number of ways to arrange a As and b Bs so as to
get m = i AB juxtapositions is
µ ¶µ ¶ µ ¶µ ¶ µ ¶µ ¶ µ ¶µ ¶
a−1 b−1 a−1 b−1 b−1 a−1 b−1 a−1
+ + +
i−1 i−1 i i−1 i i−1 i i
µ ¶µ ¶
a b
= .
i i
The simpler answer points to an easier way to get this, which is left as an
exercise for the reader. Now the probability qj of getting j ABs is
min{a,b} µ
X ¶µ ¶µ ¶µ ¶
a b m n − m a!b!c!
qj = .
m=j
m m j a+b−j n!
7
120 Tools for Teaching 1998
Exercises
6. Give a combinatorial argument to explain why the the number of ways to
¡ ¢¡ ¢
arrange a As and b Bs so as to get exactly i AB juxtapositions is ai bi .
7. Suppose that 6 print jobs in a computer system are queued at random. Two
are long, two are of medium length, and two are short. What is the proba-
bility that no long job immediately precedes a short job?
F M N N F F M F M N M N M F M M F F M N N M F M N M F M N F.
µ ¶ µ ¶
2ab a+b 2ab a+b−µ µ(µ + c − 1)
σ = 2
1− + =µ 1− = ,
n n − 1 n(n − 1) n−1 n−1
where c = n − (a + b).
Thus, for example, when T is the number of Queen–King or King–Queen
juxtapositions, we have n = 52 and a = b = 4, so µ = 2 · 4 · 4/52 = 8/13,
8
The Probability That a Queen Sits Beside a King 121
and
³X X ´ XX
E(T 2 ) = E Xi Xj = E(Xi Xj ).
9
122 Tools for Teaching 1998
a b
j=i n−1 AB · +
n n−1
b a
BA ·
n n−1
a b a−1
j =i+1 2(n − 2) ABA · · +
n n−1 n−2
b a b−1
or j = i − 1 BAB · ·
n n−1 n−2
Adding every E(Xi Xj ) value multiplied by its number of terms and sim-
plifying, we get
µ ¶
¡ 2 ¢ 2ab 2ab − a − b
E T = 1+ .
n n−1
Then σ 2 = E(T 2 ) − (E(T ))2 reduces to the result claimed above, completing
the calculation.
Exercises
9. What is the expected number of club-diamond and diamond-club juxtapo-
sitions in a randomly shuffled deck? What is the variance?
10. In a randomly shuffled deck, how many runs of face cards and of nonface
cards will there be on average? What is the standard deviation?
11. Suppose that when the scores of college students on a test are arranged in
order (assume no ties) and the class of each student is noted (1 = freshman,
2 = sophomore, etc.), the following sequence of classes is observed:
3 2 3 111 4 1 44 2 4 2 44 22 11 3.
10
The Probability That a Queen Sits Beside a King 123
12. Let U denote the number of AB juxtapositions (in that order) in a random
permutation of a As, b Bs, and c Cs. Derive formulas for the mean and
variance of U .
13. The number of runs is used as a nonparametric statistic in tests of ran-
domness. The number of juxtapositions can be used instead. For example,
suppose that a row of 14 plants shows the following pattern of 7 healthy
(H) and 7 diseased (D) plants:
HHHDDDDHHHHDDD.
W M CCW CW CM CCW CM CW CM CM
6. Related Problems
The juxtaposition problems that we have considered represent just one kind
of problem connected with random permutations. Besides the run probabil-
ities considered here, there are many interesting problems in the distribution
theory of runs, including those involving runs of more than two kinds of ob-
jects; comprehensive accounts are given in David and Barton [1962] and the
classic article Mood [1940]. The former source also discusses matching and
derangement problems for (two) random permutations, and it gives extensive
calculations of moments via indicator random variables.
Takács [1981] also discusses the classical problem of ménages—finding the
probability that some husband and wife will be seated together if n couples are
11
124 Tools for Teaching 1998
randomly seated around a circular table with men and women alternating. Bar-
bour et al. [1992, Ch. 4] address various problems connected with random per-
mutations, including matching and ménage problems; they calculate moments
via indicator random variables, and they provide Poisson approximations to
various probability distributions.
But none of these sources gives the juxtaposition probabilities presented in
this Module.
Exercises
15. Derive formulas for the mean and variance of the number U of AB juxta-
positions.
16. Derive formulas for the mean and variance of the number T of AB and BA
juxtapositions.
19. Three Arabs, four Israelis, and six Swiss are seated randomly at a circular
table. What are the mean and variance of the number of Arab–Israeli jux-
tapositions? What is the probability that no Arab and no Israeli are side by
side?
20. Repeat Examples 1–4 for circular permutations.
12
The Probability That a Queen Sits Beside a King 125
8. Solutions
1. KQKQKQKQ KQKQKQQK KQKQQKQK KQQKQKQK
QKKQKQKQ QKKQKQQK QKKQQKQK QQKKQKQK
QKQKKQKQ QKQKKQQK QKQQKKQK QQKQKKQK
QKQKQKKQ QKQKQQKK QKQQKQKK QQKQKQKK
2.
m Qs Ks K–Q # ways to insert A to get
to follow to precede sequence j=0 j=1 j=2
m=0 QQ KK KKQQ 5 0 0
m=1 Q|Q |KK QKKQ 1 4 0
m=1 Q|Q K|K KQKQ 1 4 0
m=1 QQ| |KK QQKK 1 4 0
m=1 QQ| K|K KQQK 1 4 0
m=2 Q|K| |K|K QKQK 0 2 3
3.
i=1 AABB j = 0: AACBB.
j = 1: AABBC, AABCB, ACABB, CAABB.
i=1 ABBA j = 1: ABBCA, ACBBA.
j = 2: ABBAC, ABCBA, CABBA.
i=1 BAAB j = 2: BAACB, BCAAB.
j = 2: BAABC, BACAB, CBAAB.
i=1 BBAA j = 0: BBCAA.
j = 1: BBAAC, BBACA, BCBAA, CBBAA.
i=2 ABAB j = 2: ABACB, ABCAB, ACBAB.
j = 3: ABABC, CABAC.
i=2 BABA j = 2: BABCA, BACBA, BCABA.
j = 3: BABAC, CBABA.
4. Let type A be contagious; B, susceptible; and C, immune; then a = 3, b =
4, c = 5, and n = 12. We want to calculate 1 − p0 . By the formula given,
· µ ¶ µ ¶ µ ¶ µ ¶ µ ¶¸
11 10 9 8 7 3!4!5! 59
p0 = 2 · +5· + 12 · +9· +6· = ,
7 7 7 7 7 12! 924
so 1 − p0 ≈ 94%.
13
126 Tools for Teaching 1998
5.
j 0 1 2 3 4 5
61 101 223 27 23 1
pj
440 264 660 220 1320 1320
14
The Probability That a Queen Sits Beside a King 127
a b
j=i n−1 AB ·
n n−1
j − i = ±1 2(n − 2) impossible 0
a b a−1 b−1
|j − i| ≥ 2 (n − 2)(n − 3) AB, AB · · ·
n n−1 n−2 n−3
1 ≤ i, j ≤ n − 1 (n − 1)2
Therefore,
a b a b a−1 b−1
E(U 2 ) = (n − 1) · + (n − 2)(n − 3) · · · ,
n n−1 n n−1 n−2 n−3
2 µ(µ + c)
whence, by algebra, σU = .
n−1
13. a) Mean = 7; standard deviation ≈ 1.80. The observed number of juxta-
positions (3) is more than two standard deviations away from the mean.
b) p0 + p1 + p2 + p3 ≈ .02506. Here p0 = 0.
c) p11 + p12 + p13 + p14 ≈ .02506. Here p14 = 0.
d) Consequently the P -value is about 0.051.
15.
ab 2 µU (µU + c − 1)
µU = E(U ) = , σU = .
n−1 n−2
16.
2ab µT (µT + c − 2)
µT = E(T ) = , σT2 = .
n−1 n−2
15
128 Tools for Teaching 1998
b a
q ∗ (j; a, b, c) = q(j − 1; a − 1, b − 1, c)
nn−1
b a
+ q(j; a, b, c) − q(j; a − 1, b − 1, c).
nn−1
18. Adapt the procedure used to find pj . Count carefully: It is easy to go astray!
For each i between 1 and min{a, b}, count the linear arrangements of a As
and b Bs yielding i circular runs of each type. There are four pattern cases
(A+ B + · · · A+ B + , etc.), and the number of circular runs, which equals the
number of juxtapositions, must be even (2i). For each arrangement, count
the ways of choosing j AB and BA contacts to keep (which sometimes
involves the “wraparound” case), place a C in the other AB and BA gaps
(sometimes a left or right end), and then, regarding these other gaps and the
gaps among the As and Bs as urns, count the ways to place the remaining
Cs in these urns. Sum over i and multiply by a!b!c!/n!, where n = a + b + c,
to get the desired probability, p∗j .
Consider, for example, the A+ B + · · · A+ B + pattern with i A+ s and i
¡ ¢¡b−1¢
B + s. With a As and b Bs, this can be arranged in a−1 i−1 i−1 ways. If the
wraparound
¡2i−1¢ contact is maintained, then there are j − 1 interior contacts to
keep— j−1 choices—and 2i − 1 − (j − 1) contacts to break up with one
C each. The remaining r = ¢c − (2i − j) Cs can then be distributed into
¡r+u−1
u = a + b − j urns in u−1 ways. If the wraparound contact is broken
up, then choose the
¡2i−1 ¢ j contacts to be maintained from the 2i − 1 interior
possibilities— j ways—and place a C in each of the other 2i − 1 − j
interior gaps. At least one of the remaining Cs must go at one end, so first
count the ways to put r = c − (2i − 1 − j) balls into u1 = a + b + 1 − j urns
(this includes both ends), and then subtract the number of ways to put the
r balls into the u2 = a + b − 1 − j non-end urns. The total for the two cases
is given by Yij below.
After the remaining three patterns are tallied, the result is:
min{a,b} · µ ¶µ ¶
X a−1 b−1
p∗j = 2 Yij
i=1
i−1 i−1
½µ ¶µ ¶ µ ¶µ ¶¾ ¸
a−1 b−1 a−1 b−1 a!b!c!
+ + Zij ,
i i−1 i−1 i n!
16
The Probability That a Queen Sits Beside a King 129
where
µ ¶µ ¶ µ ¶ ·µ ¶ µ ¶¸
2i − 1 n − 2i − 1 2i − 1 n − 2i + 1 n − 2i − 1
Yij = + −
j−1 a+b−j−1 j a+b−j a+b−j−2
and
µ ¶µ ¶
2i n − 2i
Zij = .
j a+b−j
j 0 1 2 3 4 5 6 7
p∗j .5065 .3752 .1037 .0137 .0009 3 × 10−5 4 × 10−7 2 × 10−9
(2)
j 2 3 4 5 6 7 8 9 10 11
p∗j .01 .04 .09 .15 .19 .19 .15 .10 .05 .02
(3)
j 0 1 2 3 4 5 6 7 8
p∗j .092 .267 .322 .212 .083 .120 .003 .000 .000
(4)
j 0 1 2 3
qj∗ 5/21 ≈ .2381 15/28 ≈ .5357 3/14 ≈ .2143 1/84 ≈ .0119
References
Barbour, A.D., Lars Holst, and Svante Janson. 1992. Poisson Approximation.
New York, NY: Oxford University Press.
Barton, D.E., and F.N. David. 1957. Multiple runs. Biometrika 44: 168–178, 534.
Beyer, ed. 1968. Handbook of Tables for Probability and Statistics, 2nd ed. Boca
Raton, FL: Chemical Rubber Company.
David, F.N., and D.E. Barton. 1962. Combinatorial Chance. London, England:
Charles Griffin.
Freund, John E. 1992. Mathematical Statistics. 5th ed. Englewood Cliffs, NJ:
Prentice-Hall.
17
130 Tools for Teaching 1998
Hogg, Robert V., and Allen T. Craig. 1995. Introduction to Mathematical Statistics.
5th ed. Upper Saddle River, NJ: Prentice Hall.
Hogg, Robert V., and Elliot A. Tanis. 1993. Probability and Statistical Inference
4th ed. New York, NY: Macmillan.
Holte, John, and Mark Holte. 1993. The probability of n Ace-King adjacencies
in a shuffled deck. Mathematical Gazette 77: 368–370.
Mood, A.M. 1940. The distribution theory of runs. Annals of Mathematical
Statistics 11: 367–392.
Ross, Sheldon. 1994. A First Course in Probability. 4th ed. New York: Macmillan.
Singmaster, David. 1991. The probability of finding an adjacent pair in a deck.
Mathematical Gazette 75: 293–299.
Suman, Kenneth A. 1993. A problem in arrangements with adjacency restric-
tions. Mathematical Gazette 77: 366–367.
Swed, Frieda S., and C. Eisenhart. 1943. Tables for testing randomness of
grouping in a sequence of alternatives. Annals of Mathematical Statistics 14:
66–87.
Takács, L. 1981. On the “problème des ménages.” Discrete Mathematics 36: 289–
297.
Whitworth, William Allen. 1886. Choice and Chance. 5th ed., reprinted. New
York: Hafner, 1959.
18