10 Advanced Topics

Discrete Structure · Unit 10

Advanced Topics

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

Advanced Topics in short

This chapter joins earlier ideas to real computing. It covers matrices of 0s and 1s, algorithms that use random choices, and arithmetic with very large numbers. It ends with uses of modular arithmetic.

Advanced Topics: notes

Boolean matrices and operations

A Boolean (zero-one) matrix has only 0 and 1 as entries. Such matrices store relations and graphs. Three operations use Boolean logic: 1 is true, 0 is false.

  • Join $A \vee B$: entry is $a_{ij} \vee b_{ij}$ (OR). Both matrices must have the same size.
  • Meet $A \wedge B$: entry is $a_{ij} \wedge b_{ij}$ (AND). Same size needed.
  • Boolean product $A \odot B$: for $A$ of size $m \times k$ and $B$ of size $k \times n$, the entry is $$c_{ij} = (a_{i1} \wedge b_{1j}) \vee (a_{i2} \wedge b_{2j}) \vee \dots \vee (a_{ik} \wedge b_{kj})$$

It is like ordinary matrix multiplication, with AND in place of multiplication and OR in place of addition.

Example (join and meet). Let $$A = \begin{bmatrix} 1 & 0 & 1 \ 0 & 1 & 0 \end{bmatrix}, \quad B = \begin{bmatrix} 0 & 1 & 0 \ 1 & 1 & 0 \end{bmatrix}$$

$$A \vee B = \begin{bmatrix} 1 & 1 & 1 \ 1 & 1 & 0 \end{bmatrix}, \quad A \wedge B = \begin{bmatrix} 0 & 0 & 0 \ 0 & 1 & 0 \end{bmatrix}$$

Example (Boolean product). Let $$A = \begin{bmatrix} 1 & 0 & 0 \ 0 & 1 & 1 \end{bmatrix}, \quad C = \begin{bmatrix} 0 & 1 \ 1 & 0 \ 0 & 0 \end{bmatrix}$$

Row 1, column 1: $(1 \wedge 0) \vee (0 \wedge 1) \vee (0 \wedge 0) = 0$. Row 1, column 2: $(1 \wedge 1) \vee (0 \wedge 0) \vee (0 \wedge 0) = 1$. Row 2, column 1: $(0 \wedge 0) \vee (1 \wedge 1) \vee (1 \wedge 0) = 1$. Row 2, column 2: $(0 \wedge 1) \vee (1 \wedge 0) \vee (1 \wedge 0) = 0$.

$$A \odot C = \begin{bmatrix} 0 & 1 \ 1 & 0 \end{bmatrix}$$

Uses.

  • The matrix of the composite relation $S \circ R$ is $M_R \odot M_S$.
  • The Boolean power $M^{[r]}$ shows which pairs are joined by a path of length $r$.
  • Transitive closure of a relation with matrix $M$ on $n$ elements is $M \vee M^{[2]} \vee \dots \vee M^{[n]}$.

Example. For $R = {(1,2), (2,3)}$ on ${1, 2, 3}$: $$M = \begin{bmatrix} 0 & 1 & 0 \ 0 & 0 & 1 \ 0 & 0 & 0 \end{bmatrix}, \quad M^{[2]} = \begin{bmatrix} 0 & 0 & 1 \ 0 & 0 & 0 \ 0 & 0 & 0 \end{bmatrix}$$

$M^{[3]}$ is all zeros. So the closure is $M \vee M^{[2]}$, which adds the pair $(1,3)$.

What this unit covers

  • Boolean matrices and operations
  • Randomized algorithms
  • Computer arithmetic with large integers
  • Modular arithmetic applications

Randomized algorithms

2082 · 10 marks

List some advantages of randomized algorithm.Given any set of ten natural numbers between 1 and 99 inclusive, prove that there are two disjoint nonempty subsets of the set with equal sums of their elements.How do you generalize permutations and combinations?[2+4+4]

Show solved answer

Randomized Algorithms, Pigeonhole Principle Proof, and Generalized Permutations & Combinations


Part 1: Advantages of Randomized Algorithms [2 marks]

  1. Simplicity: Randomized algorithms are often simpler to design and implement than their deterministic counterparts.
  2. Efficiency: They can achieve better average-case time complexity, avoiding worst-case inputs that slow deterministic algorithms.
  3. Avoidance of adversarial inputs: Since the algorithm makes random choices, no fixed input can consistently cause worst-case behavior.
  4. Useful when deterministic solutions are hard: For problems like primality testing, randomized approaches (e.g., Miller-Rabin) are practical and fast.
  5. Space efficiency: Some randomized algorithms use less memory than deterministic equivalents.

