Discrete Mathematics (H) Final Review Note

64 minute read

Published:

1 Logic

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 pq, we call p the hypothesis and q the conclusion.

The converse of pq is qp. The inverse of pq is ¬p¬q. The contrapositive of pq is ¬q¬p.

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 p and q are logically equivalent if and only if pq is a tautology, denoted by pq or pq.

1.1.5 Important Logical Equivalences

  • Identity laws

    pTp
    pFp
  • Domination laws

    pTT
    pFF
  • Idempotent laws

    ppp
    ppp
  • Double negation laws

    ¬(¬p)p
  • Commutative laws

    pqqp
    pqqp
  • Associative laws

    (pq)rp(qr)
    (pq)rp(qr)
  • Distributive laws

    p(qr)(pq)(pr)
    p(qr)(pq)(pr)
  • De Morgan’s laws

    ¬(pq)¬p¬q
    ¬(pq)¬p¬q
  • Absorption laws

    p(pq)p
    p(pq)p
  • Negation laws

    p¬pT
    p¬pF
  • Useful law

    pq¬pq

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, Prime(x) is not a proposition, while Prime(3) and xPrime(x) are propositions.

The universe(domain) D 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 P(x) is the set of objects in the universe that can be substituted for x in P(x) to make the resulting proposition true.

The truth values of xP(x) and xP(x) depend on both the universe and the predicate P(x).

1.2.2 Precedence of Quantifiers

The quantifiers and have higher precedence than all the logical operators. For example, xP(x)Q(x) means (xP(x))Q(x), not x(P(x)Q(x)).

1.2.3 Translation with Quantifiers

Universal quantification

Sentence: All SUSTech students are smart.

Universe: all students

Translation: x(At(x,SUSTech)Smart(x))

Typical error: x(At(x,SUSTech)Smart(x)), which means all students are at SUSTech and smart.

Existential quantification

Sentence: Some SUSTech students are smart.

Universe: all students

Translation: x(At(x,SUSTech)Smart(x))

Typical error: x(At(x,SUSTech)Smart(x)), 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 L(x,y) denotes “x loves y”, then xyL(x,y) means “Everyone loves someone”, while yxL(x,y) means “There is someone whom everyone loves”. In general, xyP(x,y)yxP(x,y) is a tautology, but yxP(x,y)xyP(x,y) 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

  • ¬xP(x)x¬P(x)

  • ¬xP(x)x¬P(x)

  • ¬xyP(x,y)xy¬P(x,y)

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: ((pq)p)q

  • Modus Tollens: ((pq)¬q)¬p

  • Hypothetical Syllogism: ((pq)(qr))(pr)

  • Disjunctive Syllogism: ((pq)¬p)q

  • Addition: p(pq)

  • Simplification: (pq)p

  • Conjunction: ((p)(q))(pq)

  • Resolution: ((pq)(¬pr))(qr)

  • Universal instantiation: xP(x)P(c)

  • Universal generalization: P(c) for an arbitrary cxP(x)

  • Existential instantiation: xP(x)P(c) for some element c

  • Existential generalization: P(c)xP(x)

2.1.3 Methods of Proof

To proof pq:

  • Direct proof: Show that if p is true then q follows.

  • Proof by contrapositive: Show that ¬q¬p.

  • Proof by contradiction: Show that p¬q contradicts the assumptions.

  • Proof by cases: Give proofs for all possible cases.

  • Proof of equivalence pq: Prove pq and qp.

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: {}

  • P(S) is the power set of S, which is the set of all subsets of S.

  • Disjoint sets A and B are sets that have no elements in common, i.e., AB=.

3.1.3 Set Operations

  • Union: AB={x|xA or xB}

  • Intersection: AB={x|xA and xB}

  • Difference: A-B={x|xA and xB}

  • Complement: A¯={x|xU and xA}

  • Cartesian product: A×B={(a,b)|aA and bB}

3.1.4 Cardinality

The cardinality of a set S, denoted by |S|, is the number of distinct elements in the set. The sets A and B have the same cardinality if there is a one-to-one correspondence between them. If there is a one-to-one function from A to B, the cardinality of A is less than or equal to the cardinality of B, denoted by |A||B|.

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 S over a finite alphabet A

  • Uncountable Sets: , P()

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 f:AB and g:BA, then there is a one-to-one correspondence between A and B, and |A|=|B|.

To prove a set is uncountable, we can use Cantor’s diagonalization method. Assume that S is countable, then we can list all elements of S in a table. Then we can construct a new element that is not in the table, which contradicts the assumption that S is countable.

For power set, we have the following formula:

|P(S)|=2|S|

For union and intersection, we have the following formulas:

|AB|=|A|+|B|-|AB|

For Cartesian product, we have the following formula:

|A×B|=|A|×|B|

Note: ||=0 and |{}|=1

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 {0,1,2,,9} is uncountable. (Cantor’s diagonalization method)

3.1.6 Cantor’s Theorem

For any set S, |S|<|P(S)|.

This is obviously true for finite sets, because |P(S)|=2|S|. (Note that ||=0,|P()|=1)

For infinite sets, we can prove this by contradiction. Assume that |S|=|P(S)|, then there is a one-to-one correspondence between S and P(S). Let f be a function from S to P(S), then we can construct a set T={sS|xf(s)}. Since f is a one-to-one correspondence, there must be an element s0S such that f(s0)=T. However, s0T implies s0T, which is a contradiction.

To build a one-to-one function from P(S) to S is trivial, because we can just map each subset of S to its smallest element.

Hence, we know that |S||P(S)| and |S||P(S)|. Therefore, |S|<|P(S)|.

3.1.7 Set Identities

  • Identity laws

    A=A
    AU=A
  • Domination laws

    AU=U
    A=
  • Idempotent laws

    AA=A
    AA=A
  • Complementation laws

    A¯¯=A
  • Commutative laws

    AB=BA
    AB=BA
  • Associative laws

    (AB)C=A(BC)
    (AB)C=A(BC)
  • Distributive laws

    A(BC)=(AB)(AC)
    A(BC)=(AB)(AC)
  • De Morgan’s laws

    AB¯=A¯B¯
    AB¯=A¯B¯
  • Absorption laws

    A(AB)=A
    A(AB)=A
  • Complement laws

    AA¯=U
    AA¯=

