7 Combinatorics And Counting

Discrete Structure · Unit 7

Combinatorics and Counting

Exam-focused notes for Combinatorics and Counting (Discrete Structure, BIT152): what the TU syllabus asks and how it has actually been tested, with 8 solved past questions from this unit.

Combinatorics and Counting in short

Combinatorics is the art of counting without listing every case. It is used to count passwords, arrangements, selections and to estimate how much work an algorithm does.

Combinatorics and Counting: notes

Product rule

Product rule (multiplication principle): suppose a task has two stages. The first can be done in $n_1$ ways, and the second in $n_2$ ways for each first choice. Then the whole task can be done in $n_1 \cdot n_2$ ways. It extends to any number of stages.

Sum rule: suppose a task can be done in $n_1$ ways or in $n_2$ ways, and the two cannot happen together. Then there are $n_1 + n_2$ ways.

Example. A code has 3 letters followed by 3 digits. Letters and digits can repeat.

$$26 \cdot 26 \cdot 26 \cdot 10 \cdot 10 \cdot 10 = 17{,}576{,}000$$

Example. The number of bit strings of length 8 is $2^8 = 256$. The number of functions from a set of $m$ elements to a set of $n$ elements is $n^m$. The number of subsets of an $n$-element set is $2^n$.

Example. A student picks one project from 5 on networks or 7 on databases. By the sum rule there are $5 + 7 = 12$ choices.

Permutations

A permutation is an ordered arrangement of objects. The number of permutations of $n$ distinct objects is $n!$. An ordered arrangement of $r$ objects chosen from $n$ is an $r$-permutation:

$$P(n, r) = \frac{n!}{(n-r)!} = n(n-1)\cdots(n-r+1)$$

Example. Ways to award first, second and third prize among 10 students:

$$P(10, 3) = 10 \cdot 9 \cdot 8 = 720$$

Example. The letters of NEPAL can be arranged in $5! = 120$ ways.

Permutations with repeated objects. Suppose there are $n$ objects, with $n_1$ of one kind and $n_2$ of another. Then the number of distinct arrangements is:

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

Example. The word MISSISSIPPI has 11 letters: M once, I four times, S four times, P twice.

$$\frac{11!}{1!,4!,4!,2!} = \frac{39{,}916{,}800}{1152} = 34{,}650$$

Example. Seat 5 people around a round table. Fix one person to remove rotations, then arrange the other 4: $(5-1)! = 24$ ways.

What this unit covers

  • Product rule
  • Permutations
  • Combinations
  • Lexicographic ordering
  • Pigeonhole principle
  • Generalized pigeonhole principle
  • Inclusion and exclusion principle
  • Binomial coefficients

Generalized pigeonhole principle

2081 · 5 marks

State generalized Pigeonhole principle. How many ways can you draw four digits integers without repetition of the digit? [5]

  • Digit set: ${0, 1, 2, 3, 4, 5, 6, 7, 8, 9}$ - total 10 digits - Required: four-digit integers, no repetition of digits - Implicit constraint: a genuine 4-digit integer must not begin with 0 Statement: If $N$ objects are placed into $k$ boxes, then there is at least one box containing at least...
Open this answer on its own page →

2079 · 5 marks

What is generalized pigeonhole principle. If a class has 24 students, what is the maximum number of possible grading that must be done to ensure that there at least two students with the same grade. [5]

Show solved answer

Generalized Pigeonhole Principle

Given Data

  • Number of students in class: $24$
  • Grading system: standard grades assumed as ${A, B, C, D, F}$, so number of grade categories $k = 5$
  • Required: number of gradings needed to guarantee at least two students share the same grade

Note: The number of distinct grades is not stated in the question. The standard university grading scheme with 5 grades (A, B, C, D, F) is assumed. If a different number of grades is intended, the answer changes accordingly.


Definition

Generalized Pigeonhole Principle:

If $N$ objects are placed into $k$ boxes, then at least one box contains at least $\left\lceil \dfrac{N}{k} \right\rceil$ objects.

Basic Pigeonhole Principle (special case): If $N > k$, then at least one box contains at least $2$ objects.


Solution

Here the grades are the pigeonholes and the students are the objects.

We want at least two students in the same grade category, i.e.

$$\left\lceil \frac{N}{k} \right\rceil \geq 2$$

This is guaranteed when

$$N \geq k + 1$$

Worst-case reasoning: Assign grades one by one. The first $5$ students could each receive a different grade (one per category). The very next student ($6^{th}$) must repeat a grade.

With $k = 5$:

$$N = k + 1 = 5 + 1 = 6$$

$$\boxed{\text{At most } 6 \text{ gradings guarantee two students with the same grade}}$$


Interpretation of "24 students"

The class has $24$ students, which far exceeds the $6$ required. So the class of $24$ students certainly contains repeated grades. Indeed, distributing $24$ students among $5$ grades:

$$\left\lceil \frac{24}{5} \right\rceil = \lceil 4.8 \rceil = 5$$

So with all $24$ students, at least one grade is shared by at least $5$ students. But to merely guarantee two students with the same grade, grading only $6$ students suffices.

Answer: The maximum number of gradings needed is $6$ (using $k = 5$ grades). The number $24$ simply confirms a repetition is unavoidable.