Part 2: Prove that among any 10 natural numbers from {1, ..., 99}, there exist two disjoint nonempty subsets with equal sums [4 marks]

Setup

Let $S = {a_1, a_2, \ldots, a_{10}}$ be any set of 10 distinct natural numbers chosen from ${1, 2, \ldots, 99}$.

Step 1: Count the nonempty subsets

The number of nonempty subsets of $S$ is: $$2^{10} - 1 = 1023$$

Step 2: Bound the possible sums

The maximum possible sum of any nonempty subset is at most: $$99 + 98 + 97 + 96 + 95 + 94 + 93 + 92 + 91 + 90 = 945$$

The minimum possible sum of any nonempty subset is at least $1$.

So every nonempty subset has a sum in the range ${1, 2, \ldots, 945}$, giving at most 945 distinct sum values.

Step 3: Apply the Pigeonhole Principle

We have:

  • 1023 nonempty subsets (pigeons)
  • 945 possible sum values (holes)

Since $1023 > 945$, by the Pigeonhole Principle, there exist at least two distinct nonempty subsets $A$ and $B$ of $S$ such that: $$\text{sum}(A) = \text{sum}(B)$$

Step 4: Make the subsets disjoint

If $A$ and $B$ are already disjoint, we are done.

If $A$ and $B$ share common elements, let $C = A \cap B$. Define: $$A' = A \setminus C, \quad B' = B \setminus C$$

Then:

  • $A'$ and $B'$ are disjoint (by construction).
  • Since $A \neq B$, at least one of $A'$, $B'$ is nonempty; in fact both are nonempty (if one were empty, say $A' = \emptyset$, then $A \subseteq B$, and $\text{sum}(A) = \text{sum}(B)$ would force $\text{sum}(B \setminus A) = 0$, impossible for natural numbers).
  • Their sums are equal: $$\text{sum}(A') = \text{sum}(A) - \text{sum}(C) = \text{sum}(B) - \text{sum}(C) = \text{sum}(B')$$

Therefore, $A'$ and $B'$ are two disjoint nonempty subsets of $S$ with equal sums. $\blacksquare$


Part 3: Generalization of Permutations and Combinations [4 marks]

Permutations with Repetition (Generalized Permutations)

When repetition is allowed, the number of ways to arrange $r$ objects chosen from $n$ distinct types is: $$n^r$$

When objects are not all distinct (multiset permutations): If we have $n$ objects where object type $i$ appears $n_i$ times (with $n_1 + n_2 + \cdots + n_k = n$), the number of distinct arrangements is: $$\frac{n!}{n_1!, n_2!, \cdots, n_k!}$$

Example: The number of arrangements of the letters in "MISSISSIPPI": $\frac{11!}{1!,4!,4!,2!} = 34650$

Combinations with Repetition (Generalized Combinations)

When repetition is allowed (multiset combinations): The number of ways to choose $r$ objects from $n$ types with repetition allowed (order does not matter) is: $$\binom{n + r - 1}{r} = \binom{n+r-1}{n-1}$$

Example: Choosing 3 scoops of ice cream from 5 flavors (repetition allowed): $\binom{5+3-1}{3} = \binom{7}{3} = 35$

Summary Table

TypeFormula
Permutation without repetition ($n$ distinct, choose $r$)$P(n,r) = \dfrac{n!}{(n-r)!}$
Permutation with repetition$n^r$
Multiset permutation$\dfrac{n!}{n_1!, n_2!, \cdots, n_k!}$
Combination without repetition$C(n,r) = \dfrac{n!}{r!(n-r)!}$
Combination with repetition$\dbinom{n+r-1}{r}$

These generalizations extend the basic counting principles to handle real-world scenarios where items may repeat or be indistinguishable.

Open this answer on its own page →

Boolean matrices and operations

2080.1 · 10 marks

What is Boolean matrix and list its operations?Prove that the sum of first NNN odd integers is N2N^2N2 using mathematical induction.[4+6]

--- A Boolean matrix is a matrix in which each entry is either 0 or 1 (i.e., entries belong to the set {0, 1}). It is also called a zero-one matrix or binary matrix. Example: $$A = \begin{bmatrix} 1 & 0 & 1 \ 0 & 1 & 0 \ 1 & 1 & 0 \end{bmatrix}$$ --- Let $A = [a{ij}]$ and $B = [b{ij}]$ be two B...

Open this answer on its own page →