5 Counting And Discrete Probability

Discrete Structures · Unit 5 · 9 hrs

Counting and Discrete Probability

Exam-focused notes for Counting and Discrete Probability (Discrete Structures, CSC165): what the TU syllabus asks and how it has actually been tested, with 14 solved past questions from this unit.

Counting and Discrete Probability in short

This chapter develops combinatorics, the branch of discrete mathematics that counts arrangements of objects without listing them all, along with discrete probability built directly on those counts, and the recurrence relations that describe quantities defined in terms of earlier values of themselves.

Counting and Discrete Probability: notes

Counting

Combinatorics is the study of arrangements of objects, and enumeration, counting objects that satisfy some property, is one of its central concerns. Counting arguments answer questions such as how many passwords of a given shape exist, whether a telephone numbering scheme has enough numbers to meet demand, or how many steps an algorithm takes in the worst case, all without physically listing every possibility.

Basics of Counting

The sum rule says that if a task can be done in $n_1$ ways or, alternatively, in $n_2$ ways, and the two ways cannot both happen at once, then the task can be done in $n_1+n_2$ ways; in set terms, for disjoint sets $A_1,\ldots,A_m$, $|A_1\cup A_2\cup\cdots\cup A_m| = |A_1|+|A_2|+\cdots+|A_m|$. For example, drawing a heart or a diamond from a standard deck can be done in $13+13=26$ ways, since there are $13$ hearts and $13$ diamonds and a card cannot be both.

The product rule says that if a task consists of a first part done in $n_1$ ways followed by a second, independent part done in $n_2$ ways, the whole task can be done in $n_1 n_2$ ways; in set terms $|A_1\times A_2\times\cdots\times A_k| = |A_1|\cdot|A_2|\cdots|A_k|$. For example, an office building with $29$ floors and $37$ offices per floor has $29\times37=1073$ offices in total. Similarly, the number of three-letter initials with no letter repeated is $26\times25\times24=15600$, since the first letter has $26$ choices, the second $25$ remaining choices, and the third $24$.

When two tasks can happen at the same time, the sum rule alone over-counts, since the ways of doing both are counted once for each task; the inclusion-exclusion principle for two counting tasks corrects this exactly as it did for two sets: $$|A_1 \cup A_2| = |A_1|+|A_2|-|A_1\cap A_2|.$$ For example, counting bit strings of length eight that start with a $1$ bit or end with the two bits $00$: there are $2^7=128$ strings starting with $1$ and $2^6=64$ strings ending in $00$, and $2^5=32$ strings doing both (fixing the first bit and the last two bits leaves $8-3=5$ free bits), so the count is $128+64-32=160$.

Pigeonhole Principle

The pigeonhole principle states that if $k+1$ or more objects are placed into $k$ boxes, some box contains at least two objects. The proof is by contradiction: if every box held at most one object, the total number of objects placed would be at most $k$, contradicting that $k+1$ or more objects were placed. For example, among $30$ students, since there are only $26$ letters of the alphabet, at least two students' last names must begin with the same letter. Likewise, to guarantee two students share an exam score on a scale from $0$ to $100$ (that is, $101$ possible scores), a class needs at least $102$ students.

The generalised pigeonhole principle strengthens this: if $N$ objects are placed into $k$ boxes, some box contains at least $\lceil N/k \rceil$ objects. The proof is again by contradiction: if every box held at most $\lceil N/k\rceil - 1$ objects, the total would be at most $k(\lceil N/k\rceil-1) < N$, a contradiction. For example, among $100$ people, since there are $12$ months, some month contains at least $\lceil 100/12\rceil = \lceil 8.33\rceil = 9$ people's birthdays. Similarly, to guarantee at least $r$ people share a grade out of $5$ possible grades, the class needs at least $N$ students where $N = k(r-1)+1$; for $r=2$ (guaranteeing at least two people share a grade) with $k=5$ grades, $N=5(2-1)+1=6$ students suffice.

Permutations and Combinations

A permutation of a set of distinct objects is an ordered arrangement of some or all of them; an ordered arrangement of $r$ objects chosen from $n$ is an $r$-permutation, counted by $$P(n,r) = \frac{n!}{(n-r)!}, \qquad P(n,n)=n!.$$ For example, choosing a first-, second- and third-prize winner from $100$ contestants (order matters, no repeats) can be done in $P(100,3) = \frac{100!}{97!} = 100\times99\times98 = 970200$ ways.

