Cheatsheet

Discrete Mathematics

All topics on one page

5modules
15articles
5definitions
34formulas

01

Sets and Relations

Set theory, binary relations, order, and equivalence

Set Theory and Operations

The Language of Mathematics → Operations on Sets → Cardinality of Sets → Cartesian Product → Axiomatic Systems: ZF and ZFC → Cantor's Hierarchy of Infinities → Applications of Set Theory in Computer Science → Cardinality of Sets and Cantor's Theorem → Numerical Example: Cantor's Diagonal Argument

Formulas

De Morgan's Laws: $(A \cup B)^c = A^c \cap B^c$; $(A \cap B)^{\complement} = A^c \cup B^c$.Step 1: $P(\{1,2,3\}) = \{\emptyset, \{1\}, \{2\}, \{3\}, \{1,2\}, \{1,3\}, \{2,3\}, \{1,2,3\}\}$—8 elements. $|\{1,2,3\}|=3$.Step 2: Try a bijection $f: 1 \mapsto \{1,3\},\ 2 \mapsto \{2\},\ 3 \mapsto \{1,2,3\}$. Construct $D = \{n \in \{1,2,3\} : n \notin f(n)\}$.

Set theory is the universal language of mathematics. All mathematical objects—numbers, functions, structures—can be defined through sets.

Georg Cantor created set theory in the 1870s, despite opposition from conservative mathematicians. David Hilbert called his theory "a paradise from which we shall not be driven."

Union: $A \cup B = \{x : x \in A \text{ or } x \in B\}$. Intersection: $A \cap B = \{x : x \in A \text{ and } x \in B\}$. Difference: $A \setminus B = \{x : x \in A,\ x \notin B\}$. Symmetric difference: $A \bigtriangleup B = (A \setminus B) \cup (B \setminus A)$. Complement: $A^c = U \setminus A...

De Morgan's Laws: $(A \cup B)^c = A^c \cap B^c$; $(A \cap B)^{\complement} = A^c \cup B^c$.

Binary Relations and Their Properties

Definition → Equivalence Relations → Order Relations → Hasse Diagrams → Properties of Order Relations: Minima and Maxima → Functions and Their Properties → Applications of Relation Theory in Computer Science → Euler's Functions and Rings of Residues → Lattices and Applications to Cryptography → Numerical Example: Equivalence Relations and Partial Order

  • ·Reflexivity: $aRa$ for all $a$.
  • ·Antireflexivity: not $aRa$ for any $a$.
  • ·Symmetry: $aRb \to bRa$.
  • ·Antisymmetry: $aRb$ and $bRa \to a = b$.
  • ·Transitivity: $aRb$ and $bRc \to aRc$.

A binary relation $R$ on $A$ is a subset of $A \times A$. We write $aRb$ or $(a, b) \in R$.

Equivalence class: $[a] = \{b: b \sim a\}$. The classes form a partition of $A$ (pairwise disjoint, cover $A$).

Examples: Equality modulo $n$: $a \sim b \iff n \mid (a-b)$. Classes: $\{0, n, 2n, \ldots\}$, $\{1, n+1, 2n+1, \ldots\}$, ..., $\{n-1, 2n-1, \ldots\}$.

Partial order (poset): reflexive, antisymmetric, transitive. Example: divisibility on $\mathbb{N}$.

Lattices and Boolean Algebras

Lattice → Boolean Algebra → Boolean Functions → Huntington Algebra and Lattice Identities → Minimization of Boolean Functions: Practice → Applications of Boolean Algebra in EDA and Verification → Finite Fields and Reed–Solomon Codes → Boolean Circuit Complexity → BDD and Symbolic Representation of Boolean Functions → Numerical Example: Boolean Function Minimization

Formulas

Problem: Minimize $f(a,b,c)$ with truth table: $f=1$ for $(a,b,c)\in\{(0,0,1),(0,1,1),(1,0,1),(1,1,1)\}$.Step 2: Karnaugh map (3 variables): the $c=1$ column is completely filled with ones — one group of 4.
  • ·sup{a,b} = a∨b (join, least upper bound)
  • ·inf{a,b} = a∧b (meet, greatest lower bound)

A partially ordered set L is a lattice if for any two elements a, b there exist:

Examples: (2^A, ⊆) — the lattice of subsets. (ℕ, |) — the lattice under divisibility: a∨b = LCM(a,b), a∧b = GCD(a,b). Subspaces in a vector space.

A distributive complemented lattice: the distributive laws hold, $a\land(b\lor c) = (a\land b)\lor(a\land c)$, and complement $a^c$ such that $a\land a^c = 0$, $a\lor a^c = 1$.

