LATEST
JEEBy Pareeksha Editorial Team· ⏱ 16 min read

Distribution Problems and Derangements for JEE

Share𝕏fin
Alongside this guide

Find study material for your next topic

Browse the Reading Room and preview a chapter before choosing what to study.

Browse study material →
Distribution Problems and Derangements for JEE
On this page
  1. What this post covers
  2. The four switches
  3. Identical objects into distinct boxes: stars and bars
  4. Distinct objects into distinct boxes
  5. Dividing into groups
  6. Identical boxes
  7. Derangements
  8. Where the two halves meet
  9. Worked examples
  10. Common traps
  11. A one-page recap
  12. How to practise this chapter
  13. Frequently asked questions
  14. How do I know whether the boxes are identical or distinct?
  15. Why do I divide by $m!$ for equal groups but not for unequal ones?
  16. Is $D_n$ the same as $n!/e$?
  17. When do I use inclusion and exclusion instead of a direct count?
  18. What is the quickest way to count onto maps?
  19. How many fixed-point questions are asked in the exam?
  20. Can I use stars and bars when objects have limits and are distinct?

Questions that ask "in how many ways can these objects be distributed" are among the easiest in the counting chapter to get wrong, and not because the arithmetic is hard. The difficulty is that one sentence can describe five different problems, depending on whether the objects are identical or different, whether the boxes are identical or different, whether a box may stay empty, and whether the groups have names. Change one of those four switches and the answer changes completely. Derangements, the number of ways to scramble objects so that none returns to its own place, belong in the same family because they are solved by the same engine, inclusion and exclusion.

The chapter guide on permutations and combinations introduces stars and bars, grouping and derangements in a few paragraphs. This post takes the whole area slowly: a four-switch classification, every standard formula with the reason behind it, the partial-derangement results that JEE likes, and twelve worked examples that were each checked by enumeration in Python before they were written down. Its sibling, permutations with restrictions and circular arrangements, deals with the arrangement half of the chapter, and the two together cover most of what the exam asks beyond the basic formulas.

What this post covers

Topic Typical question
Identical objects, distinct boxes Non-negative or positive integer solutions of $x_1+\dots+x_k=n$
Bounds on the variables Each box at most $m$; minimum in some boxes
Distinct objects, distinct boxes $r^n$; onto maps; given box sizes
Dividing into groups Unlabelled groups of equal or unequal sizes
Identical boxes Partitions of a number; Stirling numbers
Derangements No letter in its own envelope; exactly $r$ fixed points

This is inside the JEE Main syllabus under permutations and combinations. We state no official weightage; in our own mocks the whole chapter gets about one question in the Mathematics section.

The four switches

Before using any formula, answer four questions in writing.

  1. Are the objects identical or distinct?
  2. Are the boxes (people, groups) identical or distinct?
  3. May a box be empty?
  4. Is there a limit on how many a box may hold?

Distinct boxes in practice means the boxes have names: three children, three rooms, three people $x$, $y$, $z$. Identical boxes means you cannot tell them apart: three unlabelled piles, three teams that will be given no names. Almost every distribution question reduces to a table lookup once the four answers are written down.

Also read: Binomial Distribution and Random Variables for JEE

Identical objects into distinct boxes: stars and bars

Place $n$ identical objects into $k$ distinct boxes, empty boxes allowed. Write the objects as stars and use $k-1$ bars to separate the boxes. Every arrangement of $n$ stars and $k-1$ bars is a distribution, so

$$\text{count}=\binom{n+k-1}{k-1}=\binom{n+k-1}{n}$$

This is the number of non-negative integer solutions of $x_1+x_2+\dots+x_k=n$.

Minimum in every box. If every box needs at least one object, first give one to each box. What remains, $n-k$ objects, goes into the boxes freely: $\binom{n-1}{k-1}$. If box $i$ needs at least $m_i$ objects, subtract $m_1+\dots+m_k$ from $n$ first and then use the free formula.

Upper bounds. If a box may hold at most $m$ objects, count without the bound and subtract the cases that break it. For a single bounded variable $x\le m$ in $x+y+z=n$, subtract the solutions with $x\ge m+1$, which are $\binom{n-(m+1)+2}{2}$. For several bounded variables, use inclusion and exclusion over the set of boxes that overflow: total, minus one overflow, plus two overflows, and so on.

A positive-integer version with an order. The number of solutions of $x+y+z=n$ in positive integers with $x\le y\le z$ is the number of partitions of $n$ into exactly three parts. It cannot be found by stars and bars; list the partitions. For $n=10$ the answer is $8$.

Distribution of identical objects among people with a different amount each. If everyone must get a different number, you are counting integer solutions with distinct entries; a short list, not a formula, is usually the fastest route.

Distinct objects into distinct boxes

Place $n$ distinct objects into $k$ distinct boxes. Each object independently chooses a box, so with empty boxes allowed the count is $k^n$.

Every box non-empty (onto maps). By inclusion and exclusion,

$$\text{onto}(n,k)=\sum_{j=0}^{k}(-1)^j\binom kj(k-j)^n = k^n-\binom k1(k-1)^n+\binom k2(k-2)^n-\cdots$$

For small $k$ you should know these by heart: $k=2$ gives $2^n-2$; $k=3$ gives $3^n-3\cdot2^n+3$; $k=4$ gives $4^n-4\cdot3^n+6\cdot2^n-4$.

Given sizes in distinct boxes. If box 1 must hold $n_1$ objects, box 2 must hold $n_2$, and so on with $n_1+\dots+n_k=n$, the count is the multinomial coefficient

$$\frac{n!}{n_1!\,n_2!\cdots n_k!}$$

This also counts the arrangements of a word with repeated letters, which is the same problem in other clothing.

Object-by-object versus box-by-box. Decide on one direction. "Each of 5 letters is posted in one of 3 boxes" is objects choosing boxes ($3^5$). "Three boxes receive 2, 2 and 1 of the 5 letters" is box sizes (the multinomial). The questions look similar and are not.

Dividing into groups

Dividing $n$ distinct objects into groups is the multinomial count divided by a symmetry factor for any groups that cannot be told apart.

  • Groups of different sizes $n_1,n_2,\dots$ (all sizes different): the groups are automatically distinguishable by their size, so the count is $\dfrac{n!}{n_1!\,n_2!\cdots}$ with no further division, whether or not the groups are named.
  • $m$ groups of the same size $s$, unlabelled: $\dfrac{n!}{(s!)^m\,m!}$. The extra $m!$ cancels the order in which the identical groups were listed.
  • $m$ groups of the same size $s$, labelled (for example sent to $m$ named destinations): $\dfrac{n!}{(s!)^m}$.
  • Mixed: divide by $m_j!$ for every block of $m_j$ groups sharing a size. For sizes $3,3,2$ the unlabelled count is $\dfrac{8!}{3!\,3!\,2!\cdot2!}$, where the last $2!$ is for the two groups of size three.
  • Pairs: $2m$ people into $m$ unlabelled pairs: $\dfrac{(2m)!}{2^m\,m!}=(2m-1)!!$. For $m=5$ this is $945$.
  • Two equal teams from $2m$ people: $\tfrac12\binom{2m}{m}$.

Then assigning groups to places. If the groups, once formed, are sent to distinct places, multiply by the number of ways to assign them, $m!$ for equal-size groups. For equal groups this recovers the labelled formula, which is a good check on your reasoning.

Identical boxes

When boxes are identical, the count of distributions of $n$ distinct objects into $k$ identical non-empty boxes is a Stirling number of the second kind, $S(n,k)$, and

$$\text{onto}(n,k)=k!\,S(n,k)$$