A combination is an unordered selection, an $r$-combination of a set counting the number of $r$-element subsets: $$C(n,r) = \binom{n}{r} = \frac{n!}{r!(n-r)!}.$$ For example, selecting $5$ players from a $10$-member tennis team, where order does not matter, can be done in $$C(10,5) = \frac{10!}{5!,5!} = 252$$ ways.

What this unit covers

  • Counting
  • Basics of Counting
  • Pigeonhole Principle
  • Permutations and Combinations
  • Two Element Subsets
  • Counting Subsets of a Set
  • Binomial Coefficients
  • Generalized Permutations and Combinations
  • Generating Permutations and Combinations
  • Discrete Probability
  • Introduction to Discrete Probability
  • Probability Theory
  • Probability Calculation in Hashing
  • Expected Value and Variance
  • Randomized Algorithms
  • Advanced Counting
  • Recurrence Relations
  • Solving Recurrence Relations (Homogeneous and Non-Homogeneous equations)
  • Introduction to Divide and Conquer Recurrence Relations

Pigeonhole Principle

2081 · 5 marks

State sum rule and product rule. If 26 integers are chosen from the set of consecutive integers {1,2,3,...,50}, prove that there are sure to be two numbers so that one is multiple of the other. [5]

Sum Rule: If a task can be done in one of $n1$ ways or one of $n2$ ways, where none of the set of $n1$ ways is the same as any of the set of $n2$ ways, then there are $n1 + n2$ ways to do the task. Product Rule: If a task can be broken down into a sequence of two subtasks, and there are $n1$ ways...

Open this answer on its own page →

2080 · 10 marks

State pigeonhole principle. Solve the recurrence relation $a_n = 5a_{n-1} - 6a_{n-2}$, with initial conditions $a_1 = 1$ and $a_2 = 3$.[10]

  • Recurrence: $an = 5a{n-1} - 6a{n-2}$ - Initial conditions: $a1 = 1$, $a2 = 3$ --- Statement: If $k+1$ or more objects are placed into $k$ boxes, then at least one box contains two or more objects. Generalized form: If $N$ objects are placed into $k$ boxes, then at least one box contains at leas...
Open this answer on its own page →

2078 · 5 marks

Show that if there are 30 students in a class, then at least two have same names that begin with the same letter. Explain the pascal's triangle. [5]

Show solved answer

Pigeonhole Principle and Pascal's Triangle

Given Data

  • Number of students = 30
  • Number of letters in the English alphabet = 26

Part 1: At Least Two Students Have Names Beginning with the Same Letter

Principle Used: Pigeonhole Principle

Statement: If $n$ objects are placed into $k$ boxes and $n > k$, then at least one box contains two or more objects.

More generally, if $n$ objects are placed into $k$ boxes, then at least one box contains at least $\left\lceil \dfrac{n}{k} \right\rceil$ objects.

Proof

Set up the correspondence:

  • Pigeonholes (boxes): the 26 letters of the alphabet that a name can begin with. So $k = 26$.
  • Pigeons (objects): the 30 students, each classified by the first letter of their name. So $n = 30$.

Since

$$n = 30 > 26 = k,$$

by the Pigeonhole Principle at least one letter (box) must be assigned to more than one student.

Using the generalized form, the most crowded letter contains at least

$$\left\lceil \frac{30}{26} \right\rceil = \lceil 1.153\ldots \rceil = 2 \text{ students.}$$

Conclusion: At least two students have names beginning with the same letter. (Proved)

Worst case reasoning: Even if the first 26 students all get distinct starting letters, the remaining $30 - 26 = 4$ students must reuse letters already taken, forcing a repetition.


Part 2: Pascal's Triangle

Definition

Pascal's Triangle is a triangular array of the binomial coefficients $\binom{n}{r}$, where each interior entry equals the sum of the two entries directly above it.

Construction Rule

$$\binom{n}{r} = \binom{n-1}{r-1} + \binom{n-1}{r}$$

with boundary conditions

$$\binom{n}{0} = 1, \qquad \binom{n}{n} = 1 \quad \text{for all } n \ge 0.$$