Stone's Theorem: Every finite Boolean algebra is isomorphic to the power set algebra of some finite set. The size is a power of two.

02

Boolean Functions and Post's Theorem

Completeness of systems of Boolean functions, closed classes

Normal Forms and Post's Theorem

SDNF and SCNF → Post's Completeness Theorem → Applications → The Five Closed Post Classes: Details → Complexity of Completeness Recognition → Zhegalkin Polynomials → Completeness Theorem for Many-Valued Logics → Quantum Logic Gates: Generalization of Boolean → Quantum Entanglement and Its Computational Implications → Numerical Example: Normal Forms and Functional Completeness

Formulas

Task: (a) Represent f(a,b)=a∧¬b in DNF and CNF. (b) Check if {⊕,1} (XOR and constant 1) is complete.Step 1 (Normal Form): Truth table for f(a,b): (0,0)=0, (0,1)=0, (1,0)=1, (1,1)=0. One unit minterm: (1,0).
  • ·T₀: functions preserving 0 (f(0,...,0)=0)
  • ·T₁: functions preserving 1 (f(1,...,1)=1)
  • ·S: self-dual (f(¬x₁,...,¬xₙ) = ¬f(x₁,...,xₙ))
  • ·M: monotone (xᵢ ≤ yᵢ → f(x) ≤ f(y))
  • ·L: linear (over GF(2))

SDNF (perfect disjunctive normal form): disjunction of minterms. A minterm is the conjunction of all variables (with or without negations) corresponding to a row of the truth table with f=1.

SCNF (perfect conjunctive normal form): conjunction of maxterms (disjunctions for rows with f=0).

A closed class of functions is a set F closed under superposition (substitution, identification of variables).

Post's theorem: A system F of functions is complete if and only if it is not contained in any of the five classes.

Combinatorics: The Principle of Inclusion-Exclusion

Fundamental Counting Principles → Principle of Inclusion-Exclusion → Generating Functions → Principle of Double Counting and Identities → The Method of Arrangements with Repetitions and Multisets → Principle of Inclusion-Exclusion: Generalization and Applications → Extremal Combinatorics → Lovász’s Lemma: The Algebraic Geometry Method in Combinatorics → Error-Correcting Codes: Constructions → Extremal Combinatorics and Hypergroup Testing

Definitions

Multiset
a collection with repetitions. The number of $k$-element submultisets of an $n$-element set: $C(n+k-1, k)$ = “stars and bars”. Interpretation: distribute $k$ indistinguishable balls into $n$ distinguishable boxes. Example: the number of solutions ...

Formulas

Sum Rule: if A and B are disjoint, $|A \cup B| = |A| + |B|$.Euler's totient function $\varphi(n)$: number of $m \leq n$ with $\gcd(m, n) = 1 = n \prod_{p|n} (1 - 1/p)$.Step 3: Triple intersection: $|A_2 \cap A_3 \cap A_5| = \lfloor 120/30 \rfloor = 4$.

Sum Rule: if A and B are disjoint, $|A \cup B| = |A| + |B|$. Product Rule: sequential choices $k_1, k_2, ...$: $k_1 \cdot k_2 \cdot ...$

Arrangements $A(n, k) = \frac{n!}{(n - k)!}$ (ordered selection of $k$ out of $n$). Combinations $C(n, k) = \frac{n!}{k!(n-k)!}$ (unordered selection).

$|A_1 \cup A_2 \cup ... \cup A_n| = \sum |A_i| - \sum |A_i \cap A_j| + \sum |A_i \cap A_j \cap A_k| - ...$

Number of derangements (permutations with no fixed points): $ D(n) = n! \sum_{k=0}^n \frac{(-1)^k}{k!} \approx \frac{n!}{e} $

Recurrence Relations

Linear Recurrences → General Method → Master Theorem → Linear Recurrences with Repeated Roots → Recurrences and Combinatorial Interpretations → Master Theorem: Boundary Cases and Generalizations → Solving Linear Recurrences: An Algebraic View → Recurrences in Algorithm Analysis: Nuances → Dynamic Programming: Probabilistic Extensions → Enumerative Combinatorics: Inclusion-Exclusion Principle

Formulas

Fibonacci numbers: $F(n) = F(n-1) + F(n-2)$, $F(0) = 0$, $F(1) = 1$.Binet's formula: $F(n) = \frac{\varphi^n - \psi^n}{\sqrt{5}}$.Application: MergeSort $T(n) = 2T(n/2) + \Theta(n)$: $a = 2$, $b = 2$, $\log_b a = 1$, $f(n) = \Theta(n) \rightarrow T(n) = \Theta(n \log n)$.Step 1: Characteristic equation: $r^2 - 5r + 6 = 0$. Discriminant: $25 - 24 = 1$. Roots: $r_1 = 2$, $r_2 = 3$.

