๐ŸงฉDiscrete Mathematics

Key Concepts in Discrete Structures

Study smarter with Fiveable

Get study guides, practice questions, and cheatsheets for all your subjects. Join 500,000+ students with a 96% pass rate.

Get Started

Why This Matters

Discrete structures are the fundamental building blocks that power everything from database queries to encryption algorithms to social network analysis. When you're tested on discrete mathematics, you're being evaluated on your ability to recognize which structure models which problem, understand how operations transform these structures, and apply logical reasoning to prove properties. The concepts here (sets, relations, graphs, logic) appear repeatedly across computer science, and exam questions often ask you to connect them.

These structures form a hierarchy of increasing expressiveness. Sets give you collections, relations add connections between elements, functions constrain those connections, and graphs visualize them. Logic provides the language to reason about all of it, and combinatorics counts the possibilities. Don't just memorize definitions. Know what each structure can represent and when to use one over another.


Foundational Collections and Mappings

These structures define how we group objects and establish correspondences between them.

Sets

A set is a collection of distinct objects. It's the most primitive discrete structure. You can define a set by listing its elements {1,2,3}\{1, 2, 3\} or by specifying a property {x:x>0}\{x : x > 0\}.

The fundamental operations you need to know:

  • Union (AโˆชBA \cup B): everything in AA, BB, or both
  • Intersection (AโˆฉBA \cap B): only elements in both AA and BB
  • Difference (Aโˆ’BA - B): elements in AA that are not in BB
  • Complement (Aโ€พ\overline{A}): everything in the universal set that's not in AA

Cardinality โˆฃAโˆฃ|A| measures the size of a set. Understanding finite vs. infinite sets matters for counting arguments, and the power set P(A)\mathcal{P}(A) (the set of all subsets of AA) has cardinality 2โˆฃAโˆฃ2^{|A|}.

Relations

A relation on sets AA and BB is a set of ordered pairs (a,b)(a, b) where aโˆˆAa \in A and bโˆˆBb \in B. It generalizes the idea of "is related to."

Four key properties to check for any relation on a set:

  • Reflexive: every element relates to itself (โˆ€a,(a,a)โˆˆR\forall a, (a,a) \in R)
  • Symmetric: if (a,b)โˆˆR(a,b) \in R then (b,a)โˆˆR(b,a) \in R
  • Transitive: if (a,b)โˆˆR(a,b) \in R and (b,c)โˆˆR(b,c) \in R then (a,c)โˆˆR(a,c) \in R
  • Antisymmetric: if (a,b)โˆˆR(a,b) \in R and (b,a)โˆˆR(b,a) \in R then a=ba = b

An equivalence relation is one that's reflexive, symmetric, and transitive. These partition a set into disjoint equivalence classes. On exams, look for all three properties together.

A partial order is reflexive, antisymmetric, and transitive. This models "less than or equal to" style relationships.

Functions

A function is a special relation where each input maps to exactly one output. That uniqueness constraint is what makes functions predictable and useful.

Classification determines what you can do with a function:

  • Injective (one-to-one): different inputs always give different outputs
  • Surjective (onto): every element in the codomain is hit by some input
  • Bijective (both): a perfect one-to-one correspondence, which guarantees an inverse exists

Composition fโˆ˜gf \circ g means "apply gg first, then ff." An inverse function fโˆ’1f^{-1} reverses ff, but it only exists when ff is bijective.

Compare: Relations vs. Functions: both are sets of ordered pairs, but functions require unique outputs for each input. If an exam asks whether a relation is a function, check: does any input have multiple outputs? If yes, it's not a function.


Graph-Based Structures

Graphs model pairwise relationships visually and computationally. They're essential for algorithm design and network analysis.

Graphs

A graph G=(V,E)G = (V, E) consists of a set of vertices (nodes) connected by edges. It's the go-to structure for modeling networks, dependencies, and relationships.

