2 Integers And Matrices

Discrete Structures · Unit 2 · 6 hrs

Integers and Matrices

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

Integers and Matrices in short

This chapter covers number theory, the branch of discrete mathematics that studies the integers and their properties, and matrices restricted to Boolean values, both of which underpin cryptography, hashing and the internal representation of numbers in a computer.

Integers and Matrices: notes

Integers

The integers, together with the operations of addition, multiplication and the ordering they carry, form the setting for divisibility, modular arithmetic, primes and the greatest common divisor, all of which computer science leans on for hashing, pseudo-random number generation, cryptography and the algorithms that manipulate binary numbers directly.

Integers and Division

For integers $a$ and $b$ with $a \neq 0$, $a$ divides $b$, written $a \mid b$, if there is an integer $c$ such that $b = ac$; $a$ is then a factor of $b$ and $b$ a multiple of $a$. For example $4 \mid 12$ since $12 = 4 \times 3$, while $5 \nmid 7$ since $7/5$ is not an integer. Divisibility satisfies: if $a \mid b$ and $a \mid c$ then $a \mid (b+c)$; if $a \mid b$ then $a \mid bc$ for any integer $c$; and if $a \mid b$ and $b \mid c$ then $a \mid c$. The first follows directly from the definition: if $b = as$ and $c = at$ for integers $s,t$, then $b + c = a(s+t)$, so $a \mid (b+c)$.

The division algorithm states that for an integer $a$ and positive integer $d$, there are unique integers $q$ (the quotient) and $r$ (the remainder) with $0 \leq r < d$ such that $a = dq + r$, written $q = a \operatorname{div} d$ and $r = a \bmod d$. For example, dividing $101$ by $11$ gives $101 = 11(9) + 2$, so the quotient is $9$ and the remainder is $2$. Dividing a negative dividend, $-11$ by $3$, gives $-11 = 3(-4)+1$, so the quotient is $-4$ and the remainder is $1$, never negative, since the remainder must satisfy $0 \le r < d$.

Modular arithmetic cares only about this remainder: two integers $a$ and $b$ are congruent modulo $m$, written $a \equiv b \pmod m$, if $m \mid (a-b)$, equivalently if $a \bmod m = b \bmod m$. For example, $17 \equiv 5 \pmod 6$ because $6 \mid (17-5)=12$, but $24 \not\equiv 14 \pmod 6$ because $6 \nmid 10$. Congruence respects addition and multiplication: if $a \equiv b \pmod m$ and $c \equiv d \pmod m$ then $a+c \equiv b+d \pmod m$ and $ac \equiv bd \pmod m$, which gives the useful shortcut $(a+b)\bmod m = \big((a \bmod m)+(b \bmod m)\big) \bmod m$ and similarly for products.

Modular arithmetic drives several applications. In hashing, a key $k$ is assigned the memory location $h(k) = k \bmod m$ for a hash table of size $m$; for $m=111$, the key $064212848$ hashes to $064212848 \bmod 111 = 14$. In pseudorandom number generation, the linear congruential method produces the sequence $x_{i+1} = (a x_i + c) \bmod m$ from a seed $x_0$; with $m=9$, $a=7$, $c=4$, $x_0=3$, the first values are $x_1 = (7\cdot3+4)\bmod 9 = 25 \bmod 9 = 7$, then $x_2 = (7\cdot7+4)\bmod 9 = 53 \bmod 9 = 8$, $x_3 = (7\cdot8+4)\bmod 9 = 60 \bmod 9 = 6$. In cryptography, the Caesar cipher shifts each letter (numbered $0$ to $25$) three places forward using $f(p) = (p+3) \bmod 26$, decrypted with $f^{-1}(p) = (p-3)\bmod 26$; the general shift cipher uses $f(p) = (p+k)\bmod 26$ for an arbitrary shift $k$.

What this unit covers

  • Integers
  • Integers and Division
  • Primes and Greatest Common Divisor
  • Extended Euclidean Algorithm
  • Integers and Algorithms
  • Applications of Number Theory (Linear Congruencies, Chinese Remainder Theorem, Computer Arithmetic with Large Integers)
  • Matrices
  • Zero-One Matrices
  • Boolean Matrix Operations

Extended Euclidean Algorithm

2081 · 5 marks

Find the GCD of 12 and 16 using Extended Euclidean Algorithm. [5]

Show solved answer

GCD of 12 and 16 using the Extended Euclidean Algorithm

Given

  • $a = 16$, $b = 12$ (arranged so larger is first)
  • Goal: find $\gcd(12,16)$ and integers $s, t$ such that $\gcd = s\cdot 12 + t\cdot 16$

Step 2 - Apply the Euclidean Algorithm (Successive Division)

StepDivisionEquation
1$16 \div 12$$16 = 1 \times 12 + 4$
2$12 \div 4$$12 = 3 \times 4 + 0$

The last non-zero remainder is $4$.