The Triangle (First 6 rows)

Row 0:            1
Row 1:          1   1
Row 2:        1   2   1
Row 3:      1   3   3   1
Row 4:    1   4   6   4   1
Row 5:  1   5  10  10   5   1

Key Properties

PropertyDescription
Symmetry$\binom{n}{r} = \binom{n}{n-r}$
Row Sum$\displaystyle\sum_{r=0}^{n}\binom{n}{r} = 2^{n}$
Binomial TheoremRow $n$ gives coefficients of $(x+y)^n$
BordersAll edge entries equal $1$

Application: Binomial Theorem

$$(x+y)^n = \sum_{r=0}^{n}\binom{n}{r} x^{n-r} y^{r}$$

Using Row 3:

$$(x+y)^3 = x^3 + 3x^2y + 3xy^2 + y^3$$

Verification of the addition rule

$$\binom{4}{2} = \binom{3}{1} + \binom{3}{2} = 3 + 3 = 6,$$

which matches the middle entry of Row 4.


Summary: With 30 students and only 26 possible initial letters, the Pigeonhole Principle guarantees at least two students share a starting letter. Pascal's Triangle arranges the binomial coefficients so each value is the sum of the two above it, encoding the coefficients of $(x+y)^n$.

Open this answer on its own page →

Solving Recurrence Relations

2081 · 5 marks

Solve the recurrence relation $a_n = a_{n-1} + 2a_{n-2}$ with initial conditions $a_0 = 2$ and $a_1 = 7$. [5]

Show solved answer

Solving the Recurrence Relation $a_n = a_{n-1} + 2a_{n-2}$

Given Data

  • Recurrence: $a_n = a_{n-1} + 2a_{n-2}$
  • Initial conditions: $a_0 = 2$, $a_1 = 7$

Step 1: Characteristic Equation

This is a linear homogeneous recurrence with constant coefficients. Assume $a_n = r^n$:

$$r^n = r^{n-1} + 2r^{n-2}$$

Divide by $r^{n-2}$:

$$r^2 = r + 2 \implies r^2 - r - 2 = 0$$

Step 2: Solve for Roots

$$r^2 - r - 2 = (r-2)(r+1) = 0$$

$$r_1 = 2, \quad r_2 = -1$$

Distinct roots, so the general solution is:

$$a_n = \alpha_1 (2)^n + \alpha_2 (-1)^n$$

Step 3: Apply Initial Conditions

From $a_0 = 2$: $$\alpha_1 + \alpha_2 = 2 \quad (i)$$

From $a_1 = 7$: $$2\alpha_1 - \alpha_2 = 7 \quad (ii)$$

Adding $(i)$ and $(ii)$: $$3\alpha_1 = 9 \implies \alpha_1 = 3$$

From $(i)$: $$\alpha_2 = 2 - 3 = -1$$

Step 4: Final Solution

$$\boxed{a_n = 3 \cdot 2^n - (-1)^n}$$

Verification

$n$FormulaExpected
$0$$3(1) - 1 = 2$$2$ ✓
$1$$3(2) - (-1) = 7$$7$ ✓
$2$$3(4) - 1 = 11$$7 + 2(2) = 11$ ✓

The solution is confirmed correct.

Open this answer on its own page →

2078 · 5 marks

Solve the recurrence relation $a_n = 5a_{n-1} - 6a_{n-2}$, with initial conditions $a_0 = 1$, $a_1 = 4$. [5]

Show solved answer

Solution of Recurrence Relation

Given

$$a_n = 5a_{n-1} - 6a_{n-2}, \quad a_0 = 1,\ a_1 = 4$$

Solution

Characteristic equation. Assume $a_n = r^n$:

$$r^2 = 5r - 6 \implies r^2 - 5r + 6 = 0$$

Roots:

$$(r-2)(r-3) = 0 \implies r_1 = 2,\ r_2 = 3$$

Distinct roots, so the general solution is:

$$a_n = \alpha_1 \cdot 2^n + \alpha_2 \cdot 3^n$$

Apply initial conditions:

$n=0$: $\alpha_1 + \alpha_2 = 1 \quad (i)$

$n=1$: $2\alpha_1 + 3\alpha_2 = 4 \quad (ii)$

