How many different ways are there to order the letters A,B,C,D,E,G,H in a line in such a way the letter B be always between A and D?

For examples $A,C,\textbf{B},E,G,H,D$ or $D,\textbf{B},C,A,G,H,E$ and so on.

Thanks in advance for your comments.

  • 2
    $\begingroup$ The six relative positions of the three letters should be equally likely, don't you think? (and, what happened to $F$?) $\endgroup$ Sep 2, 2020 at 6:32
  • $\begingroup$ Please edit your question to show what you have attempted and explain where you are stuck. $\endgroup$ Sep 2, 2020 at 10:16

3 Answers 3


This Can be Visualized as follows :

The total number of Permutations of seven letters would be $\ \ \displaystyle 7! .$

Hence now we group 3 elements (A, B, D) together, now we know that permutations of the group is $\ \ \displaystyle 3! . \ \ $ But only two ways are correct (namely ABD, DBA).

Thus to get correct sequence of A,B,D : $\ \ \displaystyle \frac {7!}{3!} \cdot 2 = 1680 .$

  • $\begingroup$ Yes, Thank you for pointing it out. $\endgroup$ Sep 2, 2020 at 13:48

EDIT: I originally had a stricter condition than what was asked by OP. I understood it so that B must be consecutively after A/D and before D/A in the draft, e.g GHABDCE is allowed, but GHAEBDC would not be. Following is a solution for both cases.

Letters do not necessarily have to be in consecutive order

The different relative orders of A, B and D is: ABD, ADB, BAD, BDA, DAB, DBA. From these 6 different orderings of {A,B,C} only 2 will fulfill the requirement of having B between A and D, i.e. ABD and DBA. One of these six orderings will occur in any permutation, and there is nothing special with any of the letters therefore any of the orders are equally likely to occur. This makes the total number of permitted permutations:

\begin{equation} \text{Permutations} = \frac{2}{6}\cdot7! = 1680 \end{equation}

Letters must be in consecutive order

The total different combinations that can occur by placing the letters out randomly is:

\begin{equation} \text{Permutations} = 7! = 5040. \end{equation}

Out of these 5,040 permutations we know that the B can not be placed in the 1st or last position; simply because then it won't have both A and D surrounding it.

We can find the probability that B is placed in any specific positions with A and D surrounding it as:

\begin{equation} \text{P(B in 2nd place)} = \text{P(A$\cup$D)$\cdot$P(B)$\cdot$P(D$\cup$A)} = \frac{2}{7}\frac{1}{6}\frac{1}{5} = 0.0095\\ \text{P(B in 3rd place)} = \text{P($\notin$ A,B,D)$\cdot$P(A$\cup$D)$\cdot$P(B)$\cdot$P(D$\cup$A)} = \frac{4}{7}\frac{2}{6}\frac{1}{5}\frac{1}{4} = 0.0095\\ \text{P(B in 4th place)} = \frac{4}{7}\frac{3}{6}\frac{2}{5}\frac{1}{4}\frac{1}{3} = 0.0095\\ \text{P(B in 5th place)} = \frac{4}{7}\frac{3}{6}\frac{2}{5}\frac{2}{4}\frac{1}{3}\frac{1}{2} = 0.0095\\ \text{P(B in 6th place)} = \frac{4}{7}\frac{3}{6}\frac{2}{5}\frac{1}{4}\frac{2}{3}\frac{1}{2}\frac{1}{1} = 0.0095 \end{equation}

Above we have the probability for the B in different positions with two specific letters surrounding it and we can see that the probability of it being in any of the allowed position with A and D around it is the same, 0.0095.

From this we can find the total number of permutations that allows for your condition as

\begin{equation} \text{Permutations with B surrounded by A and D} = \left(P(\text{B in 2nd place})+P(\text{B in 3rd place})+P(\text{B in 4th place})+P(\text{B in 5th place})+P(\text{B in 6th place})\right)\cdot\text{Permutations} \end{equation} which yields \begin{equation} \text{Permutations with B surrounded by A and D} = 0.0095\cdot5\cdot5040 = 240. \end{equation}

From this we see that there are 240 different permutations of the letters A, B, C, D, E, G, H where B will appear between A and D. This is in fact true for any specific letter surrounded by two other specific letters in a combination of 7 unique letters.

  • $\begingroup$ Your answer is incorrect. Since you have not explained the factors in your probabilities, I am not sure what you did. That said, take note of Gerry Myerson's comment above. $\endgroup$ Sep 2, 2020 at 11:55
  • $\begingroup$ Maybe I misunderstood the question. I understood it so that B must be consecutively after A/D and before D/A - reading the example again I see that may not necessarily be the case. $\endgroup$
    – Mape
    Sep 2, 2020 at 12:16
  • $\begingroup$ The fractions in the probability, e.g. $P(\text{B in 6th place}) = \frac{4}{7}\frac{3}{6}\frac{2}{5}\frac{1}{4}\frac{2}{3}\frac{1}{2}\frac{1}{1}\cdot2$ is the probability of getting $\notin$ {A,B,D} on the first 4 picks, then the 5th fraction is the probability of $\in${A,D}, 6th fraction is the probability of picking B and the last fraction is the probability of picking what was not picked in the 5th (here that's just 1 as it's the only letter remaining). $\endgroup$
    – Mape
    Sep 2, 2020 at 12:24
  • $\begingroup$ I think you misinterpreted the question. That said, there is an easier way to handle the problem if the letters A, B, and D must be consecutive. There are five objects to arrange (assuming the F is supposed to be missing): the other four letters and a box containing the letters A, B, and D. The five objects are distinct, so they can be arranged in $5!$ orders. Within the box, B must be placed in the middle. There are two ways to select whether A or D is to the left of B within the box. The other must be to the right of B within the box. Hence, there are $5!2!$ such arrangements. $\endgroup$ Sep 2, 2020 at 12:51
  • $\begingroup$ Thanks, that's a good way to view it. I'll leave this as it might be good for the interpretation between probability of an occurrence and the total number of permutations leading to the occurrence. $\endgroup$
    – Mape
    Sep 2, 2020 at 13:41

It's too easy to be solved. The 7 numbers may be divided into two parts - 4 letters are free and 3 letters(A,B,D) are to be used. So, number of ways of arranging the 7 numbers - 7!. But we want to restrict the 3 numbers so we would make it combination by dividing it by 3!. Now for each combination of A,B,D, we can only get two cases of arrangement - A,B,D and D,B,A. So we would multiply it by 2. Hence the answer is 7!/3. By calculation, it is 1680.

  • 2
    $\begingroup$ Seems good to me but the first line in your post is unnecessary $\endgroup$
    – Amadeus
    Sep 2, 2020 at 12:58

Not the answer you're looking for? Browse other questions tagged .