$$\gcd(12, 16) = 4$$


Step 3 - Back-Substitution (Express as Linear Combination)

From Step 1, isolate the remainder $4$:

$$4 = 16 - 1 \times 12$$

Rewrite explicitly as a linear combination of $12$ and $16$:

$$4 = (-1)\times 12 + (1)\times 16$$

So the coefficients are:

$$s = -1, \qquad t = 1$$


Check

$$s\cdot 12 + t\cdot 16 = (-1)(12) + (1)(16) = -12 + 16 = 4 \ \checkmark$$


Result

ResultValue
$\gcd(12, 16)$$4$
Linear combination$(-1)\times 12 + (1)\times 16 = 4$

$$\boxed{\gcd(12, 16) = 4 = (-1)\cdot 12 + (1)\cdot 16}$$

Open this answer on its own page →

2080 · 5 marks

Find the multiplicative inverse of 4 in $\mathbb{Z}_{11}$ using extended euclidean algorithm. [5]

  • Modulus: $n = 11$ - Element: $a = 4$ - Goal: find $x$ such that $4x \equiv 1 \pmod{11}$ We seek integers $s, t$ satisfying: $$s \cdot 4 + t \cdot 11 = \gcd(4, 11)$$ Since $\gcd(4,11) = 1$, the inverse exists, and $s \bmod 11$ is the inverse of 4. Step Division ---------------- 1
Open this answer on its own page →

2079 · 5 marks

Find the GCD of 24 and 32 using Extended Euclidean algorithm. [5]

Show solved answer

GCD of 24 and 32 Using the Extended Euclidean Algorithm

Given

  • $a = 32$, $b = 24$ (arrange larger first)
  • Goal: find $\gcd(24, 32)$ and Bezout coefficients $s, t$ such that $\gcd = s \cdot a + t \cdot b$.

Solution

Euclidean Algorithm (successive division)

StepEquationQuotientRemainder
1$32 = 1 \cdot 24 + 8$18
2$24 = 3 \cdot 8 + 0$30

The last non-zero remainder is $8$.

$$\gcd(24, 32) = 8$$

Back-Substitution (Extended part)

From Step 1:

$$32 = 1 \cdot 24 + 8$$

Solve for the remainder $8$:

$$8 = 32 - 1 \cdot 24$$

Written as a linear combination:

$$\boxed{8 = (1)\cdot 32 + (-1)\cdot 24}$$

So the Bezout coefficients are $s = 1$ (for 32) and $t = -1$ (for 24).

Verification

$$(1)\cdot 32 + (-1)\cdot 24 = 32 - 24 = 8 \checkmark$$

Final Result

$$\gcd(24, 32) = 8 = (1)\cdot 32 + (-1)\cdot 24$$

Labelling the coefficients by which number they multiply gives $s = -1$ for 24 and $t = 1$ for 32, the same combination: $8 = 32 - 24$. The GCD result of $8$ is unchanged.

Open this answer on its own page →

Boolean Matrix Operations

2081 · 5 marks

Discuss about meet and join operation between Boolean matrices. What are the values of 5 mod 75 and -5 mod 77? [5]

  • Boolean matrices: entries from ${0, 1}$. - Modular values to compute: $5 \bmod 75$ and $-5 \bmod 77$. No matrices are supplied for the meet/join, so an illustrative example is used. --- A Boolean (zero-one) matrix has all entries in ${0,1}$. Meet and join are defined entrywise using the Boo...
Open this answer on its own page →

Applications of Number Theory

2080 · 5 marks

Using Chinese remainder theorem solve the following congruences.x = 1 (MOD 3), x = 3 (MOD 5), x = 6 (MOD 7) [5]

System of congruences: $$x \equiv 1 \pmod{3}, \quad x \equiv 3 \pmod{5}, \quad x \equiv 6 \pmod{7}$$ - Residues: $a1 = 1,\ a2 = 3,\ a3 = 6$ - Moduli: $m1 = 3,\ m2 = 5,\ m3 = 7$ --- $3, 5, 7$ are distinct primes, so they are pairwise coprime. CRT guarantees a unique solution modulo their product. ...

Open this answer on its own page →

2079 · 5 marks

Use Chinese remainder Theorem to find the value of x such that x = 0 (MOD 2), x = 2 (MOD 3), x = 3 (MOD 5). [5]

$$x \equiv 0 \pmod 2, \quad x \equiv 2 \pmod 3, \quad x \equiv 3 \pmod 5$$ Moduli: $m1=2,\ m2=3,\ m3=5$. Residues: $a1=0,\ a2=2,\ a3=3$. $\gcd(2,3)=\gcd(2,5)=\gcd(3,5)=1$, so CRT applies. $$m = 2\times3\times5 = 30$$ $$M1=\frac{30}{2}=15,\quad M2=\frac{30}{3}=10,\quad M3=\frac{30}{5}=6$$ -

Open this answer on its own page →

