CS311H Syllabus Calendar Office Hours Readings Assignments Resources

CS311H Discrete Mathematics for Computer Science

Quiz 08 Solutions

Oct 30, 2026


Problem 1

Let \(r\) be non-negative integer. Prove or disprove that for all non-negative integers \(n\) \[ \sum_{i=r}^{n} \binom{i}{r} = \binom{n+1}{r+1}, \] where \(n \geq r.\)

Show solution

Base case: \(n = r\). We need to show that \(\sum_{i=r}^{r} \binom{i}{r} = \binom{r+1}{r+1}.\)

\[ \begin{array}{c l l} & \sum\limits_{i=r}^{r} \binom{i}{r} & \\ = & \binom{r}{r} & \textrm{algebra} \\ = & 1 & \textrm{algebra} \\ = & \binom{r+1}{r+1} & \textrm{algebra} \end{array} \]

Inductive Step: Inductive Hypothesis: Assume \(\sum\limits_{i=r}^{k} \binom{i}{r} = \binom{k+1}{r+1}\), where \(k \geq r\).

We need to show that \(\sum\limits_{i=r}^{k+1}\binom{i}{r} = \binom{k+2}{r+1}\).

\[ \begin{array}{c l l} & \sum\limits_{i=r}^{k+1}\binom{i}{r} & \\ = & \sum\limits_{i=r}^{k}\binom{i}{r} + \binom{k+1}{r} & \textrm{algebra} \\ = & \binom{k+1}{r+1} + \binom{k+1}{r} & \textrm{IH} \\ = & \frac{(k+1)!}{\left((k+1)-(r+1)\right)!(r+1)!} + \frac{(k+1)!}{\left((k+1)-r\right)!r!} & \text{algebra} \\ = & \frac{(k+1)!}{(k-r)!(r+1)!} + \frac{(k+1)!}{(k-r+1)!r!} & \text{algebra} \\ = & \frac{(k+1)!}{(k-r)!(r+1)r!} + \frac{(k+1)!}{(k-r+1)(k-r)!r!} & \text{algebra} \\ = & \frac{(k+1)!}{(k-r)!r!}\left( \frac{1}{r+1} + \frac{1}{k-r+1}\right) & \text{algebra} \\ = & \frac{(k+1)!}{(k-r)!r!}\cdot \frac{k+2}{(r+1)(k-r+1)} & \text{algebra} \\ = & \frac{(k+2)!}{(k-r+1)!(r+1)!} & \text{algebra} \end{array} \]

This proves the inductive step.

Therefore, by PMI, \(\sum_{i=r}^{n} \binom{i}{r} = \binom{n+1}{r+1},\) where \(n, r\) are non-negative integers and \(n \geq r.\)

Problem 2

Consider the set \([12]=\{1, 2, \dots, 11, 12\}\).

  1. Pick \(n\) different elements from \([12]\). What is the minimum \(n\) that guarantees that two of them must add up to \(13\)? Provide your answer.
  2. Prove that this random selection of \(n\) elements always has two elements sum to 13.
  3. Prove that this \(n\) is minimal, that any smaller \(n\) will not guarantee a sum to 13.
Show solution

If \(n \geq 7,\) then picking \(n\) different elements from \([12]\) guarantees that two of them will add up to \(13.\)

The pairs of numbers from \([12]\) that add up to \(13\) are \(\{(1,12), (2, 11), \dots, (6, 7)\}.\) There are \(6\) such pairs. Therefore, by the Pigeonhole Principle, if we pick \(7\) or more numbers from \([12]\) then both elements of a pair that adds up to \(13\) must be in the selection.

Let \(n\) be any integer with \(n \leq 6\). Choose the \(n\) elements \(\{1, 2, \dots, n\}\), which are all in \(\{1, 2, \dots, 6\}\). The largest sum of two distinct elements of \(\{1, 2, \dots, 6\}\) is \(5+6=11 \lt 13\), so no two chosen elements sum to \(13\). Therefore no \(n \leq 6\) guarantees a sum of \(13\), and \(7\) is the minimum.

Problem 3

A coding system encodes messages using an \(n\)-digit octal (base 8) string. A code is considered valid if and only if it contains an even number of 7s. For example, when \(n=4\), 6767, 0016, and 7777 are valid codes, whereas 0175, 7771 and 6765 are not valid.

  1. How many valid codes of length \(n=4\) are there?
  2. Write a recursive formula for \(a_n\), where \(a_n\) is the number of valid codes for length \(n\).
Show solution
  1. This can be calculated two ways.

    First way:

    The number of codes with exactly zero \(7\)s \(= 7^4.\)

    The number of codes with exactly two \(7\)s: Firstly, out of the 4 positions, we can choose positions for two \(7\)s in \(\binom{4}{2}\) ways, and the remaining two positions can be filled in \(7^2\) ways. Therefore, there are \(\binom{4}{2} \cdot 7^2\) codes with exactly two \(7\)s.

    The number of codes with exactly four \(7\)s \(= 1.\)

    Therefore, there are \(7^4 +\binom{4}{2} \cdot 7^2 + 1\) valid codes.

    Second way:

    There are \(8^4\) total octal codes (valid and invalid).

    The number of codes with exactly one \(7\) is \(\binom{4}{1} \cdot 7^3\).

    The number of codes with exactly three \(7\) is \(\binom{4}{3} \cdot 7^1\).

    Therefore, there are \(8^4 - \binom{4}{1} \cdot 7^3 - \binom{4}{3} \cdot 7 = 2696\) valid codes (matching the first way: \(7^4 + \binom{4}{2}\cdot 7^2 + 1 = 2696\)).

  2. A valid string of length \(n\) can be constructed from valid and invalid strings of length \(n-1.\)

    Assume there are \(a_{n-1}\) valid strings of length \(n-1\). To construct a valid string of length \(n\) from a valid string of length \(n-1,\) the \(n\)-th must be a valid digit. There are 7 ways of picking this \(n\)-th digit. Therefore, there are \(7a_{n-1}\) such valid strings.

    There are \(8^{n-1} - a_{n-1}\) invalid strings of length \(n-1\). To construct a valid string of length \(n\) from these invalid strings of length \(n-1\), the \(n\)-th digit must be a 7. Therefore there are \(8^{n-1} - a_{n-1}.\)

    Therefore, \(a_n = 7a_{n-1} + 8^{n-1} - a_{n-1} = 6a_{n-1} + 8^{n-1},\) when \(n > 1.\)

    Therefore the recursive relationship of \(a_n= 6a_{n-1} + 8^{n-1}\) \((n > 1)\), \(a_1 = 7.\)