3.2 Tuples

An ordered n-tuple is a sequence of n elements, where n is a positive integer.

3.3 Functions

3.3.1 Definitions

Let A and B be sets. A function f from A to B, denoted by f:AB, is an assignment of exactly one element of B to each element of A.

We represent a function by a formula or explicitly state the assignments between elements of A and B. For example, let A={1,2,3} and B={a,b,c,d}, then f:AB can be represented by 1a,2b,3c.

Let f:AB be a function. We say that A is the domain of f and B is the codomain of f. If f(a)=b, b is the image of a under f, and a is a preimage of b. The range of f is the set of all images of elements of A, denoted by f(A).

3.3.2 Injective, Surjective, and Bijective Functions

A function f:AB is injective (one-to-one) if and only if f(a1)=f(a2) implies a1=a2 for all a1,a2A. A function f:AB is surjective (onto) if and only if f(A)=B. A function f:AB is bijective (one-to-one correspond) if and only if f is both injective and surjective.

The inverse of a function, denoted by f-1(x), is only defined for bijective functions.

3.3.3 Sequences

A sequence is a function from a subset of integers (typically {0,1,2,} or {1,2,3,}) to a set S. We use the notation an to denote the image of n under the function, and we call an the nth term of the sequence.

4 Complexity of Algorithms

4.1 Big-O Notation

We say that f(n)=O(g(n)) (reads as “f(n) is big-O of g(n)”) if there are positive constants c and n0 such that |f(n)||cg(n)| for all nn0.

Important big-O estimation:

  • n!=O(nn)

  • logn!=O(nlogn) (Actually we can prove logn!<nlogn<2logn!)

  • logan=O(n) for any a2

  • nk=O(an) for any k and a>1

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 n, the input size actually is log2(n+1) (or just log2n). Therefore, an algorithm that runs in Θ(n) seems to be linear and efficient, but it is actually exponential (Θ(n)=Θ(2size(n))).

We say two positive functions f(n) and g(n) are of the same type if and only If

c1g(na1)b1f(n)c2g(na2)b2

for all large n and some positive constants c1,c2,a1,a2,b1,b2.

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 L is a decision problem and x is the input, we often write xL to mean that the answer to the decision problem is yes, and xL 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 n is O(nk) for some constant k.

The class P is the set of all decision problems that are solvable in polynomial time. The class NP 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 Q can be reduced to Q if every instance of Q can be transformed into an instance of Q 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 Q to Q is a reduction that can be performed in polynomial time, denoted by QpQ. Intuitively, this means Q is no harder than Q.

A problem Q is NP-complete if and only if

  • QNP

  • Every problem LNP, LpQ

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 a,b,c be integers. Then the following holds:

  • If a|b and a|c, then a|(b+c) and a|(b-c).

  • If a|b, then a|bc.

  • If a|b and b|c, then a|c.

  • Corollary: If a,b,c are integers, where a0, such that a|b and a|c, then a|(mb+nc) for any integers m and n.

5.1.2 Modular Arithmetic

Let a,b,n be integers, where n>0. We say that a is congruent to b modulo n, denoted by ab(modn), if and only if n|(a-b). This is called congruence and n is called the modulus.

The following properties hold:

  • If ab(modn) and cd(modn), then a+cb+d(modn).

  • If ab(modn) and cd(modn), then acbd(modn).

  • Corollary: (a+b)modm=((amodm)+(bmodm))modm, and (ab)modm=((amodm)(bmodm))modm.

5.2 Prime

An integer p>1 is prime if and only if its only positive divisors are 1 and p. An integer n>1 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 a and b, denoted by gcd(a,b), is the largest integer that divides both a and b. If we factorize a and b into prime numbers, then gcd(a,b)=p1min(e1,f1)p2min(e2,f2)pkmin(ek,fk), where ei and fi are the exponents of pi in the factorization of a and b. Two integers are relatively prime if and only if their GCD is 1.

Similarly, we can define LCM of two integers a and b, denoted by lcm(a,b), is the smallest positive integer that is divisible by both a and b.

5.3 Eculidean Algorithm

The Eculidean algorithm is an efficient method for computing the GCD of two integers. It can solve the problem in O(logn) time, where n is the smaller of the two integers.

The central idea is that if a=bq+r, then gcd(a,b)=gcd(b,r). Here is the proof: If d is a common divisor of a and b, we can write da and db. By the corollary, we know that d(a-bq), which implies dr. Therefore, d is a common divisor of b and r.

For example, to compute gcd(287,91):

287mod91=14
91mod14=7
14mod7=0

Therefore, gcd(287,91)=7.

5.4 Bezout’s Theorem

Let a and b be integers, not both zero. Then there exist integers x and y such that gcd(a,b)=ax+by.

We can use the extended Eculidean algorithm to find x and y.

For example, since gcd(503,286)=1, we can find x and y such that 503x+286y=1, with the following steps:

Firstly, we use the Eculidean algorithm to find the GCD of 503 and 286:

503=1286+217
286=1217+69
217=369+10
69=610+9
10=19+1
9=91+0

Then, we can find x and y:

1=10-19
=10-1(69-610)=710-169
=7(217-369)-169=7217-269
=7217-22(286-1217)=2921722286
=29(503-1286)-22286=2950351286

Therefore, x=29 and y=-51.

The corollaries of Bezout’s theorem are:

  • If 1=gcd(a,b) and a|bc, then a|c.

  • If p is a prime and p|a1a2an, then p|ai for some i.

  • If acbc(modn) and gcd(c,n)=1, then ab(modn).

The proof of the first corollary is as follows: Since gcd(a,b)=1, we can find x and y such that ax+by=1. Then c=cax+cby. Since a|bc, we know that a|cby. Therefore, a|(cax+cby)=c.

5.5 Linear Congruence

A linear congruence is an equation of the form axb(modn), where a,b,n are integers and n>0.

5.5.1 Modular Inverse

Let a and n be integers, where n>0. If there exists an integer a¯ such that aa¯1(modn), then a¯ is called the modular inverse of a modulo n.

If a and n are relatively prime, then a has a modular inverse modulo n. Furthermore, the modular inverse of a modulo n is unique modulo n.