From $(i)$: $\alpha_1 = 1 - \alpha_2$. Substitute into $(ii)$:

$$2(1 - \alpha_2) + 3\alpha_2 = 4 \implies 2 + \alpha_2 = 4 \implies \alpha_2 = 2$$

$$\alpha_1 = 1 - 2 = -1$$

Final solution:

$$\boxed{a_n = 2\cdot 3^n - 2^n}$$

Verification:

$n$$2\cdot3^n - 2^n$Check
0$2-1=1$$a_0=1$ ✓
1$6-2=4$$a_1=4$ ✓
2$18-4=14$$5(4)-6(1)=14$ ✓
Open this answer on its own page →

2076 · 10 marks

Question

State pigeonhole principle. Solve the recurrence relation $a_n = 3a_{n-1} - 3a_{n-2} + a_{n-3}$, with initial conditions $a_0 = 1, a_1 = 3, a_2 = 7$. [10]

  • Recurrence: $an = 3a{n-1} - 3a{n-2} + a{n-3}$ - Initial conditions: $a0 = 1,\ a1 = 3,\ a2 = 7$ --- Statement: If $n$ objects are placed into $k$ boxes and $n k$, then at least one box contains two or more objects. Generalized form: If $N$ objects are placed into $k$ boxes, then at least one box...
Open this answer on its own page →

2075 · 5 marks

Solve the recurrence relation $a_n = 5a_{n-1} - 6a_{n-2}$, with initial conditions $a_1 = 1$ and $a_2 = 2$. [5]

Show solved answer

Solution of Recurrence Relation

Given

  • Recurrence: $a_n = 5a_{n-1} - 6a_{n-2}$
  • Initial conditions: $a_1 = 1$, $a_2 = 2$

This is a linear homogeneous recurrence of degree 2 with constant coefficients.


Solution

Characteristic equation

Substitute $a_n = r^n$:

$$r^2 = 5r - 6 \implies r^2 - 5r + 6 = 0$$

Factor:

$$(r-2)(r-3) = 0 \implies r_1 = 2,\ r_2 = 3$$

Distinct roots, so the general solution is:

$$a_n = \alpha_1 \cdot 2^n + \alpha_2 \cdot 3^n$$

Apply initial conditions

For $a_1 = 1$: $$2\alpha_1 + 3\alpha_2 = 1 \quad (i)$$

For $a_2 = 2$: $$4\alpha_1 + 9\alpha_2 = 2 \quad (ii)$$

Multiply $(i)$ by 2: $$4\alpha_1 + 6\alpha_2 = 2 \quad (iii)$$

Subtract $(iii)$ from $(ii)$: $$3\alpha_2 = 0 \implies \alpha_2 = 0$$

From $(i)$: $$2\alpha_1 = 1 \implies \alpha_1 = \tfrac{1}{2}$$

Final solution

$$\boxed{a_n = \tfrac{1}{2}\cdot 2^n = 2^{n-1}}$$

Verification

$n$$2^{n-1}$Recurrence
11given
22given
34$5(2)-6(1)=4$ ✓
48$5(4)-6(2)=8$ ✓

The solution satisfies both the recurrence and initial conditions.

Open this answer on its own page →

2080.1 · 10 marks

Linear Homogeneous Recurrence Relation with Constant Coefficients

A linear homogeneous recurrence relation with constant coefficients is a recurrence relation of the form:

$$a_n = c_1 a_{n-1} + c_2 a_{n-2} + \cdots + c_k a_{n-k}$$

where $c_1, c_2, \ldots, c_k$ are constants and $k$ is the order of the recurrence relation.

To solve such a recurrence relation, we use the characteristic equation method:

  1. Assume a solution of the form $a_n = r^n$
  2. Substitute into the recurrence relation to get the characteristic equation
  3. Solve for the roots $r$
  4. The general solution depends on the nature of the roots (distinct, repeated, or complex)
  • Recurrence: $an = 6a{n-1} - 9a{n-2}$ - Initial conditions: $a0 = 1$, $a1 = 6$ A linear homogeneous recurrence relation of degree $k$ with constant coefficients has the form: $$an = c1 a{n-1} + c2 a{n-2} + \cdots + ck a{n-k}$$ where $c1, c2, \ldots, ck$ are constants (independent of $n$) and
