Discrete Mathematics Cheatsheet

Quick reference for logic operators, set operations, combinatorics formulas, and graph theory.

LogicSet TheoryGraph TheoryCombinatorics
NotesCheatsheet

Propositional Logic

OperatorSymbolTrue when…Code
AND (conjunction)Both P and Q are true&&
OR (disjunction)At least one of P, Q is true||
NOT (negation)¬P is false!
IMPLIESP false, OR both P and Q true (false only when P=T, Q=F)!p || q
IFF (biconditional)P and Q have the same truth valuep === q
XOR (exclusive or)Exactly one of P, Q is truep !== q

Key Equivalences (De Morgan's)

¬(P ∧ Q)  ≡  ¬P ∨ ¬Q      // NOT (A AND B) = (NOT A) OR (NOT B)
¬(P ∨ Q)  ≡  ¬P ∧ ¬Q      // NOT (A OR B)  = (NOT A) AND (NOT B)

// Contrapositive (always equivalent to original implication):
P → Q  ≡  ¬Q → ¬P

// Tautology: always true (P ∨ ¬P)
// Contradiction: always false (P ∧ ¬P)

Set Theory

OperationNotationMeaning
UnionA ∪ BElements in A or B (or both)
IntersectionA ∩ BElements in both A and B
DifferenceA − BElements in A but not in B
ComplementAᶜElements NOT in A (within universe U)
Power Set𝒫(A)All subsets of A; |𝒫(A)| = 2^|A|
Cartesian ProductA × BAll ordered pairs (a, b) where a∈A, b∈B
// Inclusion-Exclusion (avoid double-counting)
|A ∪ B| = |A| + |B| − |A ∩ B|
|A ∪ B ∪ C| = |A| + |B| + |C| − |A∩B| − |A∩C| − |B∩C| + |A∩B∩C|

Combinatorics Formulas

FormulaNameWhen to use
n!FactorialArrange n distinct items in a row
P(n,r) = n!/(n-r)!PermutationOrdered selection of r from n
C(n,r) = n!/r!(n-r)!CombinationUnordered selection of r from n
n₁ × n₂ × … × nₖMultiplication rulek independent choices
⌈n/k⌉Pigeonhole Principlen items in k boxes → ≥⌈n/k⌉ share a box

Graph Theory Terms

TermDefinition
DegreeNumber of edges incident to a vertex; sum of all degrees = 2|E|
PathSequence of distinct vertices connected by edges
CyclePath that starts and ends at the same vertex
ConnectedEvery vertex is reachable from every other (undirected)
TreeConnected acyclic undirected graph; n nodes → n-1 edges
BipartiteVertices split into two sets; edges only between sets (no odd cycles)
PlanarCan be drawn without crossing edges; Euler: V - E + F = 2
DAGDirected Acyclic Graph — used for scheduling, build deps, topological sort

Proof Techniques

// Direct proof: assume P, derive Q step by step
// "If n is even, n² is even"
// Assume n = 2k → n² = 4k² = 2(2k²) → even ✓

// Proof by contradiction: assume ¬Q, derive contradiction
// "√2 is irrational": assume √2 = p/q (fully reduced)
// → 2 = p²/q² → p² = 2q² → p even → p = 2m
// → 4m² = 2q² → q² = 2m² → q even → contradiction (both even, not reduced)

// Proof by induction:
// Base case: show P(1) is true
// Inductive step: assume P(k), prove P(k+1)
// "Sum 1..n = n(n+1)/2":
// Base: n=1 → 1 = 1(2)/2 = 1 ✓
// Step: assume S(k) = k(k+1)/2
//        S(k+1) = k(k+1)/2 + (k+1) = (k+1)(k+2)/2 ✓

Relation Properties

PropertyConditionExample
Reflexive(a, a) ∈ R for all aa ≤ a (always true)
Symmetric(a,b) ∈ R → (b,a) ∈ Ra is friend of b ↔ b is friend of a
Transitive(a,b), (b,c) ∈ R → (a,c) ∈ Ra ≤ b and b ≤ c → a ≤ c
EquivalenceReflexive + Symmetric + TransitiveCongruence mod n; same birthday

Key Rules

  • P → Q is only false when P is true and Q is false. (A broken promise: I said I would, and I didn't.)
  • Contrapositive (¬Q → ¬P) is logically equivalent to P → Q — often easier to prove.
  • Permutation = order matters; Combination = order doesn't matter. C(n,r) = P(n,r) / r!
  • Tree: n vertices → exactly n-1 edges; connected and acyclic.
  • Mathematical induction = the domino principle: prove the first falls, prove each one knocks over the next.