Draw a Venn diagram and decide region by region what belongs to the set expression.
For counting problems, fill in the regions from the centre outwards: all sets, then pairs, then single sets, then the outside.
Use inclusion–exclusion as a check: |A ∪ B| = |A| + |B| − |A ∩ B|.
For a relation, test each property on every pair and give one counterexample when it fails.
For a function, count the arrows arriving at each element of B: at most one means injective, at least one surjective.
Graph theory
Handshake lemma
Σ deg(v) = 2|E|
Complete graphs
|E(Kn)| = n(n − 1)/2, |E(Km,n)| = m·n
Regular graph
|E| = n·k/2
Tree and forest
|E| = n − 1, |E| = n − c
Leaves of a tree
L = 2 + Σ (deg(v) − 2) over deg(v) ≥ 3
Euler
circuit: all degrees even; path: exactly 2 odd degrees
Hamilton circuits in Kn
(n − 1)!/2
Dijkstra update
d(v) = min(d(v), d(u) + w(u, v))
Walks of length L
(Mᴸ)ij
Method
Write down the degree of every vertex; the degrees add up to twice the number of edges.
For Euler questions, check that the graph is connected and count the vertices with odd degree.
For trees, use n − 1 edges and the handshake lemma.
For Dijkstra, keep a table of tentative distances and settle the smallest unsettled vertex each round.
For a minimum spanning tree, sort the edges by weight and skip every edge that closes a cycle (Kruskal), or grow one tree from a start vertex (Prim).
Number theory & modular arithmetic
Division with remainder
a = q·n + r, 0 ≤ r < n
Euclid
gcd(a, b) = gcd(b, a mod b)
Least common multiple
lcm(a, b) = a·b/gcd(a, b)
Inverse
a·a⁻¹ ≡ 1 (mod n), gcd(a, n) = 1
Linear congruence
a·x ≡ b → x ≡ a⁻¹·b (mod n)
Euler’s totient
φ(n) = n·∏(1 − 1/p), φ(pᵏ) = pᵏ − pᵏ⁻¹
Fermat
aᵖ⁻¹ ≡ 1 (mod p)
RSA
n = pq, φ = (p − 1)(q − 1), d = e⁻¹ mod φ, c = mᵉ mod n, m = cᵈ mod n
Method
Reduce every number modulo n first; remainders lie between 0 and n − 1.
For a gcd, divide repeatedly with Euclid’s algorithm; the last nonzero remainder is the gcd.
For an inverse, run the extended algorithm and keep the coefficient of a; add n if it is negative.
Solve a·x ≡ b by multiplying with a⁻¹; combine two congruences by writing x = r₁ + m₁k.
For powers, write the exponent in binary and square repeatedly; in RSA, d = e⁻¹ mod φ(n) with φ(n) = (p − 1)(q − 1).
2Practice problems
1.Propositional logic & proofsMedium
You want to prove (r ∨ p) → ¬q by contrapositive. Which implication do you prove instead? Click it.
(r ∨ p) → ¬q
1(r ∨ p) ∧ ¬¬q
2¬¬q → ¬(r ∨ p)
3¬(r ∨ p) → ¬¬q
4¬q → (r ∨ p)
2.Propositional logic & proofsHard
The argument with premises q → r; r and conclusion q is invalid. Click the row of the truth table that is a counterexample.
q → rr∴ q
1q = 1, r = 1
2q = 1, r = 0
3q = 0, r = 1
4q = 0, r = 0
3.Sets, relations & functionsMedium
R = {(1, 2), (3, 2), (3, 4), (4, 3)} is a relation on {1, 2, 3, 4}. What is the smallest number k of ordered pairs that must be added to R to make it transitive (the size of the transitive closure minus |R|)?
R = {(1, 2), (3, 2), (3, 4), (4, 3)}
k =
4.Sets, relations & functionsHard
The arrow diagram shows a function f: A → B with A = {1, 2, 3, 4, 5} and B = {a, b, c}. Click the description that fits f.
f = {(1, c), (2, c), (3, a), (4, b), (5, c)}
1injective, not surjective
2surjective, not injective
3bijective
4neither
5.Graph theoryMedium
A tree has 3 vertices of degree 4, 3 vertices of degree 2, and all its other vertices are leaves (degree 1). How many leaves L does it have?
3 × deg 43 × deg 2
L =
6.Graph theoryHard
Use Dijkstra’s algorithm to find the length d(F) of the shortest path from A to F in the weighted graph.
start: Aend: F
d(F) =
7.Number theory & modular arithmeticMedium
Find the inverse of 17 modulo 64: the number x with 0 < x < 64 and 17·x ≡ 1 (mod 64).
a = 17n = 64
17−1 mod 64 =
8.Number theory & modular arithmeticHard
An RSA key uses the primes p = 5 and q = 19 and the public exponent e = 13. Find the private exponent d (0 < d < φ(n)).
p = 5q = 19e = 13
d =
3Solutions
1.Propositional logic & proofs
Answer: ¬¬q → ¬(r ∨ p)
Logical equivalence: two formulas are equivalent (≡) when they have the same value in every row of the truth table. A tautology is 1 in every row, a contradiction is 0 in every row, and a contingency is neither. Useful laws: De Morgan, ¬(a ∧ b) ≡ ¬a ∨ ¬b and ¬(a ∨ b) ≡ ¬a ∧ ¬b; a → b ≡ ¬a ∨ b ≡ ¬b → ¬a (contrapositive); ¬(a → b) ≡ a ∧ ¬b; and the distributive laws, a ∨ (b ∧ c) ≡ (a ∨ b) ∧ (a ∨ c).
Parts of the implication
a = r ∨ p, b = ¬q
Contrapositive
¬b → ¬a = ¬¬q → ¬(r ∨ p)
Answer
¬¬q → ¬(r ∨ p)
The contrapositive is equivalent to the original statement, so proving it proves the statement.
2.Propositional logic & proofs
Answer: q = 0, r = 1
Quantifiers and arguments: ¬∀x P(x) ≡ ∃x ¬P(x) and ¬∃x P(x) ≡ ∀x ¬P(x). Move a negation inwards, swap every quantifier it passes, and negate the inner formula with the propositional laws, such as ¬(a → b) ≡ a ∧ ¬b. An argument is valid when the conclusion is 1 in every row in which all premises are 1. A single row with true premises and a false conclusion is a counterexample and shows the argument is invalid.
Premises and conclusion row by row
q = 1, r = 1: 1 1 | 1
q = 1, r = 0: 0 0 | 1
q = 0, r = 1: 1 1 | 0
q = 0, r = 0: 1 0 | 0
Counterexample
q = 0, r = 1
Answer
q = 0, r = 1
An argument with this form looks like a valid rule, but one row is enough to show that it is not.
3.Sets, relations & functions
Answer: k = 3
Relations: a relation R on a set X is a set of ordered pairs (x, y). R is reflexive when (x, x) ∈ R for every x in X; symmetric when (x, y) ∈ R always comes with (y, x) ∈ R; antisymmetric when (x, y) and (y, x) are both in R only if x = y; and transitive when (x, y) and (y, z) in R force (x, z) ∈ R. An equivalence relation is reflexive, symmetric and transitive, and splits X into disjoint classes.
Pairs to add
{(3, 3), (4, 2), (4, 4)}
Count
k = 3
Answer
k = 3
4.Sets, relations & functions
Answer: surjective, not injective
Functions and counting: a function f: A → B gives every element of A exactly one image in B. f is injective (one-to-one) when different elements have different images, surjective (onto) when every element of B is an image, and bijective when both hold. With |A| = m and |B| = n there are nᵐ functions, n!/(n − m)! injective ones (m ≤ n), and by inclusion–exclusion Σ (−1)ᵏ·C(n, k)·(n − k)ᵐ surjective ones. |𝒫(A)| = 2ᵐ and |A × B| = m·n.
Injective?
f(1) = f(2) = c → not injective
Surjective?
every element of B is hit → surjective
Answer
surjective, not injective
Answer
surjective, not injective
5.Graph theory
Answer: L = 8
Euler, Hamilton and trees: a connected graph has an Euler circuit (every edge once, back to the start) when every vertex has even degree, and an Euler path that is not a circuit when exactly two vertices have odd degree; the path then runs from one odd vertex to the other. A Hamilton circuit visits every vertex once; Kn has (n − 1)!/2 of them. A tree on n vertices has n − 1 edges, and a connected graph with m edges keeps a spanning tree after removing m − n + 1 edges.
Handshake lemma for a tree
L + 18 = 2(L + 6) − 2
L = 8
Answer
L = 8
Shortcut: L = 2 + Σ (d − 2) over the vertices with degree d ≥ 3.
6.Graph theory
Answer: d(F) = 19
Shortest paths and spanning trees: Dijkstra’s algorithm settles one vertex per round: the unsettled vertex with the smallest tentative distance. Its distance is then final, and every neighbour v gets d(v) = min(d(v), d(u) + w(u, v)). Kruskal’s algorithm builds a minimum spanning tree by taking the edges from light to heavy and skipping any edge that would close a cycle; Prim’s algorithm grows one tree from a start vertex by always adding the lightest edge that leaves it. A spanning tree of n vertices has n − 1 edges.
Dijkstra round by round
Each line: the vertex settled, its final distance, and the neighbours whose distance improves.
A (0): B: 13, C: 6
C (6): E: 19
B (13): D: 17, G: 28
D (17): F: 19, G: 27
E (19)
F (19)
G (27)
Shortest path
A → B → D → F
d(F) = 19
Answer
d(F) = 19
7.Number theory & modular arithmetic
Answer: 17−1 mod 64 = 49
Inverses and congruences: a has an inverse modulo n exactly when gcd(a, n) = 1. The extended Euclidean algorithm writes 1 = s·n + t·a, and then a⁻¹ ≡ t (mod n). A congruence a·x ≡ b (mod n) with gcd(a, n) = 1 has the solution x ≡ a⁻¹·b. Two congruences x ≡ r₁ (mod m₁) and x ≡ r₂ (mod m₂) with coprime moduli have one solution modulo m₁·m₂ (Chinese remainder theorem). Euler’s φ(n) counts the numbers from 1 to n that are coprime to n: φ(n) = n·∏(1 − 1/p).
Extended Euclidean algorithm
Each remainder r is written as r ≡ t·17 (mod 64).
r = 64, t = 0
r = 17, q = 3, t = 1
r = 13, q = 1, t = −3
r = 4, q = 3, t = 4
r = 1, q = 4, t = −15
Inverse
1 ≡ −15·17 (mod 64)
x = 49
check: 17·49 = 833 = 13·64 + 1
Answer
17−1 mod 64 = 49
8.Number theory & modular arithmetic
Answer: d = 61
Modular powers and RSA: compute aᵏ mod n by repeated squaring: write k in binary, square, reduce after every step and multiply the powers whose bit is 1. Fermat: aᵖ⁻¹ ≡ 1 (mod p) for a prime p not dividing a, so the exponent can be reduced modulo p − 1. RSA: choose primes p and q, n = p·q and φ(n) = (p − 1)(q − 1); the public exponent e is coprime to φ(n), and the private exponent is d = e⁻¹ mod φ(n). Encrypt with c = mᵉ mod n and decrypt with m = cᵈ mod n.