A sequence is defined recurrently: $a(n)$ is expressed in terms of $a(n-1), ..., a(n-k)$.

Characteristic equation: $x^2 = x + 1$. Roots: $\varphi = \frac{1+\sqrt{5}}{2}$ (golden ratio), $\psi = \frac{1-\sqrt{5}}{2}$.

1. Characteristic equation: $x^k = c_1x^{k-1} + \ldots + c_k$. 2. If the roots $x_1, ..., x_k$ are distinct: $a(n) = \alpha_1 x_1^n + \ldots + \alpha_k x_k^n$. 3. Coefficients are obtained from initial conditions.

For repeated roots $x_i$ of multiplicity $m_i$: the term $x_i^n(\alpha_0 + \alpha_1 n + \ldots + \alpha_{m_i-1} n^{m_i-1})$ appears.

03

Graph Theory

Connectivity, trees, planarity, colorings

Graphs: Basic Concepts and Theorems

Definition and Types → Paths and Connectivity → Trees → Kirchhoff Numbers → Spectral Graph Theory → Graph Algorithms: Practice → Graph Theory Problems in Computer Science → Planarity: Planarity Algorithm and Euler’s Formula → Hypergraphs and Their Applications → Numerical Example: Dijkstra’s Algorithm

Definitions

Tree
a connected graph without cycles. Equivalent conditions (for n vertices):

Formulas

Graph G = (V, E): V is the set of vertices, E is the set of edges (pairs of vertices).Step 2: Extract A (d=0). Update neighbors: d(B)←min(∞,0+4)=4; d(C)←min(∞,0+2)=2.Step 3: Extract C (d=2). Update: d(B)←min(4,2+1)=3; d(D)←min(∞,2+8)=10.Step 4: Extract B (d=3). Update: d(D)←min(10,3+5)=8. Extract D (d=8). Done.
  • ·Any two vertices are connected by a unique path
  • ·Connected and adding any edge creates a cycle

Graph G = (V, E): V is the set of vertices, E is the set of edges (pairs of vertices).

Degree of a vertex deg(v) — the number of edges incident to v. Handshaking Lemma: Σ deg(v) = 2|E| (each edge contributes 2 to the sum of degrees). Corollary: the number of vertices of odd degree is even.

Walk: a sequence of vertices v₀, v₁, ..., vₖ with edges v_{i-1}v_i. Path: a walk with no repeated vertices.

Shortest paths: Dijkstra's algorithm (non-negative weights) O((V+E)log V); Bellman–Ford (allows negatives) O(VE); Floyd–Warshall (all pairs) O(V³).

Planarity and Graph Coloring

Planar Graphs → Graph Coloring → Ramsey’s Theorem → Chromatic Polynomial and Algebraic Methods → Ramsey Theorem: Exact Values → Bipartiteness and Bipartite Matching Algorithm → The Five Color Theorem: Constructive Proof → Directed Graphs and Reachability Problems → Numerical Example: Strongly Connected Components

Formulas

Euler's formula: For a connected planar graph, $V - E + F = 2$, where $F$ is the number of faces (including the outer face).Graph $K_5$ (complete graph on 5 vertices): $E=10$, $3V-6=9$. Therefore, $K_5$ is non-planar.Graph $K_{3,3}$ (complete bipartite 3+3): $E=9$, $2V-4=8$ (bipartite). Non-planar.Step 1: DFS from 1: discovery numbers $d[1]=0$, $d[2]=1$, $d[3]=2$, $d[4]=3$, $d[5]=4$. Stack: [1,2,3,4,5].Step 2: At vertex 5: edge $5 \to 4$, $d[4]=3 < d[5]$ $\to$ back edge. $low[5]=\min(4,3)=3$. $d[5]=low[5]$? No $(4 \ne 3)$. Return to 4.

A graph is planar if it can be drawn on the plane without any edge crossings.

Euler's formula: For a connected planar graph, $V - E + F = 2$, where $F$ is the number of faces (including the outer face).

Corollary: $E \le 3V - 6$ (for $V \ge 3$). If there are no triangles: $E \le 2V - 4$.

Graph $K_5$ (complete graph on 5 vertices): $E=10$, $3V-6=9$. Therefore, $K_5$ is non-planar.

Eulerian and Hamiltonian Graphs. Flows in Networks

