# Problem about eight different books randomly put on shelf.

The problem sounds like this (My translation from Russian):

Eight different books were put on a shelf in random order. Calculate probability that two specific books were put near each other.

My answer: Let's divide the space on the shelf into eight slots. Let's also name our two books, "A" and "B" respectively. We have two sets of combinations - in the first set of combinations we have AB (i.e. A goes first). For example, A is put into the first slot and B is put into the second slot. Next example, A is put into the second slot and B is put into the third slot. And so on. There are 7 such AB combinations in total. By the same logic there are also 7 BA combinations. Obviously there is no overlap between said combinations, thus we can sum them up and get 14 combinations in total where books A and B are put side by side.

As for number of total combinations of books on the bookshelf, it's equal to "n!", where n is equal to 8. Why? Because in order to calculate combinations when repetitions are forbidden and order is important we use this formula:

n means total number of items and r means number of selected items. But because in our case n=r we get (n-r)!=0!=1. Consequently, the formula is turned into "n!".

This all means that the probability of A and B being beside each other is 14/8!

What my textbook says: My textbook has different opinion. Namely, for some strange reasons it thinks that the probability is (7*2!*6!)/8!

UPDATE:

I understand my mistake now. I forgot that while A and B can stand still in their slots we can get additional combinations by making other books to change their slots. Thus each case with positions of A and B is in fact set of combinations. How many combinations in each set? It's "6!", because we decreased number of total and selected books by ignoring books A and B. We multipy it by 14 and get 6!*14=6!*2*7=6!*2!*7

Now I'm with agreement with my textbook.

• In your answer, then where are the other 6 books? They also should be put in the shelf. – J1U Oct 1 '18 at 15:46
• @J1U Of course they are. I just didn't mention it explicitly. Like when I said that A is in the first slot and B is in the second slot I assumed that other books occupy the remaining slots ... OH WAIT, I forgot that we have different combinations even when A and B occupy the same slots by virtue of other books changing their slots. In other words, ABCDEFGH and ABDCFEHG are two different combinations. – user161005 Oct 1 '18 at 16:02
• That's the point. – J1U Oct 1 '18 at 16:03

For the two specific books, keep one. The remaining 7 books have $$7!$$ possible orderings. So to be next to the other specific book, the one kept behind has 2 positions (left and right). This odds against all $$8!$$ orderings of all of the books.
$$\frac{2 \times 7!}{8!} = \frac1{4}$$
The number of options to put the books on the shelf in any order is $$8!$$, that is correct. Now, what is the number of options to put the books in an order such that $$A$$ and $$B$$ are next to each other? This is the way it should be done: think about $$A$$ and $$B$$ as about one book. It makes sense because you anyway need them to be next to each other. Now you need to put just $$7$$ "books" on the shelf-$$6$$ books which are not $$A$$ and $$B$$ and that "$$AB$$ book". So the number of ways to order them is $$7!$$. But then you also need to choose which of the books $$A$$ and $$B$$ will be on the left side and which will be on the right side, that is two options. So in general the number of ways to order the books where $$A$$ and $$B$$ are next to each other is $$7!\times 2$$, or as it appears in your textbook $$7\times 2!\times 6!$$. So the probability is really $$\frac{7!\times 2}{8!}$$.