We can use the extended Eculidean algorithm to find the modular inverse of a modulo n.

5.5.2 Chinese Remainder Theorem

Let n1,n2,,nk be positive integers that are pairwise relatively prime, and let a1,a2,,ak be any integers. Then the system of linear congruences:

xa1(modn1)
xa2(modn2)
xak(modnk)

has a solution, and any two solutions are congruent modulo n1n2nk.

Let n=n1n2nk. Then the solution is x=a1y1nn1+a2y2nn2++akyknnk, where yi is the modular inverse of nni modulo ni.

For example, to solve the system of linear congruences:

x2(mod3)
x3(mod5)
x2(mod7)

We can find y1=2, y2=1, and y3=1. Therefore, x=2352+3211+2151=233 is a solution.

5.6 Fermat’s Little Theorem

Let p be a prime and a be an integer such that a0(modp). Then ap-11(modp).

5.7 Euler’s Theorem

Euler’s function ϕ(n) is the number of positive integers less than or equal to n that are relatively prime to n. The function has the following properties:

  • If p is prime, then ϕ(p)=p-1.

  • If p is prime and k1, then ϕ(pk)=pk-pk-1.

  • If m and n are relatively prime, then ϕ(mn)=ϕ(m)ϕ(n).

Euler’s theorem states that if n is a positive integer and a is an integer such that a and n are relatively prime, then aϕ(n)1(modn).

It is worth noting that ϕ(n) might not be the smallest positive integer k such that ak1(modn).

5.8 Primitive Roots

A primitive root modulo a prime p is an integer g such that every nonzero integer modulo p is congruent to a power of g modulo p.

6 Groups, Rings, and Fields

6.1 Groups

A group is a set G together with a binary operation * on G such that the following axioms hold:

  • Closure: For all a,bG, a*bG.

  • Associativity: For all a,b,cG, (a*b)*c=a*(b*c).

  • Identity: There exists a unique element 1eG such that for all aG, a*1e=a.

  • Inverse: For each aG, there exists an element a-1G such that a*a-1=1e.

6.1.1 Permutation Groups

A permutation group is a group whose elements are permutations of a given set S and whose operation is composition of permutations in S. Let sn=<1,2,,n> denotes a sequence of n elements, and Pn denotes the set of all permutations of sn. Then for any two elements π and ρ, πρ is also a permutation of sn.

For example, s3=<1,2,3>, and P3={<1,2,3>,<1,3,2>,<2,1,3>,<2,3,1>,<3,1,2>,<3,2,1>}. If π=<3,2,1> and ρ=<1,3,2>, then πρ=<2,1,3>. The operation is πρ[i]=ρ[π[i]].

Therefore, (Pn,) is a group.

6.1.2 Abeilian Groups

A group G is abeilian if and only if for all a,bG, a*b=b*a.

6.2 Rings

If (R,+) is an abeilian group, we define a second binary operation * on R such that the following axioms hold:

  • Closure: For all a,bR, a*bR.

  • Associativity: For all a,b,cR, (a*b)*c=a*(b*c).

  • Distributivity: For all a,b,cR, a*(b+c)=a*b+a*c and (a+b)*c=a*c+b*c.

6.2.1 Commutative Ring

A ring R is commutative if and only if for all a,bR, a*b=b*a.

6.2.2 Integral Domain

A commutative ring R is an integral domain if the following axiom holds:

  • Identity: There exists a unique element 1mR such that for all aR, a*1m=1m*a=a.

  • Nonzero product: For all a,bR, if a*b=0, then a=0 or b=0.

6.3 Fields

A commutative ring F is a field if the following axiom holds:

  • Inverse: For each aF, there exists an element a-1F such that a*a-1=a-1*a=1m.

6.4 Other Facts

  • Zm, the set of integers modulo m, is a commutative ring.

  • (GL(n),) is a group but not an abeilian group. (The set of all invertible n×n matrices)

  • (𝕄n×n,+,) is a ring but not a commutative ring.

  • (Zm,+m,m) 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. 1.

    Choose two large primes p and q.

  2. 2.

    Compute n=pq and ϕ(n)=(p-1)(q-1).

  3. 3.

    Choose e such that 1<e<ϕ(n) and gcd(e,ϕ(n))=1.

  4. 4.

    Compute d such that ed1(modϕ(n)).

  5. 5.

    Publish the public key (n,e) and keep the private key d secret.

To encrypt a message m, compute cme(modn). To decrypt a ciphertext c, compute mcd(modn).

The correctness of the algorithm is as follows:

cd(me)d(modn)
med(modn)
mkϕ(n)+1(modn)
m(mϕ(n))k(modn)
m1k(modn)
m(modn)

To leave a RSA signature, compute smd(modn). To verify a RSA signature, compute mse(modn).(d and e are interchangeable)

7.1.2 El Gamal Cryptosystem

The El Gamal public key cryptosystem works as follows:

  1. 1.

    Choose a large prime p and a primitive root g modulo p.

  2. 2.

    Choose x such that 1<x<p-2.

  3. 3.

    Compute ygx(modp).

  4. 4.

    Publish the public key (p,g,y) and keep the private key x secret.

To encrypt a message m, choose k such that 1<k<p-1 and gcd(k,p-1)=1, then compute c1gk(modp) and c2myk(modp). To decrypt a ciphertext (c1,c2), compute mc2(c1x)-1(modp).

The correctness of the algorithm is as follows:

c2(c1x)-1myk(gkx)-1(modp)
mgkxg-kx(modp)
m(modp)

7.2 Diffie-Hellman Key Exchange

The Diffie-Hellman key exchange works as follows:

  1. 1.

    Choose a large prime p and a primitive root g modulo p.

  2. 2.

    Alice chooses x such that 1<x<p-2 and sends ygx(modp) to Bob.

  3. 3.

    Bob chooses z such that 1<z<p-2 and sends wgz(modp) to Alice.

  4. 4.

    Alice computes wx(gz)xgzx(modp).

  5. 5.

    Bob computes yz(gx)zgxz(modp).

  6. 6.

    Now Alice and Bob share the secret key gxz(modp).

8 Mathematical Induction

8.1 Proof by Smallest Counterexample