because ordering the identical boxes in all possible ways gives distinct boxes. A few values worth knowing: $S(4,2)=7$, $S(5,2)=15$, $S(5,3)=25$, $S(6,2)=31$, $S(6,3)=90$, $S(6,4)=65$. They satisfy $S(n,k)=k\,S(n-1,k)+S(n-1,k-1)$ but you will rarely need it in the exam; the onto-map formula divided by $k!$ is faster.

When both objects and boxes are identical, you are counting partitions of $n$, and there is no closed formula at JEE level. List them. Six identical objects into three identical boxes with empties allowed: $6$, $5+1$, $4+2$, $4+1+1$, $3+3$, $3+2+1$, $2+2+2$, giving $7$.

Derangements

A derangement of $n$ objects is a permutation in which no object is in its original place. The number is

$$D_n=n!\left(1-\frac1{1!}+\frac1{2!}-\frac1{3!}+\cdots+\frac{(-1)^n}{n!}\right)$$

and the values to remember are

$n$ 1 2 3 4 5 6 7
$D_n$ 0 1 2 9 44 265 1854

Two recurrences let you rebuild any entry from earlier ones: $D_n=(n-1)(D_{n-1}+D_{n-2})$ and $D_n=nD_{n-1}+(-1)^n$. The proof of the formula is inclusion and exclusion: let $A_i$ be the event that object $i$ is in its own place; then $|A_{i_1}\cap\dots\cap A_{i_j}|=(n-j)!$ and the sum over subsets gives the alternating series.

Exactly $r$ fixed points. Choose which $r$ objects stay, then derange the others:

$$\binom nr D_{n-r}$$

At least one fixed point: $n!-D_n$. At least $r$ fixed points: use a complement or sum the exact counts; do not multiply $\binom nr(n-r)!$, because that counts arrangements with several fixed points more than once.

Only some objects forbidden. If only $s$ of the $n$ objects must avoid their own places (the other $n-s$ are unrestricted), inclusion and exclusion over the $s$ objects gives

$$\sum_{j=0}^{s}(-1)^j\binom sj(n-j)!$$

For $s=2$ this is $n!-2(n-1)!+(n-2)!$, the "A not first and B not last" formula from the restricted-arrangement post.

A useful identity. Classifying every permutation of $n$ objects by its number of fixed points gives $\sum_{r=0}^{n}\binom nr D_{n-r}=n!$.

For large $n$. The fraction of permutations that are derangements is $D_n/n!$, and it is already $0.368$ for $n=6$. It tends to $1/e$, which is why a question that says "five letters put into five envelopes at random" has a surprisingly large chance of every letter being misplaced.

Where the two halves meet

Many questions combine a grouping step with a derangement or onto step. "Five persons are given hats which are redistributed so that nobody gets their own" is a derangement. "Eight distinct objects are divided into groups of 3, 3 and 2 and then each group is given to one of three named people" is grouping followed by assignment. Work in two clearly labelled stages and multiply; do not try to do the whole problem with one formula.

Worked examples

Every answer below was checked by direct enumeration or by an independent formula in Python before it was included.

Example 1 (single-correct). The number of ways of distributing $8$ identical balls among $3$ different boxes so that no box is empty is: (A) $21$ (B) $28$ (C) $35$ (D) $45$.

Solution. Positive solutions of $x+y+z=8$: $\binom{8-1}{3-1}=\binom72=21$. Answer: (A). Option (B) is $\binom82$, which forgets to place one ball in each box first, and (D) is $\binom{10}{2}$, the count with empty boxes allowed.

Example 2 (numerical-value). Ten identical sweets are given to four children so that no child receives more than $4$ sweets. The number of ways is ______.

Solution. Without the limit: $\binom{13}{3}=286$. A child gets at least $5$ sweets in $\binom{8}{3}=56$ ways (give $5$ first, distribute the remaining $5$ freely among four), and there are $4$ such children: $4\times56=224$. Two children each with at least $5$ use all ten sweets: the remaining $0$ sweets can be distributed in $1$ way, for $\binom42=6$ pairs: $6\times1=6$. Three children cannot all have five. Count $=286-224+6=68$. Answer: 68.