Open this answer on its own page →

2080.1 · 5 marks

State generalized Pigeonhole principle. How many ways can we get the 3 digit integers without repeating the digit? [5]

  • Digits available: $0,1,2,3,4,5,6,7,8,9$ (10 digits total) - Form: 3-digit integer, no digit repeated - Implicit constraint: leading digit (hundreds place) $\neq 0$ --- Statement: If $N$ objects are placed into $k$ boxes, then there is at least one box containing at least $$\left\lceil \frac{N}{...
Open this answer on its own page →

Pigeonhole principle

2080 · 5 marks

What is the pigeonhole principle? Show that binomn+1k=binomnk−1+binomnk\binom{n+1}{k} = \binom{n}{k-1} + \binom{n}{k}binomn+1k=binomnk−1+binomnk where nnn and kkk are positive integers with n≥kn \geq kn≥k . [5]

--- Definition: If n + 1 or more objects (pigeons) are placed into n containers (pigeonholes), then at least one container must contain two or more objects. Formal Statement: If a function $f: A \to B$ where $A B$, then $f$ is not injective (not one-to-one), meaning at least two elements of $A$ m...

Open this answer on its own page →

Permutations

2080 · 5 marks

What is permutation? What is the next permutation in lexicographic order after 362541? [5]

Show solved answer

Permutation and Next Permutation in Lexicographic Order

Given Data

  • Current permutation: 362541 (digits: 3, 6, 2, 5, 4, 1)
  • Task: find the next permutation in lexicographic (dictionary) order.

What is a Permutation?

A permutation of a set of elements is an arrangement of those elements in a definite order. For a set of $n$ distinct elements, the total number of permutations is:

$$n! = n \times (n-1) \times (n-2) \times \cdots \times 1$$

Example: For ${1, 2, 3}$, the $3! = 6$ permutations are: $$123,\ 132,\ 213,\ 231,\ 312,\ 321$$

In lexicographic order, permutations are ordered like words in a dictionary, comparing element by element from left to right.


Next Permutation Algorithm

Step 1: Find the largest index $i$ such that $a[i] < a[i+1]$ (the pivot). Step 2: Find the largest index $j > i$ such that $a[j] > a[i]$. Step 3: Swap $a[i]$ and $a[j]$. Step 4: Reverse the suffix starting at $a[i+1]$.


Applying to 362541

Index the digits (0-based):

Index012345
Digit362541

Step 1: Find pivot (scan right to left):

  • $a[4]=4 > a[5]=1$ → no
  • $a[3]=5 > a[4]=4$ → no
  • $a[2]=2 < a[3]=5$ → pivot found, $i = 2$, value $= 2$

Step 2: Find successor $a[j] > 2$ (scan right to left):

  • $a[5]=1 < 2$ → skip
  • $a[4]=4 > 2$ → found, $j = 4$

Step 3: Swap $a[2]$ and $a[4]$:

Before: $3,\ 6,\ \mathbf{2},\ 5,\ \mathbf{4},\ 1$ After: $3,\ 6,\ \mathbf{4},\ 5,\ \mathbf{2},\ 1$

Step 4: Reverse suffix from index 3 to end:

Suffix $5, 2, 1 \Rightarrow 1, 2, 5$

Result: $3,\ 6,\ 4,\ 1,\ 2,\ 5$


Result

The next permutation in lexicographic order after 362541 is $\boxed{364125}$.

Verification: $364125 > 362541$ and it is the smallest such permutation (the change occurs at the rightmost possible position with the smallest valid increase), confirming correctness.

Open this answer on its own page →

0 · 5 marks

Differentiate permutation with combination. What is the next permutation in lexicographic order after 362541? [5]

Basis Permutation Combination --------------------------------- Definition Arrangement of objects where order matters Selection of objects where order does not matter Formula $P(n, r) = \dfrac{n!}{(n - r)!}$ $C(n, r) = \dfrac{n!}{r!,(n - r)!}$ Example $AB$ and $BA$ are different $AB$ and $BA$ ar...

Open this answer on its own page →

Inclusion and exclusion principle

2079 · 10 marks

Why do we need principle of inclusion and exclusion? How many ways can we express the four character words ending with a digit and beginning three are lowercase alphabets. Be sure that none of the character can be repeated. Using induction, show that $3^n - 1$ is multiple of 2 for $n \geq 1$. [5+5]

  • Word length: 4 characters - Positions 1, 2, 3: lowercase alphabets (26 available) - Position 4: a digit (10 available: 0-9) - Constraint: no character repeated - Induction claim: $3^n - 1$ is a multiple of 2 for $n \geq 1$ --- When we count elements in a union of overlapping sets, simply adding...
Open this answer on its own page →

Product rule

2078 · 5 marks

Explain product rule. How many strings are there of four lowercase letters that have the letter x in them? [5]

  • String length: 4 characters - Alphabet: 26 lowercase letters - Condition: the letter 'x' must appear at least once The Product Rule (Multiplication Principle) states: If a procedure consists of a sequence of $k$ tasks, where task 1 can be done in $n1$ ways, task 2 in $n2$ ways, ..., and task
Open this answer on its own page →