Eulerian Paths → Hamiltonian Paths → Flows in Networks → Ford–Fulkerson Algorithm: Details and Correctness → Eulerian Circuits: Fleury's Algorithm → Hamiltonian Paths and the Traveling Salesman Problem → Edge Coloring (Chromatic Index) → Perfect Graph Theory → Random Graphs: Erdős–Rényi Model → Expander Graphs and Their Applications

Definitions

Eulerian path
a route that traverses each edge exactly once.
Hamiltonian path
a path passing through every vertex exactly once.
G(n,p)
random graph on n vertices, each edge independently with probability p. Threshold theory: if p < (1−ε)ln(n)/n the graph is almost surely not connected, if p > (1+ε)ln(n)/n — almost surely connected. Triangle threshold: p ~ n^{−1}. Hamiltonian cycl...

Formulas

Step 3: E[number of isolated vertices] = 100·0.0105 ≈ 1.05. Exactly at the threshold we expect about 1 isolated vertex.

Euler's Theorem (1736): A graph has an Eulerian cycle if and only if it is connected and all vertices have even degree.

An Eulerian path (not cycle) exists ⟺ the graph is connected and exactly 2 vertices have odd degree.

The Königsberg bridges problem: seven bridges over a river — is it possible to cross each one exactly once? Four islands, all with odd degree → no.

Unlike Eulerian: there is no simple criterion! The problem of finding a Hamiltonian cycle is NP-complete.

04

Combinatorics

Inclusion–exclusion principle, generating functions

Enumerative Combinatorics

Counting Problems → Integer Partitions → Vandermonde's Combinatorial Identity → Burnside's Lemma → Combinatorics on Words and Sequences → The Generating Functions Method for Complex Enumerations → Bell Numbers and Set Partitions → Pólya's Theorem and Enumeration with Symmetries → Asymptotics of Partitions and the Hardy–Ramanujan Formula → Symmetry Groups and Applications in Chemistry

Formulas

Problem 1: Partitions for $n=6$ — how many are there? Problem 2: Coloring a necklace of 4 beads with 3 colors, counting rotations.Step 2 (partitions): Check by Euler’s recurrence: $p(6)=p(5)+p(4)-p(1)=7+5-1=11$. ✓

Combinatorics answers the question: "How many?" — how many different objects of a given type exist. This is fundamental for algorithm theory, cryptography, and statistics.

The number of surjective functions from an n-element set to an m-element set (m ≤ n): $S(n,m) = \sum_{k=0}^m (-1)^k C(m,k)(m-k)^n$.

Stirling numbers of the second kind $S(n,k)$ denote the number of ways to partition an n-element set into k non-empty subsets. Recurrence: $S(n,k) = k \cdot S(n-1,k) + S(n-1,k-1)$.

A partition of a number $n$ is a way of representing $n$ as a sum of natural numbers (without regard to order).

Generating Functions and Their Applications

Ordinary Generating Functions → Exponential Generating Functions → Linear Recurrences and Fractions → Analytic Methods → Generating Functions for Algorithm Analysis → Random Structures via Generating Functions → Estimates for Nontrivial Enumerative Problems → Block Designs and Experimental Design → Coding in Finite Fields → Combinatorial Proofs of Identities

Formulas

Number of partitions into odd parts = number of partitions into distinct parts (remarkable Euler’s identity).

Number of partitions of the number n into parts 1,2,3,...: ∏ₖ₌₁^∞ 1/(1−xᵏ) = Σₙ p(n)xⁿ.

Number of partitions into odd parts = number of partitions into distinct parts (remarkable Euler’s identity).

F(n) (Fibonacci numbers) → f(x) = x/(1−x−x²) = x/((1−φx)(1−ψx)). Decomposition into partial fractions → Binet’s formula.

Saddle point method (Laplace): for the coefficient [xⁿ]f(x) at large n — asymptotics via the saddle point of f.

Extremal Combinatorics

Extremal Problems → The Pigeonhole Principle (Box Principle) → Ramsey and Gelfand Theorems → The Green–Tao Theorem and Primes in AP → Ultrametrics and Metric Ramsey Results → Polychromatic Ramsey Numbers → Combinatorial Games and the Hex Theorem → Game Theory and Combinatorial Games: Grundy Numbers → Alphabetic Games and Codes → Deterministic Cellular Automata

Extremal combinatorics: how large or small can an object with given properties be?

Turán's Theorem: The maximum number of edges in a $K_{r+1}$-free graph on $n$ vertices: $e \leq (1 - 1/r) \cdot n^2/2$. Achieved on the complete $r$-partite Turán graph $T(n, r)$.

