Sub topic 8
Restrictions: Together, Never Together and Fixed Positions
This chapter assumes you know the multiplication principle, factorials, and nPr as the count of ordered selections. Restriction problems ask you to arrange objects while obeying a rule about who sits next to whom or where someone sits. Almost every one reduces to three moves: glue objects into a block, subtract the bad cases, or place the restricted objects first.
Items that must be together
Treat the items that must stay adjacent as one block. Arrange the block with the other objects, then arrange the items inside the block.
Example. Six people A, B, C, D, E, F stand in a row. A and B must be adjacent.
- Glue A and B into one block. You now have 5 objects (the block, C, D, E, F), which can be arranged in 5! = 120 ways.
- Inside the block, A and B can swap, which gives 2! = 2 ways.
- Total: 5! × 2! = 240.
The general rule: if k specified items are together among n distinct objects, the count is (n − k + 1)! × k!.
Repeated letters. If the glued items include identical objects, divide at the end. Take the letters of LETTER (L, E, E, T, T, R) with the two E's together. The block EE is one object, so you arrange L, EE, T, T, R. That gives 5!/2! = 60. The inside of the block contributes nothing extra, because the two E's are identical.
Items that must never be together
There are two reliable methods. Use the first when the restriction involves one pair. Use the second when several items must be kept apart.
Method 1: complement. Never together = total − together. For the six people above:
6! − 5! × 2! = 720 − 240 = 480
Method 2: gap method.
- Arrange the unrestricted objects first.
- This creates gaps: one before, one after, and one between each neighbouring pair. With m objects there are m + 1 gaps.
- Choose gaps for the restricted objects. Each gap holds at most one of them.
For the six people, arrange C, D, E, F in 4! = 24 ways. That leaves 5 gaps. A and B go into two different gaps, in order, which is 5P2 = 20 ways. Total: 24 × 20 = 480. This matches the complement method.
Check the repeated-letter case too. LETTER with the E's apart: arrange L, T, T, R in 4!/2! = 12 ways. Choose 2 of the 5 gaps for the identical E's in C(5, 2) = 10 ways. Total: 120. The complement agrees: 6!/(2! × 2!) − 60 = 180 − 60 = 120.
Fixed positions
When an object is forced into a position, place it first and count the arrangements of everyone else.
- Seven people in a row, A must be first and B must be last: A and B are fixed, so 5! = 120.
- A must be at either end: 2 choices of end, then 6! for the rest, so 2 × 720 = 1440.
- A must not be at either end: total − restricted = 7! − 1440 = 3600. Directly, A has 5 interior seats and the others fill the rest in 6! ways: 5 × 720 = 3600.
Restricted sets of positions. Suppose three vowels of TRIANGLE must occupy odd positions. There are 4 odd positions (1, 3, 5, 7). Place the vowels first in 4P3 = 24 ways. The 5 consonants fill the remaining 5 positions in 5! = 120 ways. Total: 24 × 120 = 2880.
Order conditions. If A must come before B and nothing else is restricted, exactly half of all arrangements qualify, by symmetry. For 7 people this is 7!/2 = 2520. The same trick works for any fixed order of k items: divide by k!.
Alternating and mixed patterns
Place the larger or more constrained group first, then the others in the gaps it creates.
- 4 men and 4 women alternate in a row. The row can start with a man or a woman: 2 × 4! × 4! = 1152.
- 5 men and 4 women alternate in a row. The men must take positions 1, 3, 5, 7, 9, so there is only one pattern: 5! × 4! = 2880.
- 5 boys and 3 girls, with no two girls together. Arrange the boys in 5! = 120 ways, which creates 6 gaps. Place the girls in 6P3 = 120 ways. Total: 14400.
Summary of patterns
| Condition | Method | Count for n distinct objects |
|---|---|---|
| k specified items together | Glue into a block | (n − k + 1)! × k! |
| Two specified items not together | Complement | n! − (n − 1)! × 2! |
| Several items pairwise apart | Gap method | (n − k)! × (n − k + 1)Pk |
| Two items fixed at two positions | Fix first | (n − 2)! |
| Item A before item B | Symmetry | n!/2 |
Verifying with code
Brute force is a fast way to check a formula on a small case. This script enumerates all 720 arrangements of six people.
from itertools import permutations
from math import factorial, perm
people = "ABCDEF"
arrangements = list(permutations(people))
together = sum(1 for p in arrangements if abs(p.index("A") - p.index("B")) == 1)
apart = len(arrangements) - together
a_before_b = sum(1 for p in arrangements if p.index("A") < p.index("B"))
print(together, factorial(5) * factorial(2)) # 240 240
print(apart, factorial(4) * perm(5, 2)) # 480 480
print(a_before_b, factorial(6) // 2) # 360 360Both columns match, so the glue, gap and symmetry formulas agree with direct enumeration.
Common errors
- Forgetting the internal arrangement of a block. Multiply by k! unless the items are identical.
- Counting gaps wrongly. m arranged objects give m + 1 gaps, not m − 1.
- Using the gap method with a restricted group that is also unevenly constrained. Place the most constrained group first.
- Subtracting the wrong total. When the objects include repeats, both the total and the "together" count must use the repeated-letter division.
- Mixing "at the ends" and "at the corners". In a row there are 2 end positions. Corners belong to circular or grid problems.
Exercise
Five boys and three girls stand in a row. (a) In how many ways can all three girls stand together? (b) In how many ways can no two girls stand together?
Show answer
(a) Glue the girls into one block. There are 6 objects (5 boys and the block), giving 6! = 720 arrangements. The girls can order themselves in 3! = 6 ways. Total: 720 × 6 = 4320. (b) Arrange the boys in 5! = 120 ways, which creates 6 gaps. Place the three girls in different gaps in 6P3 = 120 ways. Total: 120 × 120 = 14400.
Exercise
How many arrangements of the letters of the word LEADER (L, E, A, D, E, R) have the two E's apart?
Show answer
Total arrangements are 6!/2! = 360. With the E's together, the block EE and the other four letters give 5! = 120. So the E's are apart in 360 − 120 = 240 ways. Check with gaps: arrange L, A, D, R in 4! = 24 ways, then choose 2 of the 5 gaps for the identical E's in C(5, 2) = 10 ways, giving 240.