Example 3 (numerical-value). The number of non-negative integer solutions of $x+y+z=12$ with $x\le5$ is ______.

Solution. All solutions: $\binom{14}{2}=91$. Solutions with $x\ge6$: put $x=6+x'$, so $x'+y+z=6$ has $\binom82=28$ solutions. Required count $91-28=63$. Answer: 63.

Example 4 (numerical-value). Six different books are given to three different students so that each student gets at least one book. The number of ways is ______.

Solution. Onto maps from $6$ objects to $3$ boxes: $3^6-3\cdot2^6+3\cdot1^6=729-192+3=540$. Answer: 540. Cross-check by size patterns: $(4,1,1)$ gives $3\times\frac{6!}{4!}=90$; $(3,2,1)$ gives $6\times\frac{6!}{3!\,2!}=360$; $(2,2,2)$ gives $\frac{6!}{2!2!2!}=90$; the sum is $540$.

Example 5 (single-correct). The number of ways in which $10$ people can be divided into $5$ unlabelled pairs is: (A) $945$ (B) $1890$ (C) $113400$ (D) $252$.

Solution. $\dfrac{10!}{(2!)^5\,5!}=\dfrac{3628800}{32\times120}=945$. Answer: (A). Option (C) is the labelled count $\frac{10!}{2^5}$, and (D) is $\binom{10}{5}$.

Example 6 (numerical-value). The number of ways of putting $5$ different objects into $3$ identical boxes so that no box is empty is ______.

Solution. Distinct boxes would give $3^5-3\cdot2^5+3=150$. Identical boxes divide by $3!=6$: $150/6=25$. Answer: 25. (This is $S(5,3)$.)

Example 7 (numerical-value). The number of ways of putting $6$ identical balls into $3$ identical boxes (a box may be empty) is ______.

Solution. Identical boxes and identical balls mean partitions of $6$ into at most three parts: $6$; $5+1$; $4+2$; $4+1+1$; $3+3$; $3+2+1$; $2+2+2$. That is $7$ partitions. Answer: 7.

Example 8 (single-correct). Five letters are put at random into five addressed envelopes, one letter per envelope. The number of ways in which at least one letter is in its own envelope is: (A) $76$ (B) $44$ (C) $120$ (D) $80$.

Solution. Total $5!=120$. Derangements $D_5=44$. At least one correct: $120-44=76$. Answer: (A).

Example 9 (numerical-value). Six letters are put into six addressed envelopes. The number of ways in which exactly two letters go to their correct envelopes is ______.

Solution. Choose the two correct letters in $\binom62=15$ ways; the other four must all be wrong, which is $D_4=9$. Count $15\times9=135$. Answer: 135.

Example 10 (numerical-value). The number of permutations of $1,2,\ldots,7$ in which none of the numbers $1$, $2$ and $3$ is in its own place (the numbers $4,5,6,7$ are unrestricted) is ______.

Solution. Only three objects are restricted, so use $\sum_{j=0}^{3}(-1)^j\binom3j(7-j)!$: $$7!-3\cdot6!+3\cdot5!-4!=5040-2160+360-24=3216.$$ Answer: 3216. The full derangement number $D_7=1854$ would be wrong because it also forbids fixed points among $4,5,6,7$.

Example 11 (numerical-value). Six different gifts are distributed among four different children so that every child receives at least one gift. The number of ways is ______.

Solution. Onto maps from six objects to four boxes: $$4^6-4\cdot3^6+6\cdot2^6-4\cdot1^6=4096-2916+384-4=1560.$$ Answer: 1560. Check by size patterns: $(3,1,1,1)$ gives $4\times\frac{6!}{3!}=480$; $(2,2,1,1)$ gives $6\times\frac{6!}{2!\,2!}=1080$; and $480+1080=1560$.

Example 12 (multiple-correct). Which of the following are correct? (A) $D_4=9$ (B) $D_5=45$ (C) $D_6=265$ (D) the number of permutations of $6$ objects with exactly two fixed points is $135$.