Open this answer on its own page →

Permutations and Combinations

2081 · 5 marks

When do we use permutation rather than combination? How many 5-digit numbers can be generated using the digits 0 to 9, if each number starts with 98 and no digit appears more than once? [5]

We use a permutation when the order of arrangement matters, i.e., when different orderings of the same selected items are counted as distinct outcomes. We use a combination when only the selection matters and order is irrelevant. Formulas: - Permutation: $P(n, r) = \dfrac{n!}{(n-r)!}$ (order matt...

Open this answer on its own page →

2076 · 5 marks

How many 3 digits numbers can be formed from the digits 1,2,3,4 and 5 assuming that:a. Repetitions of digits are allowed b. Repetitions of digits are not allowed [5]

  • Available digits: ${1, 2, 3, 4, 5}$ → 5 digits - Number to form: 3-digit number (Hundreds, Tens, Units) Multiplication Rule: if positions can be filled in $n1, n2, n3$ ways, total = $n1 \times n2 \times n3$. --- Each of the 3 positions can independently be any of the 5 digits. Position Choice...
Open this answer on its own page →

2075 · 5 marks

List any two applications of conditions of probability. You have 9 families you would like to incite to a wedding. Unfortunately, you can only invite 6 families. How many different sets of invitations could you write? [5]

Show solved answer

Applications of Conditional Probability and Combination Problem

Given Data

  • Total families available: $n = 9$
  • Families to be invited: $r = 6$
  • Order does not matter (a set of invitations), so this is a combination problem.

Part 1: Two Applications of Conditional Probability

Conditional probability $P(A|B)$ is the probability of event $A$ occurring given that event $B$ has already occurred. Two applications:

  1. Medical Diagnosis: Determining the probability that a patient actually has a disease given a positive test result, i.e., $P(\text{Disease} \mid \text{Positive Test})$. This is often computed using Bayes' theorem.

  2. Spam Email Filtering: Classifying an email as spam given the presence of certain words, i.e., $P(\text{Spam} \mid \text{Keywords})$. Bayesian spam filters rely on this.

(Other valid examples: weather forecasting, risk assessment in insurance, fault diagnosis in machines.)


Part 2: Combination Problem

Formula

The number of ways to choose $r$ families from $n$ families, without regard to order:

$$C(n, r) = \binom{n}{r} = \frac{n!}{r!,(n-r)!}$$

Solution

$$C(9, 6) = \frac{9!}{6!,(9-6)!} = \frac{9!}{6!,\cdot,3!}$$

Expanding and cancelling $6!$:

$$= \frac{9 \times 8 \times 7 \times 6!}{6! \times (3 \times 2 \times 1)} = \frac{9 \times 8 \times 7}{6} = \frac{504}{6} = 84$$

Conclusion

There are $\boxed{84}$ different sets of invitations that could be written when choosing 6 families out of 9.

Open this answer on its own page →

Binomial Coefficients

2078 · 5 marks

What is the coefficient of $x^2$ in $(1+x)^{11}$? Describe how relation can be represented using matrix. [5]

  • Expression: $(1+x)^{11}$ - Required: coefficient of $x^2$ - Second task: describe matrix representation of a relation --- By the Binomial Theorem: $$(1+x)^n = \sum{k=0}^{n} \binom{n}{k} x^k$$ The term containing $x^k$ has coefficient $\binom{n}{k}$. For $n = 11$, $k = 2$: $$\binom{11}{2} = \fra...
Open this answer on its own page →

Randomized Algorithms

2075 · 5 marks

What does probability testing means? Describe how Fermat's Little Theorem tests for a prime number with suitable example. [5]

Probability testing (also called probabilistic primality testing) is a method of determining whether a given integer is prime, not with absolute certainty, but with a high degree of probability. Instead of checking all possible divisors (which is computationally expensive for large numbers), a pr...

Open this answer on its own page →

Basics of Counting

2080.1 · 5 marks

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

  • Alphabet size: 26 lowercase letters - String length: 4 - Condition: string must contain the letter 'x' (at least once) - Repetition of letters: allowed (standard assumption for such strings) All data required is present. --- Definition: If a procedure can be carried out as a sequence of $k$ tas...
Open this answer on its own page →