Erdős's Distinct Distances Problem: $n$ points in the plane determine at least $c\sqrt{n}$ distinct distances.

If $n$ objects are placed into $m$ boxes and $n > m$, then some box contains at least 2 objects.

05

Automata and Formal Languages

Finite automata, regular languages, Kleene’s theorem

Finite Automata and Regular Languages

Deterministic Finite Automaton (DFA) → Nondeterministic Automata (NFA) → Regular Languages and Expressions → Minimal Automata and Syntactic Monoids → Deterministic vs. Nondeterministic Automata → Regular Languages and Boolean Algebra → ω-Automata and Infinite Languages → Formal Grammars and Natural Languages → Regular Expressions and Their Computational Complexity → Automata and Cryptographic Stream Ciphers

Formulas

Example: DFA for binary strings divisible by 3: states — residues {0, 1, 2}. q₀ = F = {0}. δ(q, 0) = 2q mod 3, δ(q, 1) = (2q+1) mod 3.Task: Construct a DFA for L={w∈{0,1}*: w ends with “01”} and check several strings.Step 2: Transition table: δ(q₀,0)=q₁; δ(q₀,1)=q₀; δ(q₁,0)=q₁; δ(q₁,1)=q₂; δ(q₂,0)=q₁; δ(q₂,1)=q₀.

DFA = (Q, Σ, δ, q₀, F): Q — the set of states, Σ — the alphabet, δ: Q×Σ → Q — the transition function, q₀ — the initial state, F ⊆ Q — accepting states.

Example: DFA for binary strings divisible by 3: states — residues {0, 1, 2}. q₀ = F = {0}. δ(q, 0) = 2q mod 3, δ(q, 1) = (2q+1) mod 3.

Theorem (Rabin–Scott): DFA and NFA are equivalent in recognized languages (subset construction).

Kleene’s Theorem: A language is regular ⟺ recognized by a DFA ⟺ defined by a regular expression.

Context-Free Languages and Grammars

CFG and CFL → Pushdown Automata → Chomsky Hierarchy → Algorithmic Problems → Normal Forms of CFG and CYK Algorithm → Chomsky Hierarchy → Deterministic CFL and Parsing → Pumping Lemma for CFL → Attribute Grammars → Transducers and Translating Automata

Formulas

Task: CFG G: S→AB, A→a, B→b. String w="ab". Does w belong to L(G)?
  • ·Type 3: DFA / regular expressions.
  • ·Type 2: PD automata / CFG (grammars of programming languages).
  • ·Type 1: Linear-bounded TM (LBA).
  • ·Type 0: Arbitrary TM.

A context-free grammar G = (V, Σ, R, S): V — nonterminals, Σ — terminals, R — rules of the form A → α (A∈V, α∈(V∪Σ)*), S — start nonterminal.

Chomsky normal form: A → BC or A → a. Every CFG is equivalent to a grammar in CNF.

PDA = (Q, Σ, Γ, δ, q₀, Z₀, F): a stack (pushdown store) with alphabet Γ is added.

CFLs are closed under: union, concatenation, Kleene star. Not closed under: intersection, complement (in general).

Turing Machines and Computational Complexity

Turing Machine → Complexity Classes → Undecidable Problems → Turing Machine: Details and Variants → Gödel’s Theorem and Incompleteness → Descriptive Complexity and Algorithmic Information → Undecidability: The Halting Problem and Its Consequences → Complexity and Provability: Gödel’s Theorem → Quantum Computability and Complexity → Oracle Models and the Hierarchy of Complexity Classes

Formulas

P = NP? The key open problem of Computer Science. Most mathematicians believe P ≠ NP, but there is no proof.Step 2: Build machine D(M): if H(M,M)=“yes”, then D loops; if H(M,M)=“no”, then D halts in 1 step.Step 3: Run D(D). Case A: H(D,D)=“yes” (D halts on D) → by construction, D loops — contradiction. Case B: H(D,D)=“no” → D halts — contradiction.

TM = (Q, Σ, Γ, δ, q₀, q_accept, q_reject): Q — states, Σ — input alphabet, Γ — tape alphabet (Σ ⊆ Γ), δ: Q×Γ → Q×Γ×{L,R} — transition function. Infinite tape, read/write head.

A TM is a theoretical model of a computer. The Church–Turing thesis: anything that can be computed intuitively can be computed by a Turing machine.

NP: problems whose solutions can be verified in polynomial time. Equivalently: solvable by a nondeterministic TM in polynomial time.

NP-complete problems: every problem in NP is polynomial-time reducible to them. SAT (Cook, 1971), Clique, Coloring, TSP,...