# Probability $A$ is before $B$ when the 26 letters are arranged randomly

The 26 letters A, B, ... , Z are arrange in a random order. [Equivalently, the letters are selected sequentially at random without replacement.]

a) What is the probability that A comes before B in the random order?

b) What is the probability that A comes before Z in the random order?

c) What is the probability that A comes just before B in the random order?

Any help would be much appreciated. I was thinking that for part c the answer would be $$1/26$$ because we have $$25!$$ ways of having A right before B and $$26!$$ total arrangements. Not sure how to proceed with a and b, however.

Edit:

Thank you. For parts (a) and (b) is there a more formal way of getting $$1/2$$? Such as the formula for the total number of ways we can have $$A$$ before $$B$$ over the total number of arrangements? Would it be 25 choose 1 ... 2 choose 1 over $$26!$$ since we can have a in the first spot and B in any spot after it? Then we can have a in the 2nd spot and B in any spot after it. Also, for part (c), doesn't $$A$$ have to come immediately before $$B$$, so wouldn't the probability be $$1/26$$?

• a) 1/2 b) 1/2 . Only 2 possibilities A before or after B – mridul Dec 8 '14 at 6:43
• MAy someone shed some light on the correct answer in part c? Thanks! – user198454 Dec 8 '14 at 16:54
• Is c asking if A come right before B or that A comes right before B but not Z? – Kamster Dec 29 '14 at 5:24
• The reasoning for part (a) in chandu1729's excellent answer is quite formal actually. Let me know if you need an explanation of how to make that formal. – 6005 Dec 30 '14 at 7:02
• Yeah! Just a bounty — and here we are, a bunch of totally equal answers. – sas Dec 30 '14 at 8:15

a) From symmetry, the probability that $A$ comes before $B$ is same as the probability that $B$ comes before $A$, and the sum of these $2$ probabilities is $1$. Hence, the probability that $A$ comes before $B$ is $0.5$.

b) Here $B$ is replaced with $Z$ and by exchanging the roles of $B$ and $Z$, we get the same probability as in case (a): $0.5$.

c) If $A$ has to come just before $B$, $B$ shouldn't occur at the $1$st position, which has probability of $25/26$. After $B$'s position has been chosen(other than the $1$st position), there are 25 possibilities for position just before $B$ (everything except $B$) and only $1$ possibility is favourable (A coming before B). Hence the required probability is $(25/26)\cdot(1/25) = 1/26$.

In part c), $A$ comes right before $B.$ Consider a block $\boxed{\text{AB}}$ and treat it as ONE object. The other letters are $C, D, E, \ldots , Z$. In total, you have 25 objects - 24 letters and a block of two letters together. They can be arranged in $25!$ ways in total. Since the total number of arrangements is $26!$, the required probability is $$\dfrac{25!}{26!}=\dfrac1{26}$$

Now, let us consider part a). We'll formally prove the probability is $\dfrac12$

For this, we will consider 26 cases.

Case 1 = B is in the first position.

Clearly, if $B$ is in the first position, then in no possible arrangement, A comes before B. Thus, the number of way A comes before B is $0$ for the first case.

Case 2 = B is in the second position.

For A to come before B, it has to occupy the first spot. A can occupy the first spot in $1$ way. The rest 24 letters can be arranged in $24!$ ways. The number of ways A comes before B can happen is $1.24!$

Case 3 = B is in the third position.

For A to come before B, A can occupy the first two positions. The number of ways A can take the first two position is $2.$ The rest 24 letter can be again arranged in $24!$ ways. Hence, the number of ways A comes before B happens is $2.24!$

Case 4 = B is in the fourth position.

Now, by same logic as before, you can say it will happen in $3.24!$ ways.

Similarly, we go up to Case 26 where B comes in the $26^{th}$ i.e, last position.

These $26$ cases exhausts all the possible arrangements. By considering all the $26$ cases and summing up the total number of ways A comes before B can happen, we get

$$0+1.24!+2.24!+\cdots 25.24! = 24!(1+2+\cdots 25)=24!*\dfrac{25.26}{2}=\dfrac{26!}{2}$$

