Discrete Mathematics (H) Final Review Note
Published:
1 Logic
1.1 Propositional Logic
1.1.1 Propositions
A proposition is a declarative sentence that is either true or false, but not both. For example, “SUSTech is in Shenzhen” is a proposition, while “No parking on campus” is not a proposition.
1.1.2 Logical Connectives
There are six logical connectives in propositional logic, which are negation(), conjunction(), disjunction(), exclusive or(), implication(), and biconditional().
For implication , we call the hypothesis and the conclusion.
The converse of is . The inverse of is . The contrapositive of is .
1.1.3 Tautologies and Contradictions
A tautology is a proposition that is always true, regardless of the truth values of its individual components. A contradiction is a proposition that is always false. A contingency is a proposition that is neither a tautology nor a contradiction.
1.1.4 Logical Equivalences
Two propositions are logically equivalent if they have the same truth values for all possible combinations of truth values of their component propositions.
The propositions and are logically equivalent if and only if is a tautology, denoted by or .
1.1.5 Important Logical Equivalences
- •
Identity laws
- •
Domination laws
- •
Idempotent laws
- •
Double negation laws
- •
Commutative laws
- •
Associative laws
- •
Distributive laws
- •
De Morgan’s laws
- •
Absorption laws
- •
Negation laws
- •
Useful law
1.2 Predicate Logic
1.2.1 Predicates and Quantifiers
A constant models a specific object. A variable represents objects of specific type. A predicate represents properties or relations among objects.
However, a predicate is not a proposition, because it is not a declarative sentence. It becomes a proposition when the variable is assigned a value. Additionally, the universal quantification and existential quantification of a predicate is a proposition. For example, is not a proposition, while and are propositions.
The universe(domain) of a predicate is the set of all objects that can be substituted for the variables in a predicate. The truth set of a predicate is the set of objects in the universe that can be substituted for in to make the resulting proposition true.
The truth values of and depend on both the universe and the predicate .
1.2.2 Precedence of Quantifiers
The quantifiers and have higher precedence than all the logical operators. For example, means , not .
1.2.3 Translation with Quantifiers
Universal quantification
Sentence: All SUSTech students are smart.
Universe: all students
Translation:
Typical error: , which means all students are at SUSTech and smart.
Existential quantification
Sentence: Some SUSTech students are smart.
Universe: all students
Translation:
Typical error: , this is true if there is anyone who is not at SUSTech.
1.2.4 Nested Quantifiers
The order of nested quantifiers is important. For example, let denotes “ loves ”, then means “Everyone loves someone”, while means “There is someone whom everyone loves”. In general, is a tautology, but is not always true.
However, the order of nested quantifiers does not matter if quantifiers are of the same type.
1.2.5 Negating Quantifiers
- •
- •
- •
2 Mathematical Proofs
2.1 Theorems and Proofs
2.1.1 Definitions
An axiom or postulate is a statement or proposition that is regarded as being established, accepted, or self-evidently true. A theorem is a statement or proposition that can be proved to be true. A lemma is a statement that can be proved to be true, and is used in proving a theorem.
In formal proofs, steps follow logically from the set of premises, axioms, lemmas, and other previously proved theorems.
2.1.2 Rules of inference
- •
Modus Ponens:
- •
Modus Tollens:
- •
Hypothetical Syllogism:
- •
Disjunctive Syllogism:
- •
Addition:
- •
Simplification:
- •
Conjunction:
- •
Resolution:
- •
Universal instantiation:
- •
Universal generalization:
- •
Existential instantiation:
- •
Existential generalization:
2.1.3 Methods of Proof
To proof :
- •
Direct proof: Show that if is true then follows.
- •
Proof by contrapositive: Show that .
- •
Proof by contradiction: Show that contradicts the assumptions.
- •
Proof by cases: Give proofs for all possible cases.
- •
Proof of equivalence : Prove and .
3 Sets and Functions
3.1 Sets
3.1.1 Definitions
A set is an unordered collection of objects, called elements or members of the set. We can represent a set by listing its elements between braces, or defining a property that its elements satisfy.
3.1.2 Important Sets
- •
is the set of natural numbers.
- •
is the set of integers. is the set of positive integers.
- •
is the set of rational numbers.
- •
is the set of real numbers.
- •
is the set of complex numbers.
- •
is the set of all objects under consideration.
- •
is the empty set. Note:
- •
is the power set of , which is the set of all subsets of .
- •
Disjoint sets and are sets that have no elements in common, i.e., .
3.1.3 Set Operations
- •
Union:
- •
Intersection:
- •
Difference:
- •
Complement:
- •
Cartesian product:
3.1.4 Cardinality
The cardinality of a set , denoted by , is the number of distinct elements in the set. The sets and have the same cardinality if there is a one-to-one correspondence between them. If there is a one-to-one function from to , the cardinality of is less than or equal to the cardinality of , denoted by .
A set that is either finite or has the same cardinality as the set of positive integers is called countable. A set that is not countable is called uncountable.
Here are some examples of countable and uncountable sets:
- •
Countable Sets: , the set of finite strings over a finite alphabet
- •
Uncountable Sets: ,
The subset of a countable set is still countable.
To prove a set is countable, we can use Schröder-Bernstein theorem. If there are one-to-one functions and , then there is a one-to-one correspondence between and , and .
To prove a set is uncountable, we can use Cantor’s diagonalization method. Assume that is countable, then we can list all elements of in a table. Then we can construct a new element that is not in the table, which contradicts the assumption that is countable.
For power set, we have the following formula:
For union and intersection, we have the following formulas:
For Cartesian product, we have the following formula:
Note: and
3.1.5 Computable vs. Uncomputable
We say a function is computable if there is an algorithm that can compute the function’s value for any input in a finite amount of time.
There are functions that are not computable. This is true because the set of computer programs is countable, while the set of functions from to the set is uncountable. (Cantor’s diagonalization method)
3.1.6 Cantor’s Theorem
For any set , .
This is obviously true for finite sets, because . (Note that )
For infinite sets, we can prove this by contradiction. Assume that , then there is a one-to-one correspondence between and . Let be a function from to , then we can construct a set . Since is a one-to-one correspondence, there must be an element such that . However, implies , which is a contradiction.
To build a one-to-one function from to is trivial, because we can just map each subset of to its smallest element.
Hence, we know that and . Therefore, .
3.1.7 Set Identities
- •
Identity laws
- •
Domination laws
- •
Idempotent laws
- •
Complementation laws
- •
Commutative laws
- •
Associative laws
- •
Distributive laws
- •
De Morgan’s laws
- •
Absorption laws
- •
Complement laws
3.2 Tuples
An ordered -tuple is a sequence of elements, where is a positive integer.
3.3 Functions
3.3.1 Definitions
Let and be sets. A function from to , denoted by , is an assignment of exactly one element of to each element of .
We represent a function by a formula or explicitly state the assignments between elements of and . For example, let and , then can be represented by .
Let be a function. We say that is the domain of and is the codomain of . If , is the image of under , and is a preimage of . The range of is the set of all images of elements of , denoted by .
3.3.2 Injective, Surjective, and Bijective Functions
A function is injective (one-to-one) if and only if implies for all . A function is surjective (onto) if and only if . A function is bijective (one-to-one correspond) if and only if is both injective and surjective.
The inverse of a function, denoted by , is only defined for bijective functions.
3.3.3 Sequences
A sequence is a function from a subset of integers (typically or ) to a set . We use the notation to denote the image of under the function, and we call the th term of the sequence.
4 Complexity of Algorithms
4.1 Big- Notation
We say that (reads as “ is big- of ”) if there are positive constants and such that for all .
Important big- estimation:
- •
- •
(Actually we can prove )
- •
for any
- •
for any and
Similarly, we can define big- and big-.
4.2 Algorithms
An algorithm is a finite set of precise instructions for performing a computation or for solving a problem. A computational problem is a specification of the desired input-output relationship. An instance of a computational problem is a specific input. A correct algorithm halts with the correct output for every instance of the problem, and we can say that the algorithm solves the problem.
4.2.1 Time and Space Complexity
The time complexity of an algorithm is the number of machine operations it performs on an instance. The space complexity of an algorithm is the number of cells of memory it uses on an instance.
4.2.2 Input Size
The input size is the number of bits needed to represent the input. For an integer , the input size actually is (or just ). Therefore, an algorithm that runs in seems to be linear and efficient, but it is actually exponential ().
We say two positive functions and are of the same type if and only If
for all large and some positive constants .
Therefore, all polynomial functions are of the same type, and all exponential functions are of the same type. But polynomial functions are not of the same type as exponential functions.
4.2.3 Decision Problems and Optimization Problems
A decision problem is a question that has two possible answers: yes or no. An optimization problem is a question that requires an answer that is an optimal configuration.
If is a decision problem and is the input, we often write to mean that the answer to the decision problem is yes, and to mean that the answer is no.
An optimization problem usually has a corresponding decision problem.
4.2.4 Complexity Classes
We divide the set of all decision problems into three complexity classes.
A problem is solvable (tractable) in polynomial time if there is an algorithm that solves the problem and the number of steps required by the algorithm on any instance of size is for some constant .
The class is the set of all decision problems that are solvable in polynomial time. The class is the set of all decision problems for which there exists a certificate for each yes-input that can be verified in polynomial time.
4.2.5 NP Completeness
Reduction is a relationship between two problems. We say can be reduced to if every instance of can be transformed into an instance of such that the answer to the transformed instance is yes if and only if the answer to the original instance is yes.
A polynomial-time reduction from to is a reduction that can be performed in polynomial time, denoted by . Intuitively, this means is no harder than .
A problem is NP-complete if and only if
- •
- •
Every problem ,
Therefore, if we can find a polynomial-time algorithm for an NP-complete problem, then we can solve all NP problems in polynomial time.
5 Number Theory
5.1 Divisibility and Modular Arithmetic
5.1.1 Divisibility
Let be integers. Then the following holds:
- •
If and , then and .
- •
If , then .
- •
If and , then .
- •
Corollary: If are integers, where , such that and , then for any integers and .
5.1.2 Modular Arithmetic
Let be integers, where . We say that is congruent to modulo , denoted by , if and only if . This is called congruence and is called the modulus.
The following properties hold:
- •
If and , then .
- •
If and , then .
- •
Corollary: , and .
5.2 Prime
An integer is prime if and only if its only positive divisors are 1 and . An integer is composite if and only if it is not prime.
The fundamental theorem of arithmetic states that every integer greater than 1 is either prime or can be written as a unique product of prime numbers.
GCD of two integers and , denoted by , is the largest integer that divides both and . If we factorize and into prime numbers, then , where and are the exponents of in the factorization of and . Two integers are relatively prime if and only if their GCD is 1.
Similarly, we can define LCM of two integers and , denoted by , is the smallest positive integer that is divisible by both and .
5.3 Eculidean Algorithm
The Eculidean algorithm is an efficient method for computing the GCD of two integers. It can solve the problem in time, where is the smaller of the two integers.
The central idea is that if , then . Here is the proof: If is a common divisor of and , we can write and . By the corollary, we know that , which implies . Therefore, is a common divisor of and .
For example, to compute :
Therefore, .
5.4 Bezout’s Theorem
Let and be integers, not both zero. Then there exist integers and such that .
We can use the extended Eculidean algorithm to find and .
For example, since , we can find and such that , with the following steps:
Firstly, we use the Eculidean algorithm to find the GCD of 503 and 286:
Then, we can find and :
Therefore, and .
The corollaries of Bezout’s theorem are:
- •
If and , then .
- •
If is a prime and , then for some .
- •
If and , then .
The proof of the first corollary is as follows: Since , we can find and such that . Then . Since , we know that . Therefore, .
5.5 Linear Congruence
A linear congruence is an equation of the form , where are integers and .
5.5.1 Modular Inverse
Let and be integers, where . If there exists an integer such that , then is called the modular inverse of modulo .
If and are relatively prime, then has a modular inverse modulo . Furthermore, the modular inverse of modulo is unique modulo .
We can use the extended Eculidean algorithm to find the modular inverse of modulo .
5.5.2 Chinese Remainder Theorem
Let be positive integers that are pairwise relatively prime, and let be any integers. Then the system of linear congruences:
has a solution, and any two solutions are congruent modulo .
Let . Then the solution is , where is the modular inverse of modulo .
For example, to solve the system of linear congruences:
We can find , , and . Therefore, is a solution.
5.6 Fermat’s Little Theorem
Let be a prime and be an integer such that . Then .
5.7 Euler’s Theorem
Euler’s function is the number of positive integers less than or equal to that are relatively prime to . The function has the following properties:
- •
If is prime, then .
- •
If is prime and , then .
- •
If and are relatively prime, then .
Euler’s theorem states that if is a positive integer and is an integer such that and are relatively prime, then .
It is worth noting that might not be the smallest positive integer such that .
5.8 Primitive Roots
A primitive root modulo a prime is an integer such that every nonzero integer modulo is congruent to a power of modulo .
6 Groups, Rings, and Fields
6.1 Groups
A group is a set together with a binary operation on such that the following axioms hold:
- •
Closure: For all , .
- •
Associativity: For all , .
- •
Identity: There exists a unique element such that for all , .
- •
Inverse: For each , there exists an element such that .
6.1.1 Permutation Groups
A permutation group is a group whose elements are permutations of a given set and whose operation is composition of permutations in . Let denotes a sequence of elements, and denotes the set of all permutations of . Then for any two elements and , is also a permutation of .
For example, , and . If and , then . The operation is .
Therefore, is a group.
6.1.2 Abeilian Groups
A group is abeilian if and only if for all , .
6.2 Rings
If is an abeilian group, we define a second binary operation on such that the following axioms hold:
- •
Closure: For all , .
- •
Associativity: For all , .
- •
Distributivity: For all , and .
6.2.1 Commutative Ring
A ring is commutative if and only if for all , .
6.2.2 Integral Domain
A commutative ring is an integral domain if the following axiom holds:
- •
Identity: There exists a unique element such that for all , .
- •
Nonzero product: For all , if , then or .
6.3 Fields
A commutative ring is a field if the following axiom holds:
- •
Inverse: For each , there exists an element such that .
6.4 Other Facts
- •
, the set of integers modulo , is a commutative ring.
- •
is a group but not an abeilian group. (The set of all invertible matrices)
- •
is a ring but not a commutative ring.
- •
is a commutative ring but not an integral domain.
- •
is an integral domain but not a field.
7 Cryptography
7.1 Public Key Cryptography
7.1.1 RSA Cryptosystem
The RSA public key cryptosystem works as follows:
- 1.
Choose two large primes and .
- 2.
Compute and .
- 3.
Choose such that and .
- 4.
Compute such that .
- 5.
Publish the public key and keep the private key secret.
To encrypt a message , compute . To decrypt a ciphertext , compute .
The correctness of the algorithm is as follows:
To leave a RSA signature, compute . To verify a RSA signature, compute .( and are interchangeable)
7.1.2 El Gamal Cryptosystem
The El Gamal public key cryptosystem works as follows:
- 1.
Choose a large prime and a primitive root modulo .
- 2.
Choose such that .
- 3.
Compute .
- 4.
Publish the public key and keep the private key secret.
To encrypt a message , choose such that and , then compute and . To decrypt a ciphertext , compute .
The correctness of the algorithm is as follows:
7.2 Diffie-Hellman Key Exchange
The Diffie-Hellman key exchange works as follows:
- 1.
Choose a large prime and a primitive root modulo .
- 2.
Alice chooses such that and sends to Bob.
- 3.
Bob chooses such that and sends to Alice.
- 4.
Alice computes .
- 5.
Bob computes .
- 6.
Now Alice and Bob share the secret key .
8 Mathematical Induction
8.1 Proof by Smallest Counterexample
To prove a statement for all , we can use proof by smallest counterexample. We assume that is false for some . Then there must be a smallest integer such that is false. Since is true, . Then we use the fact that the for all is true to show that is true, which is a contradiction.
8.2 Direct Proof
8.2.1 Weak Principle of Mathematical Induction
If the statement is true, and the statement is true for all integers , then the statement is true for all integers .
We call the basis step (inductive hypothesis) and the inductive step (inductive conclusion).
8.2.2 Strong Principle of Mathematical Induction
If the statement is true, and the statement is true for all integers , then the statement is true for all integers .
We can see that the weak form is a special case of the strong form, and the strong form can be derived from the weak form.
8.3 Recursion
To prove a recursive algorithm is correct (for example the tower of Hanoi problem), we can use the mathematical induction. Also, the proof of runtime of recursive algorithms can also be proved by mathematical induction.
To proof:
Base case: When , is true.
Inductive hypothesis: Assume that is true for all . Then for , we have .
8.3.1 Iteration
For a recursive equation in the form of , we can use iteration to solve it.
This is called the “Top-down” method.
The “Bottom-up” method is to start from and compute .
Formula of Recursive Equations: If and , then we have
8.3.2 First Order Linear Recurrence
A first order linear recurrence is a recurrence of the form . First order means that the recurrence is defined by and , or to say it only goes back one step. Linear means that the power of is 1.
For a first order linear recurrence that is a constant, we have:
Then we have
This equation can often be solved by extracting the constant factor .
We can use the theorem that combines the geometric series and the arithmetic series to solve the equation.
8.3.3 Divide and Conquer Recurrence
A divide and conquer recurrence is a recurrence of the form . This can be solved by the regular “Top-down” method.
8.3.4 Master Theorem
Suppose that , where is a positive integer, and and are constants. Then has the following asymptotic bounds:
- 1.
If , then .
- 2.
If , then .
- 3.
If , then .
9 Counting
9.1 Basic Counting Principles
9.1.1 Product Rule
If there are ways to perform action 1, and for each of these ways of performing action 1, there are ways to perform action 2, then there are ways to perform action 1 and then action 2.
9.1.2 Sum Rule
If there are ways to perform action 1, and ways to perform action 2, and the two actions cannot be performed at the same time, then there are ways to perform either action 1 or action 2.
9.2 Pigeonhole Principle
If there are objects to be placed into boxes, then there is at least one box containing two or more objects.
Generalized version: If there are objects to be placed into boxes, then there is at least one box containing at least objects.
9.3 Permutations and Bijection
A bijection that maps a set to itself is called a permutation of .
In counting we usually use bijection to show two sets have the same number of elements, so that we can count one set and get the number of elements of the other set. And it is often done implicitly. For example, if we want to count the number of increasing tuple of size , we can define a bijection as follows:
This means the number of increasing tuple of size is the same as the number of subsets of size of a set with elements, which is .
9.4 Inclusion-Exclusion Principle
If is a finite set and are its subsets, then
This can be proved by mathematical induction.
Base case: When , we have
Inductive hypothesis: Assume that the equation is true for . Then for , we have
Notice that the right most term . Then we can use the inductive hypothesis on this term.
This principle can be used to count the number of onto functions from a set with elements to a set with elements. Firstly, the number of all possible functions is . Then we try to exclude the functions that are not onto. Let the set be the set of functions that map nothing to element . Then we have
9.5 -Element Permutations
An ordered tuple of distinct elements taken from set is called a -element permutation of .
If is a positive integer and is an integer that satisfies , then there are
9.6 Binomial Coefficients
For integers and with , the number of -element subsets of an -element set is denoted by and is called a binomial coefficient.
9.6.1 Properties of Binomial Coefficients
- 1.
- 2.
- 3.
This can be interpreted as: the number of subsets of an -element set is equal to the sum of the number of -element subsets of an -element set for .
- 4.
Pascal’s identity: This can be interpreted as: the number of -element subsets of an -element set is equal to the sum of the number of subsets that contain element and the number of subsets that do not contain element .
9.6.2 Binomial Theorem
For any real numbers and and any non-negative integer , we have
This can be proved by induction and Pascal’s identity.
Base case: When , .
Inductive hypothesis: Assume that the equation is true for . Then for , we have
9.6.3 Labeling and Trinomial Coefficients
When , the number of ways to label distinct objects with distinct labels so that there are objects with label is
9.7 Combinatorial Proof and Arithmetic Proof
A combinatorial proof of an identity is a proof that there is a bijection between the two sides of the identity. An arithmetic proof of an identity is a proof that the two sides of the identity are equal by algebraic manipulation.
For example, we can use combinatorial proof for Pascal’s identity. The term is the number of -element subsets of an -element set. The term is the number of -element subsets of an -element set. The term is the number of -element subsets of an -element set. We can make a bijection between the two sides: On the right side, the first term represent the number of -element subsets of an -element set that contains element . The second term represent the number of -element subsets of an -element set that does not contain element . Therefore, the two sides are equal.
9.8 Birthday Attack
The probablity that at least two people in a group of people have the same birthday is
We can estimate this number using the Taylor series of . Since , for , we have . Thus, .
10 Linear Recurrence
A linear homogeneous recurrence of degree with constant coefficients is a recurrence of the form
where are constants and .
“Linear” means that the power of each term is 1. “Homogeneous” all terms are a multiple of . “Degree ” means that is defined by previous terms. “Constant coefficients” means that the coefficients are constants.
By induction, we know that such a relation is uniquely determined by the initial values .
10.1 Solving Linear Recurrence
To solve a linear homogeneous recurrence of degree with constant coefficients, we first find the roots of the characteristic equation . Then we can find the general solution of the recurrence. (Since it is linear and homogeneous, any linear combination of solutions is also a solution) Finally, we can find the coefficients of the general solution by using the initial values.
For example, to solve the Fibonacci sequence :
- 1.
Find the roots of , which are .
- 2.
The general solution is .
- 3.
Since and , we have and .
Theorem: If the characteristic equation has distinct real roots , then is a solution of the recurrence if and only if
To prove this, we need to prove two statements:
- 1.
in the form of is a solution of the recurrence.
- 2.
Any solution of the recurrence is in the form of .
Statement 1: Let’s take an example that degree is 2. Since and are roots of the characteristic equation, we have
Then, we can find that
Hence, in the form of is a solution of the recurrence.
Statement 2:
With the initial values, we can find all the constant , thus giving us the general solution. Since the solution of the recurrence is unique when the initial values are given, the general solution is the only solution. Hence, the sequence is the same as .
10.1.1 Degenerate Roots
For a characteristic equation of degree 2, if the two roots are the same, then the general solution is
Theorem: Suppose there are roots of multiplicity respectively. Then the general solution of the recurrence is
10.2 Linear Nonhomogeneous Recurrence
A linear nonhomogeneous recurrence of degree with constant coefficients is a recurrence of the form
The associated homogeneous recurrence is .
However, there is no general method to solve the particular solution . We can only solve it by guessing.
11 Generating Functions
The generating function for a sequence is the formal power series
A finite sequence can be represented by the generating function by adding 0s to the end of the sequence.
11.1 Operations on Generating Functions
Let and be two generating functions. Then we have
11.2 Useful Generating Functions
- •
- •
- •
- •
- •
- •
- •
- •
- •
- •
- •
- •
- •
Here is a way to derive the generating function if we forget it: Suppose . Then . Then , thus . The other generating functions can be derived similarly, or by operations on the generating functions (for example, ).
Another way is to use the MacLaurin series of the function. Here is the general formula:
11.3 Counting with Generating Functions
Convolution:
Let and be two generating functions. Then the coefficient of in is .
11.3.1 -Combination with Repetition
The number of -combinations with repetition allowed means to choose elements from a set and repetition is allowed. The generating function for this is
11.3.2 Extended Binomial Theorem
The extended binomial theorem is
where is a real number and .
Corollary:
12 Relation
Let and be two sets. A binary relation from to is a subset of . Note that order matters in a relation, since it is a Cartesian product.
Typical representations of relations can use a table or a directed graph.
A relation on a set is a relation from to . The number of relation on a set is .
12.1 Properties of Relations
12.1.1 Reflexive
A relation on a set is reflexive if for all . In the matrix representation, the diagonal elements are all 1 if the relation is reflexive. For example, the divisible relation is reflexive, since for all .
12.1.2 Irrreflexive
A relation on a set is irreflexive if for all . In the matrix representation, the diagonal elements are all 0 if the relation is irreflexive. For example, the not equal relation is irreflexive, since for all .
12.1.3 Symmetric
A relation on a set is symmetric if implies for all . In the matrix representation, the matrix is symmetric if the relation is symmetric. For example, the equal relation is symmetric, since implies for all .
12.1.4 Antisymmetric
A relation on a set is antisymmetric if and implies for all . In the matrix representation, the matrix can have at most one 1 on the corresponding positions of the upper triangle and lower triangle if the relation is antisymmetric. But the diagonal elements can be whatever. For example, the divisible relation is antisymmetric, since and implies for all .
12.1.5 Transitive
A relation on a set is transitive if and implies for all . For example, the divisible relation is transitive, since and implies for all .
Theorem: The relation is transitive if and only if for all .
The “if” part: If for all , then specifically . Then and implies .
The “only if” part: Proof by induction. The base case is trivial. Suppose for all . Then we need to prove . Since , every element in in also in . Since is transitive, every element in is also in . Therefore, .
12.2 Composite Relation
Let be a relation from to and be a relation from to . Then the composite relation from to is defined as
12.3 Closure of a Relation
The reflexive closure of a relation is a set that contains all elements of , is reflexive and is the smallest set that satisfies these conditions. Similarly, we can define the symmetric closure, transitive closure, etc.
The generalized definition of closure is as follows: Let be a relation on a set . A relation on with property is called the closure of with respect to if is subset of all relations on with property and . In other words, is the smallest relation on with property that contains .
How to find transitive closure: Find all pairs that are connected in the graph.
12.4 Path and Circuit
A path from to in a relation is a finite sequence of elements such that , and for . A circuit is a path that starts and ends at the same element.
Theorem: There is a path of length from to in if and only if . This can be proved by induction.
12.4.1 Connectivity Relation
The connectivity relation on a set that contains all pairs such that there is a path from to in is an equivalence relation.
Or more formally,
Since a path that has no loop has at most elements, we can simplify the above equation to
The transitive closure of is the connectivity relation. To prove this, we need to prove two statements:
- 1.
The connectivity relation is transitive.
- 2.
The connectivity relation is the smallest transitive relation that contains .
Statement 1: If there is a path from to and a path from to , then there is a path from to .
Statement 2: Let be a transitive relation that contains . Then , where is the transitive closure of and is the transitive closure of .
The transitive closure can be found by running a Dijkstra algorithm on the adjacency matrix of the graph.
12.5 Equivalence Relation
An equivalence relation is a relation that is reflexive, symmetric and transitive. The equivalence relation partitions the set into disjoint subsets, called equivalence classes, denoted by or .
The following statements are equivalent:
- 1.
- 2.
- 3.
Proof:
- 1.
(1) (2): and .
- 2.
(2) (3): implies , since there is at least one element in and .
- 3.
(3) (1): implies there is an element such that and . Then and implies .
A partition of a set is a collection of nonempty subsets of such that every element of is in exactly one of these subsets.
The equivalence classes of an equivalence relation on a set form a partition of .
12.6 Partial Order
A partial order is a relation that is reflexive, antisymmetric and transitive. A set with a partial order is called a partially ordered set or poset.
12.6.1 Comparable
Two elements and in a poset are comparable if either or .
12.6.2 Total Order
A total order is a partial order in which every two elements are comparable.
12.6.3 Lexicographic Order
The lexicographic order on is defined as
12.6.4 Hasse Diagram
A Hasse diagram is a directed graph that represents a partial order. It leaves out the edges that can be inferred from the transitive or reflexive property.
12.6.5 Maximal and Minimal
An element in a poset is maximal if there is no element such that . An element in a poset is minimal if there is no element such that .
The greatest element in a poset is an element such that for all , which sometimes does not exist. We can define the least element similarly.
12.6.6 Upper and Lower Bound
An element in a poset is an upper bound of a set if for all . The least upper bound of a set is an element such that is an upper bound of and for all upper bounds of . We can define the lower bound and greatest lower bound similarly.
12.6.7 Well Ordering
A poset is well ordered if every nonempty subset has a least element.
12.6.8 Lattice
A lattice is a poset in which every two elements have a least upper bound and a greatest lower bound.
13 Graph
A graph is an ordered pair , where is a finite set and is a set of unordered pairs of distinct elements of . Each edge joins two endpoints, the two endpoints are adjacent to each other, the endpoint and the edge are incident to each other.
13.1 Simple Graph
A simple graph is a graph with no loops and no multiple edges.
13.2 Complete Graph
A complete graph is a simple graph in which every pair of distinct vertices is joined by exactly one edge, denoted by .
13.3 Undirected Graph
An undirected graph is a graph in which the edges are not ordered pairs. The two endpoints of an edge are adjacent to each other, or neighbors of each other. We denote the set of neighbors of a vertex by .
13.4 Directed Graph
A directed graph is a graph in which the edges are ordered pairs. If is an edge in a directed graph, then we say that is adjacent to and is adjacent from .
13.5 Degree
The degree of a vertex in an undirected graph is the number of edges incident to , denoted by . The in-degree of a vertex in a directed graph is the number of edges that end at , denoted by . The out-degree of a vertex in a directed graph is the number of edges that start at , denoted by .
13.5.1 Handshaking Theorem
In an undirected graph, the sum of the degrees of all vertices is twice the number of edges.
In a directed graph, the sum of the in-degrees of all vertices is equal to the sum of the out-degrees of all vertices.
13.6 Cycle
A cycle is a simple graph in which all vertices have degree 2, denoted by .
13.7 Wheel
A wheel can be obtained by adding a vertex to a cycle and connecting it to all vertices of the cycle, denoted by .
13.8 -Dimensional Hypercube
An -dimensional hypercube is a graph with vertices, each of which is labeled by an -bit string. Two vertices are adjacent if and only if their labels differ in exactly one bit. An -dimensional hypercube is denoted by , has edges and vertices of degree . An -dimensional hypercube is always bipartite.
13.9 Bipartite Graph
A bipartite graph is a graph whose vertices can be partitioned into two sets and such that every edge has one endpoint in and the other endpoint in . An equivalent definition is that a graph is possible to be colored with two colors such that no two adjacent vertices have the same color. A bipartite graph is denoted by , where is the number of vertices in and is the number of vertices in . A bipartite graph has no odd cycles.
13.9.1 Complete Bipartite Graph
A complete bipartite graph is a bipartite graph in which every vertex in is adjacent to every vertex in , denoted by .
13.9.2 Bipartite Matching
A bipartite matching is a set of edges in a bipartite graph such that no two edges share a common endpoint. A maximum bipartite matching is a bipartite matching with the maximum number of edges. A matching is complete if every vertex in is incident to an edge in the matching, or .
Hall’s Marriage Theorem: A bipartite graph with bipartition has a complete matching from to if and only if for all .
13.10 Union of Graphs
The union of two graphs and is the graph .
13.11 Representation of Graph
13.11.1 Adjacency Matrix
The adjacency matrix of a graph is a matrix such that
It can be modified to have multiple edges by using the number of edges instead of 1, or to have loops.
13.11.2 Incidence Matrix
The incidence matrix of a graph is a matrix such that
13.11.3 Adjacency List
The adjacency list of a graph is a list of vertices such that each vertex is followed by a list of vertices that are adjacent to it. This representation does not allow multiple edges, but allows loops.
13.12 Isoomorphism
Given two graphs and , an isomorphism from to is a bijection such that if and only if . There are some useful graph invariants that can be used to determine whether two graphs are isomorphic:
- •
Number of vertices
- •
Number of edges
- •
Degree sequence
- •
The existence of a simple circuit of length for
13.13 Path
A path from to in a graph is a sequence of edges such that for and and . The length of a path is the number of edges in the path. The path is a cycle if . A path or cycle is simple if it does not contain the same edge more than once.
Lemma: If there is a path from to in a graph , then there is a simple path from to in .
13.13.1 Connected
A graph is connected if there is a path from to for every pair of vertices and in .
13.13.2 Connected Component
A connected component of a graph is a maximal connected subgraph of . A directed graph is strongly connected if there is a path from to and a path from to for every pair of vertices and in . A directed graph is weakly connected if the underlying undirected graph is connected.
13.13.3 Cut Vertex and Cut Edge
A cut vertex is a vertex whose removal disconnects the graph. A cut edge is an edge whose removal disconnects the graph.
A set of edges is an edge cut if is disconnected. The edge connectivity of a graph is the minimum size of an edge cut of , denoted by .
13.13.4 Counting Paths
The number of paths of length from to in a graph is the -entry of , where is the adjacency matrix of .
13.14 Eular Path and Circuit
An Eular path in a graph is a simple path that contains every edge of . An Eular circuit in a graph is a simple circuit that contains every edge of .
The Eular path exists if and only if the graph is connected and has exactly two vertices of odd degree. The Eular circuit exists if and only if the graph is connected and every vertex has even degree.
13.15 Hamilton Path and Circuit
A Hamilton path in a graph is a simple path that passes through every vertex of exactly once. A Hamilton circuit in a graph is a simple circuit that passes through every vertex of exactly once.
Dirac’s Theorem: If is a simple graph with vertices such that and for every vertex of , then has a Hamilton circuit.
Ore’s Theorem: If is a simple graph with vertices such that and for every pair of nonadjacent vertices and of , then has a Hamilton circuit.
13.16 Shortest Path
If is a weighted graph, the shortest path from to is the path from to with the smallest total weight.
13.16.1 Dijkstra’s Algorithm
Dijkstra’s algorithm can be used to find the shortest path from a vertex to every other vertex in a weighted graph . The algorithm is as follows:
- 1.
Let and .
- 2.
For every vertex , let be the length of the shortest path from to .
- 3.
Choose a vertex such that is minimum and add to .
- 4.
For every vertex , if , then let .
- 5.
Repeat steps 3 and 4 until .
The runtime of Dijkstra’s algorithm is , but can be improved to using a priority queue. This algorithm can only work on graphs with nonnegative weights. If there are negative weights, we can use the Bellman-Ford algorithm, which runs in time.
13.17 Planar Graph
A planar graph is a graph that can be drawn in the plane without any edges crossing. An -dimensional hypercube is planar if and only if . A complete graph is planar if and only if .
13.17.1 Euler’s Formula
If is a connected planar graph with vertices, edges and regions, then
This can be proved by induction on the number of edges. The inductive step is to add an edge to the graph. There are two cases: the edge creates a new region or the edge does not create a new region.
The degree of a region is the number of edges that bound the region. When an edge occur twice in the boundary of a region, it is counted twice. By this we can prove the corollaries:
- •
If is a connected planar simple graph with vertices, edges and , then . This is because each region is bounded by at least 3 edges and each edge is counted twice. Hence . Then we substituted in the Euler’s formula and get .
- •
If is a connected planar simple graph, there exists a vertex of degree at most 5. Proof by contradiction. Suppose every vertex has degree at least 6. Then by Handshaking Theorem, . Then . Then by the corollary above, , which is a contradiction.
- •
If is a connected planar simple graph with vertices, edges and , but has no circuits of length 3, then . Similar to the first corollary, each region is bounded by at least 4 edges and each edge is counted twice. Hence . Then we substituted in the Euler’s formula and get .
13.17.2 Kuratowski’s Theorem
If a graph is planar, so will be any graph obtained from by a sequence of elementary subdivisions. An elementary subdivision is the replacement of an edge by a path of length 2 or more. Two graphs are called homeomorphic if both can be obtained from the same graph by a sequence of elementary subdivisions.
The more useful version of Kuratowski’s theorem is that a graph is planar if and only if it does not contain a subgraph that is homeomorphic to or .
13.17.3 Platonic Solids
There are only 5 platonic solids:
- •
Tetrahedron ()
- •
Cube ()
- •
Octahedron ()
- •
Dodecahedron ()
- •
Icosahedron ()
where the first number is the number of sides of each face and the second number is the number of faces that meet at each vertex.
Notice that in the planar graph representation of a platonic solid of faces:
- •
- •
Combining this two equations with Euler’s formula, we get
Iterating through all possible values of , and , we get the five platonic solids.
13.18 Graph Coloring
A coloring of a graph is an assignment of a color to each vertex of such that no two adjacent vertices have the same color. The chromatic number of a graph , denoted by , is the minimum number of colors needed to color .
By the Four Color Theorem, every planar graph can be colored with at most 4 colors, or . We now give proof to the weaker version of the theorem, which states that every planar graph can be colored with at most 6 colors, or . Then another proof is given to the stronger version of the theorem, which states that every planar graph can be colored with at most 5 colors, or .
Six Color Theorem: By induction on the number of vertices. Base case: . Inductive step: Suppose every planar graph with vertices can be colored with at most 6 colors. By the previous corollary, there exists a vertex of degree at most 5. We remove the vertex and by inductive hypothesis, the remaining graph can be colored with at most 6 colors. Then we put back the vertex , since it has at most 5 neighbors, there is at least one color that is not used by its neighbors. Then we can color with that color.
Five Color Theorem: By induction on the number of vertices. The base case is the same as above. The inductive step is the same as above when we can find a vertex of degree 4 or less, or when we can find a vertex of degree 5 but adjacent vertices only use 4 colors. Then we need to proof the case when the vertex has degree 5 and adjacent vertices use all 5 colors. Let the 5 adjacent vertices be , and the color of be . Then there are 2 cases:
- 1.
There is no path from to , then we can use the color to color . (If there is a vertex adjacent to and colored , we use to color it. Basically we flip the color of a chain that and are used repeatedly) Then is never used and can be used to color the vertex .
- 2.
There is a path from to , since this will create a cycle, then there must be no path from to . Then we repeat the same process as above.
13.19 Tree
A tree is a connected undirected graph with no simple circuits. An undirected graph is a tree if and only if there is a unique simple path between every pair of vertices.
Proof: “”: Easy since a tree is connected and has no simple circuits. “”: Easy to find it is connected. Suppose there is a simple circuit in the graph. Then there are two simple paths between two vertices in the circuit, which is a contradiction.
A rooted tree is a tree in which one vertex has been designated as the root and every edge is directed away from the root. A rooted tree is an -ary tree if every vertex has at most children. A full -ary tree is an -ary tree in which every internal vertex has exactly children. A full -ary tree with vertices, of which are internal, leaves satisfies the following equations:
The level of a vertex in a rooted tree is the length of the path from the root to the vertex. The height of a rooted tree is the maximum level of any vertex in the tree. A rooted tree is balanced if all leaves are at level or . There are at most leaves in an -ary tree of height . The equation holds for any -ary tree with leaves.
13.19.1 Polish Notation and Expression Tree
The Polish notation of an expression is an expression in which the operator is written before its operands. For example, is written as . This corresponds to the preorder traversal of the expression tree.
Similarly, the reverse Polish notation of an expression is an expression in which the operator is written after its operands. For example, is written as . This corresponds to the postorder traversal of the expression tree.
13.20 Catalan Number
The Catalan number is the number of different binary trees with vertices. Since a binary tree can be partitioned into a root, a left subtree and a right subtree, we have the following recurrence relation:
Let . Then we have
Then we have
Solving the quadratic equation, we get
Since , we have
Then, using the extended binomial theorem, we have
Substituting this into the equation above, we get
Then we have
13.21 Spanning Tree
A simple graph is connected if and only if it has a spanning tree.
13.21.1 Prim’s Algorithm
Prim’s algorithm can be used to find the minimum spanning tree of a weighted graph .
runtime:
correctness: By induction on the number of edges. Suppose the current tree is and it is a subgraph of some minimum spanning tree . When adding an edge to the tree , we want to prove that is still a subgraph of some minimum spanning tree . If is in , then is a subgraph of . If is not in , then contains a cycle. Then there must be an edge in the cycle that is not in . Then is another minimum spanning tree that contains .
13.21.2 Kruskal’s Algorithm
Very similar to Prim’s algorithm, but instead of adding edges to the tree, we add edges to the forest.
runtime:
correctness: Same as Prim’s algorithm.
13.22 NP Complete and SAT
A given boolean expression is satisfiable if there is an assignment of truth values to the variables that makes the expression true. A k-CNF expression is a boolean expression which is , where each is , where each is a literal.
13.22.1 2-CNF
The 2-CNF expression is satisfiable, and is polynomial time decidable. For each disjunction , we add an edge between and and and . Then if there is exists a path from to and to , then the expression is not satisfiable.
Proof:
- •
Claim 1: If there is a path from to , then there is no path from to .
- •
Claim 2: The expression is unsatisfiable if and only if there is a variable such that there is a path from to and to . This is because, one of these two path must begin with and end with , then somewhere in the middle, we can find , which is a contradiction. If there are no such literal, then we do as follows:
- –
Find an unassigned literal , with no path from to .
- –
Assign to and all its reachable literals to .
- –
Assign to and all its reachable literals to .
- –
Repeat until all literals are assigned.
This assignment is well defined because there is no path from to and at the same time. If so, by claim 1 we know there is a path from to , then concatenating the two paths, we get a path from to , which is a contradiction.
- –
13.22.2 SAT and Other NP Complete Problems
By Cook’s Theorem, SAT is NP complete. Then we prove DCLIQUE is NP complete by reducing SAT to DCLIQUE. Then we prove DVC is NP complete by reducing DCLIQUE to DVC.
A clique in an undirected graph is a subset of vertices such that every two vertices in are adjacent. The CLIQUE problem is to find the maximum clique in a graph. The DCLIQUE problem is to determine whether a graph has a clique of size . We can reduce a k-SAT problem to a DCLIQUE problem by constructing a graph with vertices representing the literals and edges representing the clauses. Then we can reduce a DCLIQUE problem to a DVC problem by constructing a graph with vertices representing every literals (allow duplicates) and edges across clauses (but not from to ). A clique of size in corresponds to a set of literals that satisfies clauses.
A vertex color of a graph is a set of vertices that every edge is incident to at least one vertex in the set. The vertex coloring problem is to find the minimum size of such a set. The DVC problem is to determine whether a graph has a vertex color of size . We can reduce a DVC problem to a vertex coloring problem by constructing a complement graph of . If there is a vertex color of size in , then there is a clique of size in .
We have a 2-approximation algorithm for vertex coloring.
- 1.
Choose an arbitrary edge in .
- 2.
Remove all edges incident to and .
- 3.
Repeat until all edges are removed.
This is because the algorithm gives a maximum matching for . The optimal vertex coloring is at least the size of the maximum matching. And the vertex coloring given by the algorithm is twice the size of the maximum matching. Hence we have