2076 · 10 marks

Find the value of x such that x = 1 (mod 3), x = 1 (mod 4), x = 1 (mod 5) and x = 0 (mod 7) using Chinese remainder theorem.[10]

$$x \equiv 1 \pmod 3,\quad x \equiv 1 \pmod 4,\quad x \equiv 1 \pmod 5,\quad x \equiv 0 \pmod 7$$ Moduli: $m1=3,\ m2=4,\ m3=5,\ m4=7$ Remainders: $a1=1,\ a2=1,\ a3=1,\ a4=0$ All pairs $(3,4),(3,5),(3,7),(4,5),(4,7),(5,7)$ have gcd $=1$, so a unique solution exists modulo $M$. $$M = 3\times4\times...

Open this answer on its own page →

2075 · 5 marks

Find the values of x such that x = 1 (mod 5) and x = 2 (mod 7) using Chinese remainder theorem. [5]

$$x \equiv 1 \pmod{5}$$ $$x \equiv 2 \pmod{7}$$ So $a1 = 1$, $m1 = 5$; $a2 = 2$, $m2 = 7$. $\gcd(5, 7) = 1$, so CRT gives a unique solution mod $m = 5 \times 7 = 35$. $$m = 35$$ $$M1 = \frac{35}{5} = 7, \qquad M2 = \frac{35}{7} = 5$$ Find $y1$ with $M1 y1 \equiv 1 \pmod{5}$: $$7 y1 \equiv 1 \pmod...

Open this answer on its own page →

Integers and Division

2079 · 5 marks

Find the value of $-2 \bmod 3$ and $3153^{15} \bmod 5$. Illustrate an example to show the join operation between any two Boolean matrices. [5]

  • Expression 1: $-2 \bmod 3$ - Expression 2: $3153^{15} \bmod 5$ (the garbled text "3153^{15}315" is read as $3153^{15}$) - Task 3: Illustrate the join operation between two Boolean (zero-one) matrices with an example. --- Definition: For integer $a$ and positive integer $d$, $r = a \bmod d$ sati...
Open this answer on its own page →

2080.1 · 5 marks

What is congruent modulo? Determine whether 37 is congruent to 3 modulo 7 and whether -29 is congruent to 5 modulo 17. [5]

Show solved answer

Congruent Modulo: Definition and Examples

Given Data

  • Check 1: Is $37 \equiv 3 \pmod{7}$?
  • Check 2: Is $-29 \equiv 5 \pmod{17}$?

STEP 1 - Definition

If $a$ and $b$ are integers and $m$ is a positive integer, then $a$ is congruent to $b$ modulo $m$ if $m$ divides $(a - b)$.

Notation: $$a \equiv b \pmod{m}$$

If they are not congruent, we write $a \not\equiv b \pmod{m}$.

Equivalent test: $a \equiv b \pmod{m}$ if and only if $a \bmod m = b \bmod m$.


Solution

Part 1: Is $37 \equiv 3 \pmod 7$?

Check if $7 \mid (37 - 3)$: $$37 - 3 = 34$$ $$34 = 7 \times 4 + 6$$

Since $7$ does not divide $34$ (remainder $6 \neq 0$): $$\boxed{37 \not\equiv 3 \pmod{7}}$$

Verification:

  • $37 \bmod 7 = 2$ (since $37 = 7 \times 5 + 2$)
  • $3 \bmod 7 = 3$
  • $2 \neq 3$, confirmed NOT congruent.

Note: the difference method gives the correct result, and the check $37 \bmod 7 = 2$ confirms it. (The remainder of $34 \div 7$ is $6$.)

Part 2: Is $-29 \equiv 5 \pmod{17}$?

Check if $17 \mid (-29 - 5)$: $$-29 - 5 = -34$$ $$-34 = 17 \times (-2) + 0$$

Since $17$ divides $-34$ exactly: $$\boxed{-29 \equiv 5 \pmod{17}}$$

Verification:

  • $-29 = 17 \times (-2) + 5 \Rightarrow -29 \bmod 17 = 5$
  • $5 \bmod 17 = 5$
  • $5 = 5$, confirmed congruent.

Summary

CheckDifferenceDivisible by $m$?Result
$37 \equiv 3 \pmod 7$$34$No ($34 = 7\cdot4+6$)$37 \not\equiv 3 \pmod 7$
$-29 \equiv 5 \pmod{17}$$-34$Yes ($-34 = 17\cdot(-2)$)$-29 \equiv 5 \pmod{17}$
Open this answer on its own page →

Zero-One Matrices

2078 · 5 marks

Define zero-one matrix. Explain the types of function. [5]

--- Definition: A zero-one matrix (also called a Boolean matrix) is a matrix whose entries belong only to the Boolean domain {0, 1}. That is, every element of the matrix is either 0 or 1. Boolean matrices are used to represent binary relations between a pair of finite sets. Algorithms using these...

Open this answer on its own page →