Discrete Mathematics

The reasoning toolkit the rest of computer science quietly assumes: logic, proof, sets and relations, counting, recurrences and the number theory behind cryptography.

If you remember nothing else

  • The contrapositive of p → q is ¬q → ¬p, and it is logically equivalent; the converse q → p is not.
  • p → q is false in exactly one case: p true and q false. A false premise makes the implication vacuously true.
  • An equivalence relation is reflexive, symmetric and transitive, and it partitions its set into disjoint classes.
  • Permutations count arrangements (order matters), combinations count selections (order does not): C(n,r) = P(n,r)/r!.
  • The pigeonhole principle: n+1 items in n boxes force some box to hold at least two — the basis of most 'prove there exist two…' questions.
  • The handshake lemma: the sum of all vertex degrees equals twice the number of edges, so the count of odd-degree vertices is always even.

Propositional logic

A proposition is a declarative statement with a definite truth value. Connectives build compound propositions, and a truth table settles any question about them mechanically.

ConnectiveSymbolRead asTrue when
Negationnot pp is false
Conjunctionp and qboth are true
Disjunctionp or qat least one is true
Exclusive orp xor qexactly one is true
Implicationif p then qalways, except when p is true and q is false
Biconditionalp if and only if qboth have the same truth value
FormStatementEquivalent to the original?
Original
ConverseNo
InverseNo (it is the converse's contrapositive)
ContrapositiveYes — always

"If it rains, the ground is wet" does not mean "if the ground is wet, it rained" (converse). It does mean "if the ground is not wet, it did not rain" (contrapositive).

Equivalences worth memorising

LawForm
De Morgan and
Distributive
Implication
Contrapositive
Absorption
Double negation

Predicate logic and quantifiers

Propositional logic cannot express "every student passed" — it has no way to talk about individuals. Predicate logic adds predicates and quantifiers over a domain.

  • Universal — P holds for every element. A single counterexample makes it false.
  • Existential — P holds for at least one element. One witness makes it true.
  • Negation rules: , and . Pushing a negation inward flips the quantifier.
Rule of inferenceFormName
From and , infer Affirm the premiseModus ponens
From and , infer Deny the conclusionModus tollens
From and , infer ChainHypothetical syllogism
From and , infer EliminateDisjunctive syllogism

Proof techniques

TechniqueTo proveMethodUse when
DirectAssume p, derive qThe implication is straightforward
ContrapositionAssume , derive The negation is easier to work with
ContradictionAny statement sAssume , derive an absurdityProving something does not exist
Induction for all Base case, then The claim is indexed by a natural number
Strong induction for all nAssume , prove The step needs more than the previous case
CounterexampleExhibit one x with Disproving a universal claim

Sets, relations and functions

  • The power set of a set with n elements has elements — including the empty set and the set itself.
  • Cardinality of a union: (inclusion-exclusion).
  • The Cartesian product has ordered pairs.
  • A relation on A is any subset of ; with n elements there are possible relations.
PropertyDefinitionExample
Reflexive, "is equal to", "divides"
Symmetric"is a sibling of"
Antisymmetric and both in R "", "is a subset of"
Transitive and in R "", "is an ancestor of"
Function typeConditionConsequence
Injective (one-to-one)Distinct inputs give distinct outputs
Surjective (onto)Every element of the codomain is hit
BijectiveBoth; an inverse exists

Counting and combinatorics

RuleFormulaUse
Product ruleIndependent sequential choices
Sum ruleMutually exclusive alternatives
PermutationArrange r of n — order matters
CombinationChoose r of n — order does not matter
With repetition (arrange)r positions, n choices each
With repetition (choose)r items from n types, repeats allowed
Circular permutationSeat n people around a table

Two principles that carry whole questions

  • Pigeonhole principle — placing objects into boxes forces some box to contain at least two. Generalised: objects in boxes force some box to hold at least . Standard use: among any 13 people, two share a birth month.
  • Inclusion-exclusion. Add the singles, subtract the pairs, add the triples, alternating.

Graph theory

  • Handshake lemma. Every edge contributes 2 to the total degree, so the number of odd-degree vertices is always even.
  • A complete graph has edges. A tree on n vertices has exactly edges and is connected and acyclic — any two of those three properties imply the third.
  • A bipartite graph has no odd-length cycle; equivalently, it is 2-colourable.
  • A graph is planar if it can be drawn without crossings. Euler's formula: for a connected planar graph. By Kuratowski's theorem, a graph is planar iff it contains no subdivision of or .
  • By the four colour theorem, every planar graph is 4-colourable.

Recurrence relations

A recurrence defines a term from earlier terms. Solving it means finding a closed form — which for algorithm analysis is exactly the running time.

  1. Substitution (iteration)

    Expand the recurrence repeatedly until the pattern is visible, then apply the base case. expands to .
  2. Characteristic equation

    For a linear homogeneous recurrence such as , substitute to get , giving roots 2 and 3, so with A and B fixed by the initial conditions.
  3. Master theorem

    For divide-and-conquer recurrences , compare against and read off the case. Covered in full in the Data Structures & Algorithms subject.
RecurrenceClosed formArises in
Linear search
Bubble sort, insertion sort worst case
Binary search
Mergesort
Towers of Hanoi

Number theory essentials

  • means m divides . Congruences may be added and multiplied, but not divided freely.
  • Euclid's algorithm: , terminating when the remainder is 0. It runs in .
  • .
  • Euler's totient counts integers in coprime to n. For a prime p, ; for distinct primes p and q, .
  • Fermat's little theorem: if p is prime and p does not divide a, then .
  • A modular inverse of a mod m exists iff ; the extended Euclidean algorithm finds it.
CEuclid, both ways
int gcd(int a, int b) { // iterative while (b) { int t = b; b = a % b; a = t; } return a; } int gcd_rec(int a, int b) { // recursive - the definition itself return b == 0 ? a : gcd_rec(b, a % b); } // gcd(48, 18) -> gcd(18, 12) -> gcd(12, 6) -> gcd(6, 0) = 6

Self-check

10 questions on Discrete Mathematics · nothing is stored

0/10 answered
Question 1

1.Which of these is logically equivalent to p → q?

Question 2

2.The statement "if 2 is odd, then 3 is even" is:

Question 3

3.A relation that is reflexive, antisymmetric and transitive is:

Question 4

4.How many distinct arrangements are there of the letters in BANANA?

Question 5

5.In any undirected graph, the number of vertices with odd degree is:

Question 6

6.∀x ∃y Loves(x, y) differs from ∃y ∀x Loves(x, y) because:

Question 7

7.A set with 5 elements has a power set of size:

Question 8

8.An Euler circuit exists in a connected graph if and only if:

Question 9

9.Concluding p from p → q and q is:

Question 10

10.A modular inverse of a modulo m exists precisely when: