MethodMath
SR
Apr 27, 2026

How to count the number of ways to arrange books on a shelf with restrictions?

I'm studying combinatorics and I'm stuck on a problem involving permutations with restrictions.

Problem: \"How many ways can 5 distinct mathematics books and 3 distinct physics books be arranged on a shelf if all books of the same subject must be together?\"

I know the answer involves 5!\imes3!\imes2!5! \imes 3! \imes 2!, but I want to understand why. Also, what if the restriction changes to \"mathematics books must be together\" but physics books can be anywhere? How does the counting change?

1 answers294 views
Loading comments...

1 Answer

DN
Dr. Nour HassanApr 28, 2026 Accepted
Let me break down both scenarios. **Scenario 1: All books of the same subject must be together.** Think of each subject group as a single \"block\". We have 2 blocks: [Math block] and [Physics block]. Step 1: Arrange the 2 blocks on the shelf: $2! = 2$ ways (either Maths then Physics, or Physics then Maths). Step 2: Within the Maths block, arrange the 5 distinct books: $5! = 120$ ways. Step 3: Within the Physics block, arrange the 3 distinct books: $3! = 6$ ways. By the multiplication principle: $$2! \ imes 5! \ imes 3! = 2 \ imes 120 \ imes 6 = 1440$$ **Scenario 2: Only mathematics books must be together, physics books unrestricted.** Treat the 5 mathematics books as a single block. Then we have $1$ block + $3$ individual physics books = $4$ items to arrange. Step 1: Arrange these $4$ items: $4! = 24$ ways. Step 2: Within the mathematics block, arrange the 5 books: $5! = 120$ ways. Total: $$4! \ imes 5! = 24 \ imes 120 = 2880$$ The physics books are already distinct and their internal arrangement is accounted for by treating them as separate items in step 1. **General Principle:** When items must be together, treat them as a block and multiply by the internal arrangements. When items must be apart, use the **gap method**: arrange the unrestricted items first, then place the restricted items in the gaps between them.
Loading comments...
Login or Register to post an answer