Solution. From the recurrence $D_n=nD_{n-1}+(-1)^n$: $D_3=2$, $D_4=4\cdot2+1=9$, $D_5=5\cdot9-1=44$, $D_6=6\cdot44+1=265$. So (A) is true, (B) is false, and (C) is true. By the exact-fixed-points formula, the count in (D) is $\binom62D_4=15\times9=135$, so (D) is true. Answer: (A), (C), (D).

Common traps

  1. Treating identical groups as labelled. Dividing 12 books into three groups of 4 for three named students is $\frac{12!}{(4!)^3}=34650$; for three unnamed groups it is $\frac{12!}{(4!)^3\,3!}=5775$. The only difference is the $3!$.
  2. Dividing by $m!$ when group sizes differ. The $m!$ symmetry factor applies only to groups of the same size. For sizes $5,3,2$ there is nothing to divide.
  3. Using stars and bars for distinct objects. The formula $\binom{n+k-1}{k-1}$ counts distributions of identical objects. Distinct objects give $k^n$.
  4. Forgetting to pre-place the minimum. For "at least one in each box" give one to each box first, then distribute freely: $\binom{n-1}{k-1}$, not $\binom{n+k-1}{k-1}$.
  5. Subtracting too little in an upper-bound problem. When two variables can overflow, add back the cases where both do. Stopping after the first subtraction undercounts.
  6. Wrong shift for an overflow. A box that must hold at least $m+1$ is handled by pre-placing $m+1$ objects, not $m$. Write the substitution $x=m+1+x'$ explicitly.
  7. Confusing "at least one fixed point" with $\binom nr(n-r)!$. That product counts permutations with at least those $r$ fixed points and counts a permutation with five fixed points several times.
  8. Using $D_n$ when only some objects are restricted. When only $s$ of $n$ objects must avoid their own places, use the partial formula, not $D_n$ or $D_s(n-s)!$.
  9. Mixing the object-choosing and box-filling views. "Each letter goes to one of three boxes" gives $3^5$. "Boxes of sizes $2,2,1$" gives a multinomial. Pick one view and stay with it.
  10. Counting onto maps with $k^n-k$. That works only for $k=2$ in the form $2^n-2$. For $k\ge3$ you need the full inclusion-exclusion.
  11. Assuming boxes are distinct because they are boxes. Check whether the question gives them names. "Three identical boxes" and "three groups" are unlabelled.
  12. Dropping the assignment step. After forming unlabelled groups, if the groups then go to named people, multiply by the number of ways to assign them.

A one-page recap

Situation Count
$n$ identical into $k$ distinct, empties allowed $\binom{n+k-1}{k-1}$
Same, each box non-empty $\binom{n-1}{k-1}$
Same, box $i$ has minimum $m_i$ reduce $n$ by $\sum m_i$ first
One bounded variable $x\le m$ all $-$ (those with $x\ge m+1$)
$n$ distinct into $k$ distinct, empties allowed $k^n$
Same, none empty $\sum_j(-1)^j\binom kj(k-j)^n$
Given sizes $n_1,\dots,n_k$, distinct boxes $n!/(n_1!\cdots n_k!)$
$m$ equal groups of size $s$, unlabelled $n!/\big((s!)^m m!\big)$
$2m$ people into $m$ pairs $(2m)!/(2^m m!)$
Distinct objects, $k$ identical non-empty boxes $S(n,k)=\text{onto}(n,k)/k!$
Derangements $D_n=n!\sum_{j=0}^n(-1)^j/j!$, with $D_n=nD_{n-1}+(-1)^n$
Exactly $r$ fixed points $\binom nr D_{n-r}$
Only $s$ objects forbidden $\sum_{j}(-1)^j\binom sj(n-j)!$

Also read: Binomial Distribution for JEE: Mean and Variance

How to practise this chapter

