Not as easy as it looks!

There are 12 books in a shelf in a particular order. All books are unique. I decide to change their order such that no 2 books, adjacent earlier, are now adjacent.

For Example- Let the books be A,B,C,D.

A cannot come next to B, B cannot come next to A and C....and so on.

In how many ways can I arrange them?


The answer is 63779034.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Jon Haussmann
Mar 7, 2015

The idea is to use the Principle of Inclusion-Exclusion , but the solution is somewhat intricate. The best way to understand the solution is to look at a particular example.

More generally, let S S be the set of all permutations of the numbers 1, 2, \dots , n n , and for 1 i n 1 1 \le i \le n - 1 , let A i , i + 1 A_{i,i + 1} denote the subset of permutations where i i and i + 1 i + 1 are adjacent. We want to count the number of permutations where i i and i + 1 i + 1 are never adjacent, and by PIE, this number is S A 1 , 2 A 2 , 3 A n 1 , n + A 1 , 2 A 2 , 3 + A 1 , 2 A 3 , 4 + + A 1 , 2 A n 1 , n A 1 , 2 A 2 , 3 A 3 , 4 . \begin{aligned} &|S| - |A_{1,2}| - |A_{2,3}| - \dots - |A_{n - 1,n}| \\ &\quad + |A_{1,2} \cap A_{2,3}| + |A_{1,2} \cap A_{3,4}| + \dots + |A_{1,2} \cap A_{n - 1,n}| \\ &\quad - |A_{1,2} \cap A_{2,3} \cap A_{3,4}| - \dotsb. \end{aligned} So, we must understand what the intersections of these sets look like.

As an example, let n = 8 n = 8 . Consider the intersection A 1 , 2 A 2 , 3 A 3 , 4 A 5 , 6 A 6 , 7 . A_{1,2} \cap A_{2,3} \cap A_{3,4} \cap A_{5,6} \cap A_{6,7}. For a permutation in this intersection, 1 is next to 2, 2 is next to 3, 3 is next to 4, 5 is next to 6, and 6 is next to 7. Thus, the numbers 1, 2, 3, 4 form one chain, and the numbers 5, 6, 7 form another chain. So permutations in this intersection include ( 4 , 3 , 2 , 1 , 8 , 5 , 6 , 7 ) (4, 3, 2, 1, 8, 5, 6, 7) and ( 7 , 6 , 5 , 1 , 2 , 3 , 4 , 8 ) (7, 6, 5, 1, 2, 3, 4, 8) .

More generally, consider an intersection of k k of the sets A i , i + 1 A_{i,i + 1} . Just as we saw in the example above, there will be a number of chains in this intersection. Let t t be the number of such chains. (Note that this number t t is not uniquely determined by k k .) Then for the PIE calculation, for a fixed value of k k , instead of trying to compute the number of elements in each intersection, then summing over all possible intersections of k k sets, we will count the number of permutations with t t chains (that arise from the intersection of k k sets).

Let c 1 c_1 , c 2 c_2 , \dots , c t c_t be the number of elements in the first chain, second chain, and so on, up until the t t th chain. Then the first chain is determined by c 1 1 c_1 - 1 adjacent pairs, the second chain is determined by c 2 1 c_2 - 1 adjacent pairs, and so on. Hence, i = 1 t ( c i 1 ) = i = 1 t c i t = k , \sum_{i = 1}^t (c_i - 1) = \sum_{i = 1}^t c_i - t = k, so i = 1 t c i = t + k . \sum_{i = 1}^t c_i = t + k. This says there are t + k t + k elements among all t t chains, so there are n t k n - t - k elements that are not included in any chains. Let's call these "single elements".

To construct a permutation with t t chains, we start by writing the numbers 1, 2, \dots , n n in a row, and deciding which numbers go in chains, and which numbers become single elements. First, we decide the number of elements in each chain. We use the equation i = 1 t ( c i 1 ) = k . \sum_{i = 1}^t (c_i - 1) = k. Each value c i 1 c_i - 1 is a positive integer. Then by stars and bars, the number of solutions to the equation above is ( k 1 t 1 ) \dbinom{k - 1}{t - 1} .

When we write out the numbers 1, 2, \dots , n n , they will form t t chains and n t k n - t - k single elements, in some order. There are ( n k t ) \dbinom{n - k}{t} ways to order them. We then let c 1 c_1 be the number of elements in the first chain, c 2 c_2 the number of elements in the second chain, and so on. Every number from 1 to n n has now been assigned as part of a chain or a single element.

There are now ( n k ) ! (n - k)! ways to order the t t chains and n t k n - t - k single elements. Finally, for each chain, we can order it forwards or backwards, so there are 2 t 2^t different ways to order the elements in the t t chains. Putting everything together, we get that the number of permutations we seek is n ! + k = 1 n ( 1 ) k t = 1 n ( k 1 t 1 ) ( n k t ) 2 t ( n k ) ! . n! + \sum_{k = 1}^n (-1)^k \sum_{t = 1}^n \binom{k - 1}{t - 1} \binom{n - k}{t} 2^t (n - k)!.

Excellent solution

Ujjwal Mani Tripathi - 6 years, 3 months ago

Why cant we use derangement technique....please explain

manish bhargao - 6 years, 3 months ago

Log in to reply

How do you plan on using Derangements ? Maybe then I'll be able to help you out

A Former Brilliant Member - 6 years, 3 months ago

As expected from the Annihilator ! Just when I think that no one's able to provide a solution , a great mind comes forward :D

A Former Brilliant Member - 6 years, 3 months ago

The recursion that I have used is

[a 0 = a 1 = 1, a 2 = a 3 = 0), and a n = ( n + 1 ) a n 1 ( n 2 ) a n 2 ( n 5 ) a n 3 + ( n 3 ) a n 4 a_n = (n+1)a_{n-1} - (n-2)a_{n-2} - (n-5)a_{n-3} + (n-3)a_{n-4} for all (n \geq 4]

If you guys want to check the OEIS listing , try here

Very nice recursion technique

Ujjwal Mani Tripathi - 6 years, 3 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...