Since the total number of arrangements is $26!$, the probability for A comes before B in a random order is $$\dfrac{26!/2}{26!}=\dfrac{1}{2}$$

• Right answer but...way too many words for part (a) :P – 6005 Dec 30 '14 at 7:01
• Thanks. Right, it bothered me too! I could've provided the same thing in a pictorial proof, which would have been way easier to comprehend, but IDK much of Geogebra. :/ – Dipanjan Pal Dec 30 '14 at 8:17

Here's a proof that the probability in part (a) is 1/2. It's the same as the one in The Math Troll's and chandu1729's answers, but with more details filled in. I want to emphasize that it really is a proof, as rigorous as anything you're likely to encounter in an introductory probability course, even though it doesn't use any formulas or complicated calculations.

Let's say two arrangements are partners if exchanging the positions of A and B turns one into the other. Here are some examples of arrangements which are partners:

ABCDEFGHIJKLMNOPQRSTUVWXYZ and BACDEFGHIJKLMNOPQRSTUVWXYZ AEIOUYBCDFGHJKLMNPQRSTVWXZ and BEIOUYACDFGHJKLMNPQRSTVWXZ THEQUICKBROWNFXJMPSVLAZYDG and THEQUICKAROWNFXJMPSVLBZYDG

You should be able to convince yourself that:

• Every arrangement has exactly one partner.
• If an arrangement has A before B, its partner has B before A, and vice versa.

Now, line up all the arrangements in two lines, with each arrangement standing next to its partner. The lines with be the same length, because each arrangement has exactly one partner.

In each pair of partners, tell the arrangement with A before B to stand on the left, and the arrangement with B before A to stand on the right. Now, the left line has all the arrangements with A before B, and the right line has all the arrangements with B before A. Since the lines are the same length, it's now obvious that the numbers of A-before-B arrangements and B-before-A arrangements are equal!

That means exactly half the arrangements have A before B, and exactly half have B before A. Therefore, if you pick an arrangement at random, the probability of getting A before B is 1/2.

You can use exactly the same argument for part (b).

The simplest way to answer these questions:

a) What is the probability that A comes before B in the random order?

In half of the cases A comes before B and in the other half B comes before A, so the answer is $\frac12$

b) What is the probability that A comes before Z in the random order?

In half of the cases A comes before Z and in the other half Z comes before A, so the answer is $\frac12$

c) What is the probability that A comes just before B in the random order?

• The total number of permutations is $26!$

• Join the letters A and B into a symbol AB, and the total number of permutations is $25!$

• Hence the answer is $\frac{25!}{26!}=\frac{1}{26}$

A more "formal" way to answer to the first (as well as the second) question:

• The probability that A is at the 1st place and B is at the 2nd to 26th places is $\frac{1}{26}\cdot\frac{25}{25}=\frac{25}{26\cdot25}$

• The probability that A is at the 2nd place and B is at the 3rd to 26th places is $\frac{1}{26}\cdot\frac{24}{25}=\frac{24}{26\cdot25}$

• The probability that A is at the 3rd place and B is at the 4th to 26th places is $\frac{1}{26}\cdot\frac{23}{25}=\frac{23}{26\cdot25}$

• $\dots$

• The probability that A is at the 25th place and B is at the 26th place is $\frac{1}{26}\cdot\frac{1}{25}=\frac{1}{26\cdot25}$

• So the probability that A comes before B is $\sum\limits_{n=1}^{25}\frac{26-n}{26\cdot25}=\frac12$

a) By symmetry, there are as many permutations with $A$ before $B$ as with $A$ after $B$.

$$p=\frac12$$

b) By symmetry, there are as many permutations with $A$ before $Z$ as with $A$ after $Z$.

$$p=\frac12$$

c) Consider the $24!$ permutations of $CDE\dots Z$. You can insert $AB$ at $25$ different places to form all distinct configurations. $$p=\frac{25\cdot24!}{26!}=\frac1{26}$$