To prove a statement P(n) for all nn0, we can use proof by smallest counterexample. We assume that P(n) is false for some n>0. Then there must be a smallest integer m such that P(m) is false. Since P(n0) is true, m>n0. Then we use the fact that P(m) the for all 0m<m is true to show that P(m) is true, which is a contradiction.

8.2 Direct Proof

8.2.1 Weak Principle of Mathematical Induction

If the statement P(b) is true, and the statement P(n-1)P(n) is true for all integers n>b, then the statement P(n) is true for all integers nb.

We call P(b) the basis step (inductive hypothesis) and P(n-1)P(n) the inductive step (inductive conclusion).

8.2.2 Strong Principle of Mathematical Induction

If the statement P(b) is true, and the statement P(b)P(b+1)P(n-1)P(n) is true for all integers n>b, then the statement P(n) is true for all integers nb.

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:

M(n)={1if n=12M(n-1)+1if n>1

Base case: When n=1, M(1)=1 is true.

Inductive hypothesis: Assume that M(k)=2k-1 is true for all k<n. Then for n, we have M(n)=2M(n-1)+1=2(2n-1-1)+1=2n-1.

8.3.1 Iteration

For a recursive equation in the form of T(n)=rT(n-1)+a, we can use iteration to solve it.

T(n)=rT(n-1)+a
=r2T(n-2)+ra+a
=r3T(n-3)+r2a+ra+a
=rkT(n-k)+rk-1a+rk-2a++ra+a
=rnT(0)+ai=0n-1ri

This is called the “Top-down” method.

The “Bottom-up” method is to start from T(0) and compute T(1),T(2),,T(n).

T(0)=b
T(1)=rT(0)+a=rb+a
T(2)=rT(1)+a=r(rb+a)+a=r2b+ra+a
T(n)=rT(n-1)+a=r(rn-1b+ai=0n-2ri)+a
=rnb+ai=0n-1ri

Formula of Recursive Equations: If T(n)=rT(n-1)+a and T(0)=b, then we have

T(n)=rnb+ai=0n-1ri=rnb+arn-1r-1

8.3.2 First Order Linear Recurrence

A first order linear recurrence is a recurrence of the form T(n)=rT(n-1)+a. First order means that the recurrence is defined by T(n) and T(n-1), or to say it only goes back one step. Linear means that the power of T(n-1) is 1.

For a first order linear recurrence that f(n) is a constant, we have:

T(n)={aif n=0rT(n-1)+g(n)if n>0

Then we have

T(n)=rna+i=1nrn-ig(i)

This equation can often be solved by extracting the constant factor rn.

T(n)=rna+rni=1ng(i)ri

We can use the theorem that combines the geometric series and the arithmetic series to solve the equation.

i=1nixi=x-(n+1)xn+1+nxn+2(1-x)2

8.3.3 Divide and Conquer Recurrence

A divide and conquer recurrence is a recurrence of the form T(n)=aT(n/b)+f(n). This can be solved by the regular “Top-down” method.

T(n)=2T(n/2)+n( assume n=2k)
=4T(n/4)+2n
=8T(n/8)+3n
=2iT(n/2i)+in
=2log2nT(n/2log2n)+nlog2n( ends when n/2log2n=1)
=nT(1)+nlog2n

8.3.4 Master Theorem

Suppose that T(n)=aT(n/b)+cnd, where a is a positive integer, b1 and c and d are constants. Then T(n) has the following asymptotic bounds:

  1. 1.

    If a<bd, then T(n)=Θ(nd).

  2. 2.

    If a=bd, then T(n)=Θ(ndlogn).

  3. 3.

    If a>bd, then T(n)=Θ(nlogba).

9 Counting

9.1 Basic Counting Principles

9.1.1 Product Rule

If there are n1 ways to perform action 1, and for each of these ways of performing action 1, there are n2 ways to perform action 2, then there are n1n2 ways to perform action 1 and then action 2.

9.1.2 Sum Rule

If there are n1 ways to perform action 1, and n2 ways to perform action 2, and the two actions cannot be performed at the same time, then there are n1+n2 ways to perform either action 1 or action 2.

9.2 Pigeonhole Principle

If there are k+1 objects to be placed into k boxes, then there is at least one box containing two or more objects.

Generalized version: If there are N objects to be placed into k boxes, then there is at least one box containing at least N/k objects.

9.3 Permutations and Bijection

A bijection that maps a set S to itself is called a permutation of S.

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 n, we can define a bijection as follows:

f((a1,a2,,an))={a1,a2,,an}

This means the number of increasing tuple of size n is the same as the number of subsets of size n of a set with n elements, which is (nk).

9.4 Inclusion-Exclusion Principle

If S is a finite set and A1,A2,,An are its subsets, then

|i=1nAi|=k=1n(-1)k+11i1<i2<<ikn|Ai1Ai2Aik|

This can be proved by mathematical induction.

Base case: When n=2, we have

|EF|=|E|+|F|-|EF|

Inductive hypothesis: Assume that the equation is true for n=k. Then for n=k+1, we have

|i=1k+1Ai|=|i=1kAi|+|Ak+1|-|(i=1kAi)Ak+1|

Notice that the right most term |(i=1kAi)Ak+1|=|i=1k(AiAk+1)|. 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 A with m elements to a set B with n elements. Firstly, the number of all possible functions is nm. Then we try to exclude the functions that are not onto. Let the set Ei be the set of functions that map nothing to element i. Then we have

#(onto functions)=nm-|E1E2En|
=nm-k=1n(-1)k+11i1<i2<<ikn|Ei1Ei2Eik|
=nm-k=1n(-1)k+1(nk)(n-k)m

9.5 k-Element Permutations

An ordered tuple of k distinct elements taken from set N is called a k-element permutation of N.

If N is a positive integer and k is an integer that satisfies 1kN, then there are

P(n,k)=n(n-1)(n-2)(n-k+1)
=n!(n-k)!

9.6 Binomial Coefficients

For integers n and k with 0kn, the number of k-element subsets of an n-element set is denoted by (nk) and is called a binomial coefficient.

(nk)=C(n,k)=P(n,k)k!=n!k!(n-k)!

9.6.1 Properties of Binomial Coefficients

  1. 1.

    (n0)=(nn)=1

  2. 2.

    (nk)=(nn-k)

  3. 3.

    k=0n(nk)=2n This can be interpreted as: the number of subsets of an n-element set is equal to the sum of the number of k-element subsets of an n-element set for k=0,1,,n.

  4. 4.

    Pascal’s identity: (nk)=(n-1k-1)+(n-1k) This can be interpreted as: the number of k-element subsets of an n-element set is equal to the sum of the number of subsets that contain element n and the number of subsets that do not contain element n.

9.6.2 Binomial Theorem

For any real numbers x and y and any non-negative integer n, we have

(x+y)n=k=0n(nk)xn-kyk

This can be proved by induction and Pascal’s identity.

Base case: When n=0, (x+y)0=1=(00)x0y0.

Inductive hypothesis: Assume that the equation is true for n=k. Then for n=k+1, we have

(x+y)k+1=(x+y)k(x+y)
=i=0k(ki)xk-iyi(x+y)
=i=0k(ki)xk-i+1yi+i=0k(ki)xk-iyi+1
=i=0k(ki)xk-i+1yi+i=1k+1(ki-1)xk-i+1yi
=(k0)xk+1+i=1k((ki)+(ki-1))xk-i+1yi+(kk)yk+1
=(k+10)xk+1+i=1k(k+1i)xk-i+1yi+(k+1k+1)yk+1

9.6.3 Labeling and Trinomial Coefficients

When k1+k2++kr=n, the number of ways to label n distinct objects with r distinct labels so that there are ki objects with label i is

(nk1,k2,,kr)=n!k1!k2!kr!

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 (nk) is the number of k-element subsets of an n-element set. The term (n-1k-1) is the number of k-1-element subsets of an (n-1)-element set. The term (n-1k) is the number of k-element subsets of an (n-1)-element set. We can make a bijection between the two sides: On the right side, the first term represent the number of k-element subsets of an n-element set that contains element n. The second term represent the number of k-element subsets of an n-element set that does not contain element n. Therefore, the two sides are equal.

9.8 Birthday Attack

The probablity that at least two people in a group of n people have the same birthday is

P(n)=1-P(all people have different birthdays)
=1-365365364365363365365-n+1365
=1-i=0n-1(1-i365)

We can estimate this number using the Taylor series of ex. Since ex=1+x+x22!+x33!+, for |x|<<1, we have ex1+x. Thus, e-i/H1-iH.

P(n)=1-i=0n-1(1-i365)
1-i=0n-1e-i/365
=1-e-i=0n-1i/365

10 Linear Recurrence

A linear homogeneous recurrence of degree k with constant coefficients is a recurrence of the form

an=c1an-1+c2an-2++ckan-k

where c1,c2,,ck are constants and ck0.

“Linear” means that the power of each term is 1. “Homogeneous” all terms are a multiple of an. “Degree k means that an is defined by previous k terms. “Constant coefficients” means that the coefficients c1,c2,,ck are constants.

By induction, we know that such a relation is uniquely determined by the initial values a0,a1,,ak-1.

10.1 Solving Linear Recurrence

To solve a linear homogeneous recurrence of degree k with constant coefficients, we first find the roots of the characteristic equation xk-c1xk-1-c2xk-2--ck=0. 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 Fn=Fn-1+Fn-2:

  1. 1.

    Find the roots of x2-x-1=0, which are 1±52.

  2. 2.

    The general solution is Fn=α(1+52)n+β(1-52)n.

  3. 3.

    Since F0=0 and F1=1, we have α=15 and β=-15.

Theorem: If the characteristic equation has k distinct real roots r1,r2,,rk, then {an} is a solution of the recurrence if and only if

an=α1r1n+α2r2n++αkrkn

To prove this, we need to prove two statements:

  1. 1.

    {an} in the form of α1r1n+α2r2n++αkrkn is a solution of the recurrence.

  2. 2.

    Any solution of the recurrence is in the form of α1r1n+α2r2n++αkrkn.

Statement 1: Let’s take an example that degree is 2. Since r1 and r2 are roots of the characteristic equation, we have

r12-c1r1-c2=0
r22-c1r2-c2=0

Then, we can find that

c1an-1+c2an-2=c1(α1r1n-1+α2r2n-1)+c2(α1r1n-2+α2r2n-2)
=α1r1n-2(c1r1+c2)+α2r2n-2(c1r2+c2)
=α1r1n-2(r12)+α2r2n-2(r22)
=α1r1n+α2r2n
=an

Hence, {an} in the form of α1r1n+α2r2n is a solution of the recurrence.

Statement 2:

With the initial values, we can find all the constant α1,α2,,αk, 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 {an} is the same as α1r1n+α2r2n++αkrkn.

10.1.1 Degenerate Roots

For a characteristic equation of degree 2, if the two roots are the same, then the general solution is

an=α1r1n+α2nr2n

Theorem: Suppose there are t roots r1,r2,,rt of multiplicity m1,m2,,mt respectively. Then the general solution of the recurrence is

an=i=1tj=1miαijnj-1rin

10.2 Linear Nonhomogeneous Recurrence

A linear nonhomogeneous recurrence of degree k with constant coefficients is a recurrence of the form

an=c1an-1+c2an-2++ckan-k+f(n)

The associated homogeneous recurrence is an=c1an-1+c2an-2++ckan-k.

However, there is no general method to solve the particular solution f(n). We can only solve it by guessing.

11 Generating Functions

The generating function for a sequence a0,a1,a2, is the formal power series

G(x)=i=0aixi

A finite sequence a0,a1,,an can be represented by the generating function by adding 0s to the end of the sequence.

11.1 Operations on Generating Functions

Let G(x)=i=0aixi and H(x)=i=0bixi be two generating functions. Then we have

G(x)+H(x)=i=0(ai+bi)xi
G(x)H(x)=i=0(j=0iajbi-j)xi

11.2 Useful Generating Functions

  • 11-x=1+x+x2+x3+

  • 11-ax=1+ax+a2x2+a3x3+

  • 11-xr=1+xr+x2r+x3r+

  • 1(1-x)2=1+2x+3x2+4x3+

  • 1(1-x)n=k=0(n+k-1k)xk

  • 1(1+x)n=k=0(-nk)xk

  • 1(1-ax)n=k=0(n+k-1k)akxk

  • 1-xn+11-x=1+x+x2++xn

  • (1+x)n=(n0)+(n1)x+(n2)x2++(nn)xn

  • (1+ax)n=(n0)+(n1)ax+(n2)a2x2++(nn)anxn

  • (1+xr)n=(n0)+(n1)xr+(n2)x2r++(nn)xnr

  • ex=1+x+x22!+x33!+

  • ln(1+x)=x-x22+x33-x44+

Here is a way to derive the generating function if we forget it: Suppose G(x)=1+x+x2+x3+. Then xG(x)=x+x2+x3+x4+. Then G(x)-xG(x)=1, thus G(x)=11-x. The other generating functions can be derived similarly, or by operations on the generating functions (for example, (1+x)2=(1+x)(1+x)).

Another way is to use the MacLaurin series of the function. Here is the general formula:

f(x)=f(0)+f(0)x+f′′(0)2!x2+f′′′(0)3!x3+=i=0f(i)(0)i!xi

11.3 Counting with Generating Functions

Convolution:

Let G(x)=i=0aixi and H(x)=i=0bixi be two generating functions. Then the coefficient of xk in G(x)H(x) is i=0kaibk-i.

11.3.1 k-Combination with Repetition

The number of k-combinations with repetition allowed means to choose k elements from a set S and repetition is allowed. The generating function for this is

(11-x)n=k=0(n+k-1k)xk

11.3.2 Extended Binomial Theorem

The extended binomial theorem is

(1+x)n=k=0(nk)xk

where n is a real number and |x|<1.

Corollary:

(-nk)=(-n)(-n-1)(-n-2)(-n-k+1)k!
=(-1)kn(n+1)(n+2)(n+k-1)k!
=(-1)k(n+k-1k)

12 Relation

Let A and B be two sets. A binary relation R from A to B is a subset of A×B. 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 A is a relation from A to A. The number of relation on a set A is 2|A|2.

12.1 Properties of Relations

12.1.1 Reflexive

A relation R on a set A is reflexive if (a,a)R for all aA. In the matrix representation, the diagonal elements are all 1 if the relation is reflexive. For example, the divisible relation is reflexive, since a|a for all a.

12.1.2 Irrreflexive

A relation R on a set A is irreflexive if (a,a)R for all aA. In the matrix representation, the diagonal elements are all 0 if the relation is irreflexive. For example, the not equal relation is irreflexive, since a=a for all a.

12.1.3 Symmetric

A relation R on a set A is symmetric if (a,b)R implies (b,a)R for all a,bA. In the matrix representation, the matrix is symmetric if the relation is symmetric. For example, the equal relation is symmetric, since a=b implies b=a for all a,b.

12.1.4 Antisymmetric

A relation R on a set A is antisymmetric if (a,b)R and (b,a)R implies a=b for all a,bA. 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 a|b and b|a implies a=b for all a,b.

12.1.5 Transitive

A relation R on a set A is transitive if (a,b)R and (b,c)R implies (a,c)R for all a,b,cA. For example, the divisible relation is transitive, since a|b and b|c implies a|c for all a,b,c.

Theorem: The relation is transitive if and only if RnR for all n1.

The “if” part: If RnR for all n1, then specifically R2R. Then (a,b)R and (b,c)R implies (a,c)R.

The “only if” part: Proof by induction. The base case is trivial. Suppose RnR for all n1. Then we need to prove Rn+1=RnR. Since RnR, every element in Rn in also in R. Since R is transitive, every element in RR is also in R. Therefore, Rn+1R.

12.2 Composite Relation

Let R be a relation from A to B and S be a relation from B to C. Then the composite relation SR from A to C is defined as

SR={(a,c)A×C| there exists bB such that (a,b)R and (b,c)S}

12.3 Closure of a Relation

The reflexive closure of a relation R is a set S that contains all elements of R, 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 R be a relation on a set A. A relation S on A with property P is called the closure of R with respect to P if S is subset of all relations on A with property P and RS. In other words, S is the smallest relation on A with property P that contains R.

How to find transitive closure: Find all pairs that are connected in the graph.

12.4 Path and Circuit

A path from a to b in a relation R is a finite sequence of elements a0,a1,,an such that a0=a, an=b and (ai,ai+1)R for i=0,1,,n-1. A circuit is a path that starts and ends at the same element.

Theorem: There is a path of length n from a to b in R if and only if (a,b)Rn. This can be proved by induction.

12.4.1 Connectivity Relation

The connectivity relation R on a set A that contains all pairs (a,b) such that there is a path from a to b in R is an equivalence relation.

Or more formally,

R=n=1Rn

Since a path that has no loop has at most |A| elements, we can simplify the above equation to

R=n=1|A|Rn

The transitive closure of R is the connectivity relation. To prove this, we need to prove two statements:

  1. 1.

    The connectivity relation is transitive.

  2. 2.

    The connectivity relation is the smallest transitive relation that contains R.

Statement 1: If there is a path from a to b and a path from b to c, then there is a path from a to c.

Statement 2: Let S be a transitive relation that contains R. Then R*S*S, where R* is the transitive closure of R and S* is the transitive closure of S.

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 [a] or [a]R.

The following statements are equivalent:

  1. 1.

    aRb

  2. 2.

    [a]=[b]

  3. 3.

    [a][b]

Proof:

  1. 1.

    (1) (2): [a][b] and [b][a].

  2. 2.

    (2) (3): [a]=[b] implies [a][b], since there is at least one element in [a] and [b].

  3. 3.

    (3) (1): [a][b] implies there is an element c such that c[a] and c[b]. Then aRc and cRb implies aRb.

A partition of a set A is a collection of nonempty subsets of A such that every element of A is in exactly one of these subsets.

AiAj= for ij and i=1Ai=A

The equivalence classes of an equivalence relation on a set A form a partition of A.

12.6 Partial Order

A partial order is a relation that is reflexive, antisymmetric and transitive. A set A with a partial order is called a partially ordered set or poset.

12.6.1 Comparable

Two elements a and b in a poset are comparable if either ab or ba.

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 A×B is defined as

(a,b)(c,d) if and only if a<c or (a=c and bd)

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 a in a poset is maximal if there is no element b such that a<b. An element a in a poset is minimal if there is no element b such that b<a.

The greatest element a in a poset is an element such that ab for all bA, which sometimes does not exist. We can define the least element similarly.

12.6.6 Upper and Lower Bound

An element a in a poset is an upper bound of a set S if ab for all bS. The least upper bound of a set S is an element a such that a is an upper bound of S and ab for all upper bounds b of S. 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 G is an ordered pair (V,E), where V is a finite set and E is a set of unordered pairs of distinct elements of V. 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 Kn.

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 v by N(v).

13.4 Directed Graph

A directed graph is a graph in which the edges are ordered pairs. If (u,v) is an edge in a directed graph, then we say that u is adjacent to v and v is adjacent from u.

13.5 Degree

The degree of a vertex v in an undirected graph is the number of edges incident to v, denoted by deg(v). The in-degree of a vertex v in a directed graph is the number of edges that end at v, denoted by deg-(v). The out-degree of a vertex v in a directed graph is the number of edges that start at v, denoted by deg+(v).

13.5.1 Handshaking Theorem

In an undirected graph, the sum of the degrees of all vertices is twice the number of edges.

vVdeg(v)=2|E|

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.

vVdeg-(v)=vVdeg+(v)=|E|

13.6 Cycle

A cycle is a simple graph in which all vertices have degree 2, denoted by Cn.

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 Wn.

13.8 N-Dimensional Hypercube

An N-dimensional hypercube is a graph with 2N vertices, each of which is labeled by an N-bit string. Two vertices are adjacent if and only if their labels differ in exactly one bit. An N-dimensional hypercube is denoted by QN, has N2N-1 edges and N2N-1 vertices of degree N. An N-dimensional hypercube is always bipartite.

13.9 Bipartite Graph

A bipartite graph is a graph whose vertices can be partitioned into two sets V1 and V2 such that every edge has one endpoint in V1 and the other endpoint in V2. 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 Km,n, where m is the number of vertices in V1 and n is the number of vertices in V2. 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 V1 is adjacent to every vertex in V2, denoted by Km,n.

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 V1 is incident to an edge in the matching, or |M|=|V1|.

Hall’s Marriage Theorem: A bipartite graph G with bipartition (V1,V2) has a complete matching from V1 to V2 if and only if |N(S)||S| for all SV1.

13.10 Union of Graphs

The union of two graphs G1=(V1,E1) and G2=(V2,E2) is the graph G=(V1V2,E1E2).

13.11 Representation of Graph

13.11.1 Adjacency Matrix

The adjacency matrix of a graph G is a |V|×|V| matrix A such that

Aij={1 if (i,j)E0 otherwise

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 G is a |V|×|E| matrix B such that

Bij={1 if vertex i is incident to edge j0 otherwise

13.11.3 Adjacency List

The adjacency list of a graph G 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 G1=(V1,E1) and G2=(V2,E2), an isomorphism from G1 to G2 is a bijection f:V1V2 such that (u,v)E1 if and only if (f(u),f(v))E2. 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 k for k=3,4,5,

13.13 Path

A path from u to v in a graph G is a sequence of n edges e1,e2,,en such that ei=(xi,xi+1) for i=1,2,,n-1 and x1=u and xn=v. The length of a path is the number of edges in the path. The path is a cycle if u=v. A path or cycle is simple if it does not contain the same edge more than once.

Lemma: If there is a path from u to v in a graph G, then there is a simple path from u to v in G.

13.13.1 Connected

A graph G is connected if there is a path from u to v for every pair of vertices u and v in G.

13.13.2 Connected Component

A connected component of a graph G is a maximal connected subgraph of G. A directed graph is strongly connected if there is a path from u to v and a path from v to u for every pair of vertices u and v in G. 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 E is an edge cut if G-E is disconnected. The edge connectivity of a graph G is the minimum size of an edge cut of G, denoted by λ(G).

13.13.4 Counting Paths

The number of paths of length k from u to v in a graph G is the (u,v)-entry of Ak, where A is the adjacency matrix of G.

13.14 Eular Path and Circuit

An Eular path in a graph G is a simple path that contains every edge of G. An Eular circuit in a graph G is a simple circuit that contains every edge of G.

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 G is a simple path that passes through every vertex of G exactly once. A Hamilton circuit in a graph G is a simple circuit that passes through every vertex of G exactly once.

Dirac’s Theorem: If G is a simple graph with n vertices such that n3 and deg(v)n2 for every vertex v of G, then G has a Hamilton circuit.

Ore’s Theorem: If G is a simple graph with n vertices such that n3 and deg(u)+deg(v)n for every pair of nonadjacent vertices u and v of G, then G has a Hamilton circuit.

13.16 Shortest Path

If G is a weighted graph, the shortest path from u to v is the path from u to v 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 u to every other vertex in a weighted graph G. The algorithm is as follows:

  1. 1.

    Let S={u} and d(u)=0.

  2. 2.

    For every vertex vV-S, let d(v) be the length of the shortest path from u to v.

  3. 3.

    Choose a vertex wV-S such that d(w) is minimum and add w to S.

  4. 4.

    For every vertex vV-S, if d(w)+l(w,v)<d(v), then let d(v)=d(w)+l(w,v).

  5. 5.

    Repeat steps 3 and 4 until S=V.

The runtime of Dijkstra’s algorithm is O(|V|2), but can be improved to O(|E|+|V|log|V|) 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 O(|V||E|) time.

13.17 Planar Graph

A planar graph is a graph that can be drawn in the plane without any edges crossing. An n-dimensional hypercube is planar if and only if n3. A complete graph Kn is planar if and only if n4.

13.17.1 Euler’s Formula

If G is a connected planar graph with v vertices, e edges and r regions, then

v-e+r=2

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 G is a connected planar simple graph with v vertices, e edges and v3, then e3v-6. This is because each region is bounded by at least 3 edges and each edge is counted twice. Hence 2e=rRdeg(r)3r. Then we substituted r in the Euler’s formula and get e3v-6.

  • If G 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, 2e6v. Then e3v. Then by the corollary above, 3ve3v-6, which is a contradiction.

  • If G is a connected planar simple graph with v vertices, e edges and v3, but has no circuits of length 3, then e2v-4. Similar to the first corollary, each region is bounded by at least 4 edges and each edge is counted twice. Hence 2e=rRdeg(r)4r. Then we substituted r in the Euler’s formula and get e2v-4.

13.17.2 Kuratowski’s Theorem

If a graph G is planar, so will be any graph obtained from G 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 K5 or K3,3.

13.17.3 Platonic Solids

There are only 5 platonic solids:

  • Tetrahedron ({3,3})

  • Cube ({4,3})

  • Octahedron ({3,4})

  • Dodecahedron ({5,3})

  • Icosahedron ({3,5})

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 n faces:

  • r=n

  • pr=qv=2e

Combining this two equations with Euler’s formula, we get

1p+1q=12+1r>12

Iterating through all possible values of p, q and r, we get the five platonic solids.

13.18 Graph Coloring

A coloring of a graph G is an assignment of a color to each vertex of G such that no two adjacent vertices have the same color. The chromatic number of a graph G, denoted by χ(G), is the minimum number of colors needed to color G.

By the Four Color Theorem, every planar graph can be colored with at most 4 colors, or χ(G)4. 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 χ(G)6. 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 χ(G)5.

Six Color Theorem: By induction on the number of vertices. Base case: |V|=1. Inductive step: Suppose every planar graph with n vertices can be colored with at most 6 colors. By the previous corollary, there exists a vertex v of degree at most 5. We remove the vertex v and by inductive hypothesis, the remaining graph can be colored with at most 6 colors. Then we put back the vertex v, since it has at most 5 neighbors, there is at least one color that is not used by its neighbors. Then we can color v 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 v1,v2,v3,v4,v5, and the color of vi be ci. Then there are 2 cases:

  1. 1.

    There is no path from v1 to v3, then we can use the color c1 to color v3. (If there is a vertex adjacent to v3 and colored c1, we use c3 to color it. Basically we flip the color of a chain that c3 and c1 are used repeatedly) Then c3 is never used and can be used to color the vertex v.

  2. 2.

    There is a path from v1 to v3, since this will create a cycle, then there must be no path from v2 to v4. 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 m-ary tree if every vertex has at most m children. A full m-ary tree is an m-ary tree in which every internal vertex has exactly m children. A full m-ary tree with n vertices, i of which are internal, l leaves satisfies the following equations:

n=mi+1,n=i+l

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 h or h-1. There are at most mh leaves in an m-ary tree of height h. The equation hlogml holds for any m-ary tree with l 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, 3+4 is written as +34. 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, 3+4 is written as 34+. This corresponds to the postorder traversal of the expression tree.

13.20 Catalan Number

The Catalan number Cn is the number of different binary trees with n vertices. Since a binary tree can be partitioned into a root, a left subtree and a right subtree, we have the following recurrence relation:

Cn=i=0n-1CiCn-1-i

Let f(x)=i=0Cixi. Then we have

f(x)2=(i=0Cixi)(j=0Cjxj)
=i=0j=0CiCjxi+j
=n=0i=0nCiCn-ixn
=n=0Cn+1xn

Then we have

xf(x)2+1=f(x)

Solving the quadratic equation, we get

f(x)=1±1-4x2x

Since f(0)=1, we have

f(x)=1-1-4x2x

Then, using the extended binomial theorem, we have

1-4x=i=0(12i)(-4x)i

Substituting this into the equation above, we get

1-1-4x2x=1-i=0(12i)(-4x)i2x
=-i=1(12i)(-4x)i2x
=i=1-12(12i)(-4)ixi-1
=i=0-12(12i+1)(-4)i+1xi

Then we have

Cn=-12(12n+1)(-4)n+1
=-1212(12-1)(12-2)(12-n)(n+1)!(-4)n+1
=-12(-1)n12n+1135(2n-1)(n+1)!(-4)n+1
=2n135(2n-1)(n+1)!
=1n+11234(2n-1)2nn!n!
=1n+1(2nn)

13.21 Spanning Tree

A simple graph G 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 G.

runtime: O(elogv)

correctness: By induction on the number of edges. Suppose the current tree is T and it is a subgraph of some minimum spanning tree M. When adding an edge e to the tree T, we want to prove that T{e} is still a subgraph of some minimum spanning tree M. If e is in M, then T{e} is a subgraph of M. If e is not in M, then T{e} contains a cycle. Then there must be an edge f in the cycle that is not in T. Then M{e}-{f} is another minimum spanning tree that contains T{e}.

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: O(eloge)

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 f1f2fk, where each fi is li1li2lik, where each lij is a literal.

13.22.1 2-CNF

The 2-CNF expression is satisfiable, and is polynomial time decidable. For each disjunction li1li2, we add an edge between ¬li1 and li2 and ¬li2 and li1. Then if there is exists a path from l to ¬l and ¬l to l, then the expression is not satisfiable.

Proof:

  • Claim 1: If there is a path from x to y, then there is no path from ¬y to ¬x.

  • Claim 2: The expression is unsatisfiable if and only if there is a variable x such that there is a path from x to ¬x and ¬x to x. 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 x, with no path from x to ¬x.

    • Assign x to and all its reachable literals to .

    • Assign ¬x to and all its reachable literals to .

    • Repeat until all literals are assigned.

    This assignment is well defined because there is no path from x to y and ¬y at the same time. If so, by claim 1 we know there is a path from y to ¬x, then concatenating the two paths, we get a path from x to ¬x, 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 G is a subset S of vertices such that every two vertices in S 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 k. We can reduce a k-SAT problem to a DCLIQUE problem by constructing a graph G 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 G with vertices representing every literals (allow duplicates) and edges across clauses (but not from x to ¬x). A clique of size k in G corresponds to a set of literals that satisfies k clauses.

A vertex color of a graph G 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 k. We can reduce a DVC problem to a vertex coloring problem by constructing a complement graph G of G. If there is a vertex color of size k in G, then there is a clique of size |V|-k in G.

We have a 2-approximation algorithm for vertex coloring.

  1. 1.

    Choose an arbitrary edge e=(u,v) in E.

  2. 2.

    Remove all edges incident to u and v.

  3. 3.

    Repeat until all edges are removed.

This is because the algorithm gives a maximum matching for G. 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

|C|=2|M|2|C*|,|C||C*|2