# Mathematics | Generalized PnC Set 2

**Prerequisite –** Generalized PnC Set 1

Combinatorial problems can be rephrased in several different ways, the most common of which is in terms of distributing balls into boxes. So we must become familiar with the terminology to be able to solve problems.

The balls and boxes can be either **distinguishable** or **indistinguishable** and the distribution can take place either with or without **exclusion**.

The term exclusion means that no box can contain more than one ball, and similarly, if the problem states the distribution is without exclusion it means that a box may contain more than one ball.

Throughout this article consider that there are balls and boxes.

### 1. Distinguishable balls and Distinguishable boxes –

**With Exclusion –** In case of exclusion, distribution is the same as counting -permutations, as there are choices for the first ball, for the second and so on.

**Without Exclusion –** When the distribution is without exclusion, i.e. there is no restriction on the minimum number of balls a box has to have, the number of ways – . This is because every ball has choices.

**Fixed number of balls –** If the distribution is such that each box should only have a fixed number of balls then the number of ways is-

where is the number of balls to be put in the box.

**Example 1 –**In how many ways can 10 prizes be distributed among 5 people without exclusion?**Solution –**This situation is analogous to distributing distinct balls into distinct boxes without exclusion. For every prize there are 5 choices of people who can receive it. So the number of ways of distributing the prizes is- .**Example 2 –**How many ways are there to distribute hands of 5 cards to each of four players from a standard deck of 52 cards?**Solution –**This situation is analogous to distributing distinct balls into distinct boxes where each box must have a certain number of balls.

The first person can get the cards in C(52,5) ways.

The second person can get the cards in C(47,5) ways and so on till the fourth person can get the cards in C(37,5) ways. After 20 balls(cards) have been distributed, the remaining cards form the fifth box (or player).

This can be solved with the product rule, total ways-

==

=

This could also be solved using the formula mentioned above using group sizes 5,5,5,5 and 32.

### 2. Indistinguishable balls and Distinguishable boxes –

Counting the number of ways of placing indistinguishable balls into distinguishable boxes with exclusion is the same as counting -combinations without repetition of elements. But if the distribution is without exclusion then the problem is the same as counting the number of -combinations where elements can be repeated. Refer Generalized PnC Part-1 for more on this topic.

### 3. Distinguishable balls and Indistinguishable boxes –

There is no simple closed formula for counting the number of ways of distributing distinguishable balls into indistinguishable boxes, but there is a complex one involving Stirling number of the second kind.

The Stirling number is denoted by where is the number of balls and is the number of non-empty boxes.

So the number of ways is-

### 4. Indistinguishable balls and Indistinguishable boxes –

Counting the number of ways of distributing indistinguishable balls into indistinguishable objects is analogous to finding the number of partitions of a positive integer. No simple formula exists for finding the number of partitions of a positive integer.

For both of the above cases, enumeration of all ways is sometimes easier than finding a closed formula which gives the same result.

**Example 1 –**How many ways are there to put four different balls into three indistinguishable offices without exclusion?**Solution –**Enumerating all possible scenarios instead of using the Stirling Formula is easier. Let the four balls be .

All balls in one box –

3 balls in one box and 1 in another-

2 balls in one box and 2 in another-

2 balls in one box and 1 each in the remaining boxes-

This gives us a total of- 1 + 3 + 4 + 6 = 14 ways.**Example 2 –**How many ways are there to put 4 indistinguishable balls into 3 indistinguishable boxes?**Solution –**As mentioned above, the above problem is analogous to finding the number of partitions of the positive integer 4, where the number of partitions is less than or equal to 3.

Enumerating all possible ways-

All four balls in one box – 4

3 balls in one box, 1 ball in one – 3,1

2 balls in two boxes – 2,2

2 balls in 1 box, 1 ball in two boxes each – 2,1,1

Total number of ways = 4

It is similar to finding the number of partitions of 4-

4 = 4

3 + 1 = 4

2 + 2 = 4

2 + 1 + 1 = 4

**GATE CS Corner Questions**

Practicing the following questions will help you test your knowledge. All questions have been asked in GATE in previous years or in GATE Mock Tests. It is highly recommended that you practice them.

**References-**

Partition Number Theory – Wikipedia

Discrete Mathematics and its Applications, by Kenneth H Rosen

This article is contributed by **Chirag Manwani**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

## Recommended Posts:

- Mathematics | Generalized PnC Set 1
- Mathematics | Probability
- Mathematics | Law of total probability
- Mathematics | PnC and Binomial Coefficients
- Mathematics | Combinatorics Basics
- Mathematics | Generating Functions - Set 2
- Mathematics | Introduction to Proofs
- Mathematics | Power Set and its Properties
- Mathematics | Indefinite Integrals
- Mathematics | Algebraic Structure
- Mathematics | Covariance and Correlation
- Mathematics | Random Variables
- Mathematics | Lagrange's Mean Value Theorem
- Mathematics | Set Operations (Set theory)
- Mathematics | The Pigeonhole Principle