Types you should know:

  • Undirected: edges have no direction (friendship is mutual)
  • Directed (digraph): edges have direction (following someone on social media isn't necessarily mutual)
  • Weighted: edges carry numerical values (distances, costs)
  • Simple: no self-loops and no multiple edges between the same pair of vertices

Key properties:

  • Degree of a vertex: the number of edges connected to it. In a directed graph, you track in-degree and out-degree separately.
  • Path: a sequence of vertices connected by edges
  • Cycle: a path that starts and ends at the same vertex
  • Connectivity: a graph is connected if there's a path between every pair of vertices

The Handshaking Lemma states that the sum of all vertex degrees equals 2โˆฃEโˆฃ2|E|, since each edge contributes to the degree of two vertices.

Trees

A tree is a connected graph with no cycles. Equivalently, a tree with nn vertices has exactly nโˆ’1n - 1 edges.

Trees have a hierarchical structure with a root node and parent-child relationships, making them natural for representing recursive structures.

Special types:

  • Binary trees: each node has at most 2 children
  • Binary search trees (BSTs): left child < parent < right child, enabling efficient searching
  • Balanced trees: height is kept at O(logโกn)O(\log n) to guarantee efficient operations
  • Spanning trees: a subgraph that's a tree and includes all vertices of the original graph

Compare: Graphs vs. Trees: every tree is a graph, but trees have no cycles and exactly one path between any two nodes. For hierarchical data (file systems, org charts), trees are your structure. For general networks, use graphs.


Logical Foundations

Logic provides the formal language for reasoning about truth, validity, and proof.

Propositional Logic

A proposition is a statement that's either true or false. You combine propositions using logical connectives:

  • ยฌ\neg (NOT): flips the truth value
  • โˆง\land (AND): true only when both operands are true
  • โˆจ\lor (OR): true when at least one operand is true
  • โ†’\rightarrow (implication): pโ†’qp \rightarrow q is false only when pp is true and qq is false
  • โ†”\leftrightarrow (biconditional): true when both sides have the same truth value

Truth tables systematically evaluate compound propositions by listing all possible input combinations. They're your main tool for proving logical equivalences.

Key equivalences to memorize:

  • De Morgan's Laws: ยฌ(pโˆงq)โ‰กยฌpโˆจยฌq\neg(p \land q) \equiv \neg p \lor \neg q and ยฌ(pโˆจq)โ‰กยฌpโˆงยฌq\neg(p \lor q) \equiv \neg p \land \neg q
  • Contrapositive: pโ†’qโ‰กยฌqโ†’ยฌpp \rightarrow q \equiv \neg q \rightarrow \neg p
  • A tautology is always true; a contradiction is always false

Predicate Logic

Predicate logic extends propositional logic with variables and quantifiers:

  • Universal quantifier (โˆ€\forall): "for all" or "for every"
  • Existential quantifier (โˆƒ\exists): "there exists" or "for some"

A predicate like P(x)P(x) expresses a property of an object. This lets you write statements like "for all integers xx, if xx is even, then x2x^2 is even."

Negating quantified statements is a common exam skill:

  • ยฌ(โˆ€xโ€‰P(x))โ‰กโˆƒxโ€‰ยฌP(x)\neg(\forall x \, P(x)) \equiv \exists x \, \neg P(x)
  • ยฌ(โˆƒxโ€‰P(x))โ‰กโˆ€xโ€‰ยฌP(x)\neg(\exists x \, P(x)) \equiv \forall x \, \neg P(x)

When negating, you flip the quantifier and negate the predicate. For nested quantifiers, apply this rule from left to right.

Boolean Algebra

Boolean algebra is a two-valued system (true/false, 1/0) with operations AND, OR, and NOT. It provides the mathematical foundation of digital circuits.

Key algebraic laws for simplifying expressions:

  • Associativity, commutativity, distributivity (AND distributes over OR and OR distributes over AND)
  • Absorption: aโˆจ(aโˆงb)=aa \lor (a \land b) = a
  • Identity: aโˆจ0=aa \lor 0 = a, aโˆง1=aa \land 1 = a
  • Complement: aโˆจยฌa=1a \lor \neg a = 1, aโˆงยฌa=0a \land \neg a = 0

These laws apply directly in circuit design, programming conditionals, and database queries.

Compare: Propositional vs. Predicate Logic: propositional logic handles fixed statements ("it is raining"); predicate logic adds variables and quantifiers for statements about all or some objects ("for all days dd, if it rains on dd, the ground is wet"). Exam questions often require translating English sentences into predicate logic notation.


Counting and Recurrence

These techniques answer "how many?" questions. They're fundamental for algorithm analysis and probability.

Combinatorics

Two core formulas:

  • Permutations (order matters): P(n,r)=n!(nโˆ’r)!P(n,r) = \frac{n!}{(n-r)!}
  • Combinations (order doesn't matter): C(n,r)=n!r!(nโˆ’r)!C(n,r) = \frac{n!}{r!(n-r)!}

The inclusion-exclusion principle counts the size of unions by correcting for overcounting:

โˆฃAโˆชBโˆฃ=โˆฃAโˆฃ+โˆฃBโˆฃโˆ’โˆฃAโˆฉBโˆฃ|A \cup B| = |A| + |B| - |A \cap B|

This extends to more sets. For three sets:

โˆฃAโˆชBโˆชCโˆฃ=โˆฃAโˆฃ+โˆฃBโˆฃ+โˆฃCโˆฃโˆ’โˆฃAโˆฉBโˆฃโˆ’โˆฃAโˆฉCโˆฃโˆ’โˆฃBโˆฉCโˆฃ+โˆฃAโˆฉBโˆฉCโˆฃ|A \cup B \cup C| = |A| + |B| + |C| - |A \cap B| - |A \cap C| - |B \cap C| + |A \cap B \cap C|

The pigeonhole principle is deceptively powerful: if you place nn items into kk containers and n>kn > k, at least one container holds more than one item. Many proof problems rely on this.

Recurrence Relations

A recurrence relation defines each term of a sequence using previous terms. The Fibonacci sequence is a classic example: an=anโˆ’1+anโˆ’2a_n = a_{n-1} + a_{n-2} with a0=0,a1=1a_0 = 0, a_1 = 1.

Solving techniques:

  1. Iteration (unrolling): substitute repeatedly until you spot a pattern, then prove it
  2. Characteristic equation: for linear recurrences like an=c1anโˆ’1+c2anโˆ’2a_n = c_1 a_{n-1} + c_2 a_{n-2}, solve r2=c1r+c2r^2 = c_1 r + c_2 to find the closed form
  3. Generating functions: a more advanced technique that encodes the sequence as coefficients of a power series

In algorithm analysis, the Master Theorem solves recurrences of the form T(n)=aT(n/b)+f(n)T(n) = aT(n/b) + f(n), which arise from divide-and-conquer algorithms.

Compare: Permutations vs. Combinations: both count selections from a set, but order matters for permutations (ABCโ‰ BACABC \neq BAC) and doesn't for combinations. Ask yourself: "Does rearranging the selection change the outcome?" If yes, use permutations. If no, use combinations.


Computational Models and Languages

These structures formalize computation itself: what can be computed, how efficiently, and with what representations.

Algorithms

An algorithm is a step-by-step procedure for solving a problem. The two key concerns are correctness (does it produce the right answer?) and efficiency (how fast and with how much memory?).

Complexity analysis uses Big-O notation to describe growth rates:

  • Time complexity: how the number of operations grows with input size
  • Space complexity: how memory usage grows with input size

Common paradigms:

  • Divide and conquer: split the problem, solve subproblems, combine results (e.g., merge sort)
  • Dynamic programming: solve overlapping subproblems once and store results (e.g., Fibonacci with memoization)
  • Greedy: make the locally optimal choice at each step (e.g., Dijkstra's shortest path)

Recognizing which paradigm fits a problem type is a frequent exam skill.

Finite State Machines

A finite state machine (FSM) is a computational model with a finite number of states, transitions triggered by inputs, and designated accepting states. It models systems with limited memory.

  • Deterministic FSMs (DFAs): exactly one transition per state-input pair
  • Nondeterministic FSMs (NFAs): multiple possible transitions for a given state-input pair

Every NFA can be converted to an equivalent DFA (though the DFA may have exponentially more states). FSMs are used in lexical analysis, protocol design, and pattern matching.

Formal Languages

A formal language is a set of strings over some alphabet, defined by grammatical rules. It formalizes what "valid syntax" means.

The Chomsky hierarchy classifies languages by complexity:

Language TypeRecognized By
RegularFinite state machines
Context-freePushdown automata
Context-sensitiveLinear-bounded automata
Recursively enumerableTuring machines

Each level is strictly more powerful than the one above it. Regular languages are the simplest; recursively enumerable languages are the most general.

Compare: FSMs vs. Formal Languages: FSMs are the machines that recognize languages; formal languages are the sets of strings being recognized. An FSM accepts exactly those strings belonging to its corresponding regular language.


Algebraic Structures

Matrices and number theory provide computational tools for solving systems and securing communications.

Matrices

A matrix is a rectangular array of values arranged in rows and columns. Matrices represent linear transformations and systems of equations.

Key operations and facts:

  • Addition: element-wise, requires same dimensions
  • Multiplication: ABAB is defined when the number of columns in AA equals the number of rows in BB. Matrix multiplication is not commutative (ABโ‰ BAAB \neq BA in general).
  • Determinant: a scalar value that tells you whether a matrix is invertible. Aโˆ’1A^{-1} exists if and only if detโก(A)โ‰ 0\det(A) \neq 0.
  • Identity matrix II: the matrix equivalent of multiplying by 1

For discrete math specifically, adjacency matrices represent graphs. Entry (i,j)(i,j) equals 1 if there's an edge from vertex ii to vertex jj, and 0 otherwise. A powerful result: the entry (i,j)(i,j) in AkA^k gives the number of paths of length kk from vertex ii to vertex jj.

Number Theory

Number theory studies properties of integers, focusing on divisibility, primes, and modular arithmetic.

  • Fundamental Theorem of Arithmetic: every integer greater than 1 has a unique prime factorization. This is the foundation for many proofs about integers.
  • GCD and LCM: the greatest common divisor and least common multiple. The Euclidean algorithm efficiently computes the GCD through repeated division.
  • Modular arithmetic: aโ‰กb(modn)a \equiv b \pmod{n} means nn divides (aโˆ’b)(a - b). This is essential for cryptography (RSA relies on modular exponentiation), hashing, and computer arithmetic.

Compare: Matrices vs. Graphs: an adjacency matrix is a graph representation. Entry (i,j)(i,j) indicates an edge from vertex ii to vertex jj. Matrix operations then have graph interpretations: AkA^k counts paths of length kk.


Quick Reference Table

ConceptBest Examples
Collection/GroupingSets, Multisets, Power sets
RelationshipsRelations, Functions, Equivalence classes
Network ModelingGraphs, Trees, Directed acyclic graphs
Logical ReasoningPropositional logic, Predicate logic, Boolean algebra
CountingCombinatorics, Inclusion-exclusion, Binomial coefficients
Sequence AnalysisRecurrence relations, Closed-form solutions
Computation ModelsAlgorithms, FSMs, Formal languages
Algebraic ToolsMatrices, Number theory, Modular arithmetic

Self-Check Questions

  1. Both relations and functions are sets of ordered pairs. What property distinguishes a function from a general relation, and how would you verify this property given a relation?

  2. Compare graphs and trees: what structural constraint makes a tree a special case of a graph, and what property does this guarantee about paths between vertices?

  3. If you need to count the number of ways to select a committee of 5 from 12 people, would you use permutations or combinations? What if the committee has a chair, vice-chair, and three regular members?

  4. Explain how propositional logic and predicate logic differ in expressiveness. Give an example of a statement that requires predicate logic to express formally.

  5. A recurrence relation defines T(n)=2T(n/2)+nT(n) = 2T(n/2) + n with T(1)=1T(1) = 1. What type of algorithm typically produces this recurrence, and what is its time complexity in Big-O notation?