In how many ways can 6 people sit around a round table? In how many of these do two particular friends sit together?
120 ways in total, since circular arrangements of n people number (n - 1)! = 5! = 120. With two friends together, treat them as one unit: (5 - 1)! x 2 = 24 x 2 = 48 ways.
Explain it simply
At a round table there is no first seat. Rotating everyone one place to the left gives the same seating, because each person still has the same neighbours. So fix one person's seat to remove the rotations, then arrange the others in a line: (n - 1)! ways.
Example
Question: 6 people at a round table. Total arrangements, and arrangements with friends P and Q together.
- Total = (6 - 1)! = 5! = 120.
- P and Q together: glue them into one unit. Now 5 units around a table: (5 - 1)! = 24.
- P and Q can swap within the unit: x 2.
- Together = 48.
- Not together = 120 - 48 = 72.
If the items are beads on a necklace that can be flipped over, clockwise and anticlockwise orders are the same, so divide by 2 again: (n - 1)!/2.
const f = n => (n <= 1 ? 1 : n * f(n - 1));
console.log(f(5)); // Output: 120
console.log(f(4) * 2); // Output: 48What to say in the interview
"Fixing one person removes the rotations, so 6 people give 5 factorial, 120. With two friends glued together there are 5 units, 4 factorial times 2, which is 48."
Common mistakes
- Using n! for a circle.
- Forgetting the factor of 2 for the friends swapping places.