for parts a and b then the answer is $1/2$. One way to look at is is to note that for any arrangement of the letters, say "DEFGBAC", there is another arrangment the order of the letters reversed, in this case "CABGFED". It is clear that if $A$ comes before $B$ in the first, then it will come after the $B$ in the second, and vice versa. So we can take all the random arrangements and arrange them in to pairs in this manner. Since each arrangement with $A$ before $B$ is paired with another unique arrangment with $B$ before $A$, there must be the same number of strings with $A$ before $B$ and $B$ before $A$. So selecting one of the possible arrangements at random has a probability of $1/2$ of having the $A$ before the $B$.

For part c, There are 26 postions where the $A$ can go, and, since that position is filled, 25 positions when the $B$ can go. Now for 25 of the 26 positions where the $A$ can go, the position immediately following it is vacant. In this case there is a change of $1/25$ that the $B$ randomly falls into that position. So in $25/26$ of the cases (where $A$ is not in the last position), there is a chance of $1/25$ of the $B$ immediately following the $A$.

However, in 1/26 of the cases, the $A$ is in the last place, and the $B$ cannot follow the $A$, so the probability is $0$.

So from the first situation we have $25/26 \times 1/25 = 1/26$, and from the second $1/26\times0 = 0$

Adding up the two, $1/26 + 0 = 1/26$. So you appear to be correct that the probability is $1/26$.

For parts a and b, we can construct a bijection between A before B and B before A (proceed similarly for part b).

Suppose we have one that is A before B. Then we switch the A and B then we get a B before A. The other direction of the bijection will be similar.

Now for part c. If A is the last, then there is 0 chance. This happens 1/26 of the time. If A isn't the last, then there will be one immediately after it. There will be 25 possibilities (and they are random), so the chance is 1/25. This happens 25/26 of the time Hence 1/25*25/26+0=1/26.

• Your answer for part C is wrong! it is 1/52 – mridul Dec 8 '14 at 10:21
• Then what is the problebility that A and B together? 1/13? Please use good words. – mridul Dec 8 '14 at 10:24
• Note that there are 26*25 positions for A and B. For A to come before B, there are 25 positions. Thus the probability is 1/26. Please check your solution first. – user198454 Dec 8 '14 at 10:25

Total 26! rearrangements are possible. In 1st case A has only 2 relative possitions after or before B. Therefore probability is 1/2.

In 3rd case : Total possible arrangements such that A and B are together is 25!. Therefore Total possible arrangements such that A comes just before B is 25! / 2.

a) 1/2

b) 1/2

c) 1/52

Edit:

For parts (a) and (b),

Let A at 1st possition, total number of arrangements(A before B) is 25!.

Let A at 26th possition, total number of arrangements is 0. together we got 25!.

Then take 2nd and 25th possitions.

Let A at 2st possition, total number of arrangements(A before B) is 24*24!. (B has 24 possitions such that B after A)

Let A at 25st possition, total number of arrangements(A before B) is 1*24!. (B has only 1 possition such that B after A)

24*24! + 1*24! = 25*24! =25!

Then take 3rd and 24th possitions.

Let A at 3st possition, total number of arrangements(A before B) is 23*24!.

Let A at 24st possition, total number of arrangements(A before B) is 2*24!.

Together we got 25!.

etc .. upto 13th,14th possitions.

Add all together we got 13*25! arrangements.

• Thank you. For parts (a) and (b) is there a more formal way of getting $1/2$? Such as the formula for the total number of ways we can have $A$ before $B$ over the total number of arrangements $(26!)$? Also, for part (c), doesn't $A$ have to come immediately before $B$, so wouldn't the probability be $1/26$? – mylasthope Dec 8 '14 at 7:08
• In the case of part c answer is 1/52. For parts (a) and (b), let A at 1st possition, total number of arrangements(A before B) is 25!. let A at 26th possition, total number of arrangements is 0. together we got 25!. Then take 2nd and 25th possitions together we got 25!. etc. Add all together we got 13*25! arrangements. – mridul Dec 8 '14 at 7:43