Read the chapter in the book first: Permutations and Combinations, chapter 3 of the Matrices and Counting book, with the same chapter in Hindi and Telugu. Then take the four chapter tests: Chapter Test 01 and its siblings with ids ending -03-02, -03-03 and -03-04. Each has 15 questions in 36 minutes and includes numerical-value answers. Move the topic into a JEE Main Mathematics practice test and, once a week, a full JEE Main mock. The free JEE Main mini mock gives you ten questions to see where you stand. Full mocks, practice tests and chapter tests are part of the Pro Pass.

Counting links forward to probability: favourable cases for conditional probability and Bayes are often distributions, and the coefficient-sum ideas in the binomial theorem are the same objects counted in a different way. The overview is in matrices, determinants, permutations and the binomial theorem.

A ten-day plan we suggest:

Day Work
1 The four switches; stars and bars with and without minimums; 15 problems
2 Upper bounds with inclusion and exclusion; 12 problems
3 Distinct objects into distinct boxes; onto maps for $k=2,3,4$; cross-check with size patterns
4 Grouping: unlabelled and labelled, equal and unequal sizes; chapter test 01
5 Pairs, teams, then assigning groups to places
6 Identical boxes, partitions, Stirling values; chapter test 02
7 Derangements: formula, recurrence, exactly $r$ fixed points
8 Partial derangements and mixed problems; chapter test 03
9 Chapter test 04; log each wrong answer in an error log with the switch you set wrongly
10 Redo the log; one timed mixed set of 25 counting questions

Frequently asked questions

How do I know whether the boxes are identical or distinct?

Look for names. People, rooms, colours or numbered boxes are distinct. "Piles", "groups" and "identical boxes" are unlabelled. If a question says "divided into three groups" and then "given to three people", the first step is unlabelled and the second assigns names, so multiply by the number of assignments.

Why do I divide by $m!$ for equal groups but not for unequal ones?

Listing $m$ groups of the same size in different orders produces the same division, so the multinomial overcounts by $m!$. Groups of different sizes can always be told apart by their size, so every listing is already a different division and no correction is needed.

Is $D_n$ the same as $n!/e$?

It is the nearest integer to $n!/e$ for every $n\ge1$, which is a handy check: $720/e\approx264.9$ and $D_6=265$. The exact value comes from the alternating series, and you should use the series or the recurrence in a solution.

When do I use inclusion and exclusion instead of a direct count?

Use it when the condition is "none of these bad events happens" and the bad events overlap. Upper bounds in stars and bars, onto maps and derangements are all of this type. Write the bad event for each variable, then the pairs, then the triples, with alternating signs.

What is the quickest way to count onto maps?

For $k=2$ use $2^n-2$, for $k=3$ use $3^n-3\cdot2^n+3$ and for $k=4$ use $4^n-4\cdot3^n+6\cdot2^n-4$. If the numbers are small, cross-check by listing the size patterns, as in Examples 4 and 11. The check takes a minute and catches most slips.

How many fixed-point questions are asked in the exam?

Letters-and-envelopes questions turn up from time to time and usually ask for $D_n$ or an exactly-$r$ count. We make no claim about frequency. The value of the topic is that the same inclusion-exclusion habit solves bounded distributions and onto maps too.

Can I use stars and bars when objects have limits and are distinct?

No. Stars and bars counts identical objects. If objects are distinct and a box has a capacity, count by size patterns and multinomials, then multiply by the ways to choose which boxes get which sizes.

Now test yourself: free, no sign-up to start

Share:𝕏fin
Put what you read into practice

Find study material for your next topic

Browse the Reading Room and preview a chapter before choosing what to study.

Browse study material →

Make this reading part of your preparation

Create your free account to bookmark Reading Room chapters and track your practice scores. You’ll return to this article after signing in.

By continuing, you agree to our terms and privacy policy.

No payment needed. Already registered? Use the same options to sign in.

Comments (0)

Sign in to join the discussion.

No comments yet. Be the first to share your thoughts.