Mathematical Foundations
Before we can rigorously analyze algorithms, we must establish the mathematical language and reasoning tools that will serve as our foundation. This chapter introduces the essential concepts from set theory, logic, proof techniques, and combinatorics that underpin all algorithmic analysis.
While these topics may seem abstract, they provide the precise vocabulary needed to discuss computational problems and their solutions. Every algorithm we encounter will be described using sets, analyzed using logical reasoning, proven correct through formal techniques, and evaluated using combinatorial methods.
1.1 Set Theory
A set is a collection of distinct objects, called elements or members. Sets form the foundation of mathematical discourse because they allow us to discuss collections of objects with precision.
1.1.1 Basic Definitions and Notation
We write to denote that is an element of set , and to denote that is not an element of . Sets can be specified in several ways:
Roster notation: Set-builder notation:
Two sets are equal if they contain exactly the same elements. Order and repetition do not matter: .
Important sets:
- (natural numbers)
- (integers)
- (rational numbers)
- (real numbers)
- (empty set)
1.1.2 Set Operations
Given sets and :
Union: Intersection: Difference: Complement: (relative to some universal set)
Exercise 1.1: Let and . Find , , , and .
1.1.3 Relations Between Sets
Set is a subset of set , written , if every element of is also an element of . Formally:
If and , then is a proper subset of , written .
Theorem 1.1: For any sets , , and :
- (reflexivity)
- If and , then (antisymmetry)
- If and , then (transitivity)
Exercise 1.2: Prove that if , then and .
1.1.4 Cartesian Products and Relations
The Cartesian product of sets and is:
A relation from set to set is a subset of . We write or to indicate that is related to .
Exercise 1.3: Let and . Find and . Are they equal?
1.1.5 Functions
A function is a special relation where each element of is related to exactly one element of . We write to denote that maps to .
- is the domain of
- is the codomain of
- The range of is
A function is:
- Injective (one-to-one) if implies
- Surjective (onto) if for every , there exists such that
- Bijective if it is both injective and surjective
Exercise 1.4: Determine whether the function defined by is injective, surjective, or bijective.
1.2 Logic and Proof Techniques
Mathematical logic provides the framework for precise reasoning about mathematical statements. Understanding logical structure is essential for constructing and evaluating proofs.
1.2.1 Propositions and Logical Connectives
A proposition is a statement that is either true or false. We use variables like , , to represent propositions.
Logical connectives:
- Negation: (“not ”)
- Conjunction: (” and ”)
- Disjunction: (” or ”)
- Implication: (“if then ”)
- Biconditional: (” if and only if ”)
Truth tables:
T | T | F | T | T | T | T |
T | F | F | F | T | F | F |
F | T | T | F | T | T | F |
F | F | T | F | F | T | T |
Exercise 1.5: Construct truth tables for and . What do you observe?
1.2.2 Logical Equivalences
Two propositions are logically equivalent if they have the same truth value under all possible assignments of truth values to their variables.
Important equivalences:
- De Morgan’s Laws: ,
- Contrapositive:
- Double negation:
- Distributivity:
Exercise 1.6: Prove that using truth tables.
1.2.3 Quantifiers
Universal quantifier: means “for all , is true” Existential quantifier: means “there exists an such that is true”
Quantifier negation:
Exercise 1.7: Express the following statements using quantifiers:
- Every positive integer has a successor
- There exists a real number that is not rational
- For every real number, there exists a larger real number
1.2.4 Proof Techniques
Direct Proof
To prove , assume is true and show that must be true.
Example: Prove that if is an even integer, then is even. Proof: Suppose is even. Then for some integer . Therefore, . Since is an integer, is even. □
Proof by Contradiction
To prove , assume and derive a contradiction.
Example: Prove that is irrational. Proof: Suppose is rational. Then where and are integers with . Squaring both sides: , so . This means is even, so is even. Let . Then , so . This means is even, so is even. But if both and are even, then , contradicting our assumption. Therefore, is irrational. □
Proof by Contrapositive
To prove , prove .
Example: Prove that if is odd, then is odd. Proof: We prove the contrapositive: if is even, then is even. If is even, then for some integer . Therefore, , which is even. □
Mathematical Induction
To prove :
- Base case: Prove
- Inductive step: Prove for arbitrary
Example: Prove that for all . Proof: Base case: For , LHS and RHS . ✓ Inductive step: Assume the formula holds for . Then: This is the formula for . By induction, the formula holds for all . □
Exercise 1.8: Prove by induction that for all .
1.3 Basic Combinatorics
Combinatorics studies methods of counting, which is essential for analyzing algorithm efficiency and correctness.
1.3.1 Fundamental Counting Principles
Addition Principle: If task can be done in ways and task can be done in ways, and the tasks cannot be done simultaneously, then choosing to do either or can be done in ways.
Multiplication Principle: If task can be done in ways and task can be done in ways, then doing both and can be done in ways.
Exercise 1.9: A restaurant offers 5 appetizers, 8 main courses, and 4 desserts. How many different three-course meals are possible?
1.3.2 Permutations
A permutation is an arrangement of objects in a specific order.
Permutations of distinct objects: (read ” factorial”) Permutations of objects from distinct objects:
Exercise 1.10: In how many ways can 8 people be arranged in a line? In how many ways can 3 people be selected from 8 people and arranged in a line?
1.3.3 Combinations
A combination is a selection of objects where order doesn’t matter.
Combinations of objects from distinct objects:
Properties of binomial coefficients:
- (Pascal’s identity)
Exercise 1.11: Prove Pascal’s identity both algebraically and combinatorially.
1.3.4 The Binomial Theorem
Theorem 1.2 (Binomial Theorem): For any real numbers and and non-negative integer :
Exercise 1.12: Use the binomial theorem to expand .
1.3.5 The Pigeonhole Principle
Theorem 1.3 (Pigeonhole Principle): If pigeons are placed in pigeonholes and , then at least one pigeonhole contains more than one pigeon.
Generalized Pigeonhole Principle: If pigeons are placed in pigeonholes, then at least one pigeonhole contains at least pigeons.
Exercise 1.13: Prove that among any 13 people, at least two have birthdays in the same month.
1.3.6 Inclusion-Exclusion Principle
Theorem 1.4 (Inclusion-Exclusion Principle): For finite sets :
Exercise 1.14: Use inclusion-exclusion to find the number of integers from 1 to 1000 that are divisible by 2, 3, or 5.
1.4 Connecting Foundations to Algorithms
These mathematical foundations directly support algorithmic analysis:
Set theory provides the vocabulary for describing input domains, output ranges, and data structures. Every algorithm operates on sets of data.
Logic enables precise specification of algorithm correctness. We express what an algorithm should do using logical statements, then prove these statements hold.
Proof techniques allow us to rigorously demonstrate that algorithms work correctly. We’ll use direct proof, contradiction, and induction repeatedly.
Combinatorics gives us tools to count operations, analyze worst-case scenarios, and compute probabilities in randomized algorithms.
Exercise 1.15: Consider the problem of finding the maximum element in a set of distinct integers.
- Express the problem statement using set theory and logic
- Describe an algorithm to solve this problem
- Prove your algorithm is correct
- Count the number of comparisons your algorithm makes
Summary
This chapter established the mathematical language we’ll use throughout our study of algorithms. We covered:
- Set theory: Basic operations, relations, and functions
- Logic: Propositions, quantifiers, and logical reasoning
- Proof techniques: Direct proof, contradiction, contrapositive, and induction
- Combinatorics: Counting principles, permutations, combinations, and important theorems
These tools provide the foundation for rigorous algorithm analysis. In the next chapter, we’ll begin applying these concepts to analyze the correctness and efficiency of basic algorithms.
Key takeaways:
- Precision in mathematical language prevents ambiguity in algorithm specification
- Logical reasoning enables rigorous correctness proofs
- Combinatorial analysis quantifies algorithm performance
- Mathematical maturity develops through practice with formal reasoning
The exercises in this chapter are essential for developing the mathematical fluency needed for advanced algorithm analysis. Work through them systematically before proceeding to the next chapter.
Selected Exercise Solutions
Solution 1.1: , , , .
Solution 1.8: Base case: For , . ✓ Inductive step: Assume . Then . Since , we have , so . By induction, for all . □