# How many ways can $5$ books be arranged on a shelf if $2$ of the books must remain together?

How many ways can $$5$$ books be arranged on a shelf if $$2$$ of the books must remain together?

I have $$5$$ books $$A,B,C,D,E$$ and spots as $$\underline{A} \ \underline{B} \ \underline{C} \ \underline{D} \ \underline{E}$$

These can be arranged in $$5!$$ ways. So suppose that $$A,B$$ must remain together. Can I treat $$AB$$ as a single element and consider $$\underline{AB} \ \underline{C} \ \underline{D} \ \underline{E}$$ even though this has $$5$$ books but $$4$$ spots? These can be arranged as $$\underline{AB} \ \underline{C} \ \underline{D} \ \underline{E} \\ \underline{C} \ \underline{AB} \ \underline{D} \ \underline{E} \\ \vdots \\ \underline{C} \ \underline{D} \ \underline{E} \ \underline{AB}$$ so I have $$4$$ different arrangements that can be ordered in $$4!$$ ways so the total would be $$5! - 4\cdot(4!)= 24$$?

• It can either be $AB$ or $BA$ Nov 25 at 9:56
• Also $5! - 4 \cdot 4!$ is nothing but $4!$ as $AB$ together gives you $4$ books (one of them being a combined book) Nov 25 at 9:57
• If you treat AB as one item then you get $4!$ possibilities, but BA counts too so $2 \times 4!$ combined Nov 25 at 10:03