You are on page 1of 7

CS1231 Cheatsheet

for finals, by ning

Appendix A of Epp is not covered. Theorems, corollar- Rules of Inference Universal Generalization true. We call p the hypothesis (or antecedent), and q
ies, lemmas, etc. from the Epp textbook are prefixed Modus ponens If P (c) must be true, and we have assumed nothing the conclusion (or consequent).
with ‘Epp’; those without asterisks (*) are from the p→q about c, then ∀x, P (x) is true.
lecture notes, those with the asterisk are not (e.g. A conditional statement that is true because its hy-
Epp theorems not covered by the lecture). In titles, p Regular Induction pothesis is false is called vacuously true or true by
‘T’ is short for theorem, ‘L’ for lemma, ’C’ for corollary. ·q Modify the domain of the quantifiers below according default.
to P , if necessary:
Modus tollens
Proofs P (0) Definition 2.2.2 (Contrapositive)
p→q The contrapositive of p → q is ¬q → ¬p.
∀k ∈ N, P (k) → P (k + 1)
Basic Notation ¬q
∀k ∈ N, P (n) Definition 2.2.3 (Converse)
· ¬p
R set of real numbers Epp T2.1.1 Logical Equivalences The converse of p → q is q → p.
Z set of integers (includes 0) Generalization
Commutative Laws
Q set of rationals p Definition 2.2.4 (Inverse)
N set of natural numbers (usually includes 0) p∧q ≡q∧p The inverse of p → q is ¬p → ¬q.
·p∨q
∃ there exists... p∨q ≡q∨p
∃! there exists a unique... Specialization Definition 2.2.6 (Biconditional)
∀ for all... Associative Laws The biconditional of p and q is denoted p ↔ q and is
p∧q
∈ member of... (p ∧ q) ∧ r ≡ p ∧ (q ∧ r) true if both p and q have the same truth values, and
3 such that... ·p
(p ∨ q) ∨ r ≡ p ∨ (q ∨ r) is false if p and q have opposite truth values.
Elimination
Proof Types
p∨q Distributive Laws Definition 2.2.7 (Necessary & Sufficient)
p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) “r is sufficient for s” means r → s, “r is necessary for
- By Construction: finding or giving a set of direc- ¬q s” means ¬r → ¬s or equivalently s → r.
tions to reach the statement to be proven true. In ·p p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r)
proving equality, a useful note: Transitivity Definition 2.3.2 (Sound & Unsound Arguments)
Identity Laws
a≤b∧a≥b→a=b p∧t≡p An argument is called sound, iff it is valid and all its
p→q premises are true.
- By Contraposition: proving a statement through q→r p∨c≡p
its logically equivalent contrapositive. ·p→r Definition 3.1.3 (Universal Statement)
Negation Laws A universal statement is of the form
- By Contradiction: proving that the negation of Proof by Division into Cases p ∨ ¬p ≡ t
the statement leads to a logical contradiction. ∀x ∈ D, Q(x)
p∨q p ∧ ¬p ≡ c
- By Exhaustion: considering each case. It is defined to be true iff Q(x) is true for every x in
p→r D. It is defined to be false iff Q(x) is false for at least
- By Mathematical Induction: proving for a base Double Negative Law
q→r one x in D.
case, then an induction step. In the inductive step, ¬(¬p) ≡ p
work from the k + 1, not the k case. ·r
Idempotent Laws Definition 3.1.4 (Existential Statement)
- By Strong Induction: mathematical induction as- Contradiction Rule p∧p≡p A existential statement is of the form
suming P (k), P (k − 1), · · · , P (a) are all true. ¬p → c ∃x ∈ D s.t. Q(x)
p∨p≡p
·p It is defined to be true iff Q(x) is true for at least one
Order of Operations Universal Bound Laws x in D. It is defined to be false iff Q(x) is false for all
Universal Rules of Inference
First ∼ (also represented as ¬). No priority within ∧ x in D.
Only modus ponens, modus tollens, and transitivity p∨t≡t
and ∨, so p ∧ q ∨ r is ambiguous and should be written
have universal versions in the lecture notes. p∧c≡c
as (p ∧ q) ∨ r or p ∧ (q ∨ r). The implication, → is Theorem 3.2.1 (Negation of Universal State.)
performed last. Can be overwritten by parenthesis. The negation of a statement of the form
Implicit Quantification De Morgan’s Laws
The notation P (x) =⇒ Q(x) means that every ¬(p ∧ q) ≡ ¬p ∨ ¬q ∀x ∈ D, P (x)
Universal & Existential Generalisation
element in the truth set of P (x) is in the truth set of
‘All boys wear glasses’ is written as ¬(p ∨ q) ≡ ¬p ∧ ¬q is logically equivalent to a statement of the form
Q(x), or equivalently, ∀x, P (x) → Q(x).
∀x(Boy(x) → Glasses(x)) ∃x ∈ D s.t. ¬P (x)
Absorption Laws
If conjunction was used, this statement would be fal- The notation P (x) ⇐⇒ Q(x) means that P (x) Theorem 3.2.2 (Negation of Existential State.)
and Q(x) have identical truth sets, or equivalently, p ∨ (p ∧ q) ≡ p
sified by the existence of a ‘non-boy’ in the domain of x. The negation of a statement of the form
∀x, P (x) ↔ Q(x). p ∧ (p ∨ q) ≡ p
∃x ∈ D s.t. P (x)
‘There is a boy who wears glasses’ is written as
Implication Law Negations of t and c is logically equivalent to a statement of the form
∃x(Boy(x) ∧ Glasses(x))
¬t ≡ c ∀x ∈ D, ¬P (x)
If implication was used, this statement would true p → q ≡ ¬p ∨ q ¬c ≡ t Number Theory
even if the domain of x is empty.
Universal Instantiation Definition 2.2.1 (Conditional)
Properties (of Numbers)
Valid Arguments as Tautologies If some property is true of everything in a set, then it If p and q are statement variables, the conditional of q
All valid arguments can be restated as tautologies. is true of any particular thing in the set. by p is “if p then q” or “p implies q”, denoted p → q. Closure, i.e.
It is false when p is true and q is false; otherwise it is ∀x, y ∈ Z, x + y ∈ Z, and xy ∈ Z
Commutativity, i.e. For any two primes p and p0 , Proposition 4.5.2 (Existence of gcd) 4. a and b have the same non-negative remainder
a + b = b + a and ab = ba
0
p|p →p=p
0 For any integers a, b, not both zero, their gcd exists when divided by n
and is unique. 5. a mod n = b mod n
Distributivity, i.e. Theorem 4.2.3
If p is a prime and x1 , x2 , · · · , xn are any inte- Epp T8.4.3 (Modulo Arithmetic)
a(b + c) = ab + ac and (b + c)a = ba + ca Theorem 4.5.3 (Bézout’s Identity) Let a, b, c, d, n ∈ Z, n > 1, and suppose
gers s.t. p | x1 x2 · · · xn , then p | xi for some Let a, b be integers, not both zero, and let d =
Trichotomy, i.e. xi , i ∈ {1, 2, · · · , n}. gcd(a, b). Then there exists integers x, y such that a ≡ c (mod n) and b ≡ d (mod n)
(a < b) ⊕ (b < a) ⊕ (a = b)
Epp T4.3.5 (Unique Prime Factorisation) ax + by = d Then
(Can be used without proof)
Given any integer n > 1 Or, the gcd of two integers is some linear combination 1. (a + b) ≡ (c + d) (mod n)
∃k ∈ Z ,
+ of the said numbers, where x, y above have multiple 2. (a − b) ≡ (c − d) (mod n)
Definition 1.1.1 (Colorful) solution pairs once a solution pair (x, y) is found. Also 3. ab ≡ cd (mod n)
An integer n is said to be colorful if there exists some ∃p1 , p2 , · · · , pk ∈ primes, solutions, for any integer k, 4. am ≡ cm (mod n), for all m ∈ Z+
integer k such that n = 3k. +
∃e1 , e2 , · · · , ek ∈ Z ,
kb ka Epp C8.4.4
such that (x + ,y − )
Definition 1.3.1 (Divisibility) e e e d d Let a, b, c, d, n ∈ Z, n > 1, then
If n and d are integers and d 6= 0, n= p11 p22 · · · pkk
*Epp T8.4.8 (Euclid’s Lemma) ab ≡ [(a mod n)(b mod n)] (mod n)
d | n ⇐⇒ ∃k ∈ Z s.t. n = dk and any other expression for n as a product of prime For all a, b, c ∈ Z, if gcd(a, c) = 1 and a | bc, then or equivalently,
Theorem 4.1.1 (Linear Combination) numbers is identical, except perhaps for the order in a | b. ab mod n = [(a mod n)(b mod n)] (mod n)
which the factors are written.
∀a, b, c ∈ Z, (a | b) ∧ (a | c) → ∀x, y ∈ Z, a | (bx + cy) *Epp L4.8.1 (gcd of an integer and 0) In particular, if m is a positive integer, then
Epp Proposition 4.7.3 If r is a positive integer, then gcd(r, 0) = r. m m
*Epp T4.3.1 (Pos. Divisors of Pos. Integers) a ≡ [(a mod n) ] (mod n)
For all positive integers a, b, For any a ∈ Z and any prime p,
Definition 4.7.2 (Multiplicative inv. modulo n)
p | a → p - (a + 1) *Epp L4.8.2 (Basis of Euclid’s Algorithm)
a|b→a≤b For any integers a, n with n > 1, if an integer s is
If a, b ∈ Z+ , and q, r ∈ Z s.t. a = bq + r, then such that as ≡ 1 (mod n), then s is the multiplicative
Epp T4.3.3 (Transitivity of Divisibility) Epp T4.7.4 (Infinitude of Primes)
The set of primes is infinite. gcd(a, b) = gcd(b, r) inverse of a modulo n. We may write s as a−1 .
∀a, b, c ∈ Z, (a | b) ∧ (b | c) → a | c
Algorithm 4.8.2 (Euclidean Algorithm)
Theorem 4.4.1 (Quotient-Remainder Theorem) Definition 4.5.4 (Relatively Prime) Because the commutative law still applies in modulo
Given any integer a and any positive integer b, there Integers a and b are relatively prime (or coprime) iff def gcd(a, b): arithmetic, we also have
exist unique integers q and r such that gcd(a, b) = 1. if a == 0: −1
a a ≡ 1 (mod n)
a = bq + r and 0 ≤ r < b return b
Definition 4.3.1 (Lower Bound) if b == 0: Multiplicative inverses are not unique. If s is an
Representation of Integers An integer b is said to be a lower bound for a set return a inverse, then so is (s + kn) for any integer k.
Given any positive integer n and base b, repeatedly X ⊆ Z if b ≤ x for all x ∈ X. return gcd(a%b, b) if a >= b else gcd(a, b%a)
apply the Quotient-Remainder Theorem to get, Theorem 4.6.3 (Existence of multiplicative in-
Does not require b to be in X. For example, to evaluate gcd(330, 156): verse)
n = bq0 + r0 For any integer a, its multiplicative inverse modulo n
q0 = bq1 + r1 gcd(330, 156) (= gcd(330 mod 156, 156)) where n > 1, a−1 , exists iff a and n are coprime.
Theorem 4.3.2 (Well Ordering Principle)
q1 = bq2 + r2 If a non-empty set S ⊆ Z has a lower bound, then S = gcd(18, 156) (= gcd(18, 156 mod 18))
has a least element. Finding the Multiplicative Inverse
··· = gcd(18, 12) (= gcd(18 mod 12, 12))
To find the multiplicative inverse a−1 mod b, note
qm−1 = bqm + rm Note three conditions: |S| > 0, S ⊆ Z, and S has = gcd(6, 12) (= gcd(6, 12 mod 6)) that since a, b are coprime, using Bézout’s Identity,
lower bound. = gcd(6, 0) there exists x, y ∈ Z6=0 such that,
The process stops when qm = 0. Eliminating the quo-
tients qi we get, =6 ax + by = gcd(a, b)
Likewise, if ... upper bound ... has a greatest element.
n = rm b
m
+ rm−1 b
m−1
+ · · · r1 b + r0 Proposition 4.5.5 ax + by = 1
Proposition 4.3.3 (Uniqueness of least element) For any integers a, b, not both zero, if c is a common ax + by ≡ 1 (mod b)
Which may be represented compactly in base b as a divisor of a and b, then c | gcd(a, b).
sequence of the digits ri , If a set S has a least element, then the least element ax ≡ 1 (mod b)
is unique.
n = (rm rm−1 · · · r1 r0 )b Definition 4.7.1 (Congruence modulo) −1
a ≡ x (mod b)
Definition 4.2.1 (Prime number) Proposition 4.3.4 (Uniqueness of greatest e.) Let m, z ∈ Z and d ∈ Z+ . We say that m is congruent To find x, employ the extended Euclidean algo-
If a set S has a greatest element, then the greatest to n modulo d and write rithm: express b using the quotient-remainder theorem
+ element is unique. m ≡ n (mod d) (T4.4.1) with a as the quotient. Then express the re-
n is prime ⇐⇒ ∀r, s ∈ Z
iff mainder r using the divisor as quotient. Repeat with
n = rs → Theorem 4.4.1 (Quotient-Remainder Theorem) the new remainder until a remainder of 1 is obtained.
d | (m − n)
(r = 1 ∧ s = n) ∨ (r = n ∧ s = 1) Given any integer a and any positive integer b, there Finally, express 1 in terms of a and b using the equali-
+
exist unique integers q and r such that More concisely, ties formulated during the algorithm. For example, to
n is composite ⇐⇒ ∃r, s ∈ Z s.t.
a = bq + r and 0 ≤ r < b find the multiplicative inverse of 5 mod 18.
n = rs ∧ m ≡ n (mod d) ⇐⇒ d | (m − n)
Definition 4.5.1 (Greatest Common Divisor) Epp T8.4.1 (Modular Equivalences) quotient-remainder theorem: n = dq + r
(1 < r < n) ∧ (1 < s < n) Let a and b be integers, not both zero. The greatest Let a, b, n ∈ Z and n > 1. The following statements
List of Primes to 100 common divisor of a and b, denoted gcd(a, b), is the n= d q+r (1)
are all equivalent,
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, integer d satisfying 18 = (3)5 + 3 (2)
59, 61, 67, 71, 73, 79, 83, 89, 97. 1. n | (a − b) 5 = (1)3 + 2 (3)
1. d | a and d | b 2. a ≡ b (mod n)
Proposition 4.2.2 2. ∀c ∈ Z ((c | a) ∧ (c | b) → c ≤ d) 3. a = b + kn for some k ∈ Z 3 = (1)2 + 1 (4)
Now, express 1 in terms of 5 and 18. Common Sequences Where c, d ∈ R can be found by solving for known - A∩∅=∅
1= (1) 3 − (1) 2 values of the sequence. - A∩B =B∩A
Arithmetic sequence: - A ∩ (B ∩ C) = (A ∩ B) ∩ C
= (1) 3 − (1) [(1)5 − (1)3] n Sets
Sn = (2a + (n − 1)d) - A ⊆ B ←→ A ∩ B = A
= (−1) 5 + (2) 3 2 - A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
Geometric sequence: Definition 6.1.1 (Subsets & Supersets)
= (−1) 5 + (2) [(1)18 − (3)5] - A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
S is a subset of T if all the elements of S are elements
= (2) 18 + (−7) 5 a(r n − 1)
Sn = of T , denoted S ⊆ T . Formally, Definition 6.3.5 (Disjoint)
r−1 Let S, T be sets. S and T are disjoint iff S ∩ T = ∅.
a S ⊆ T ←→ ∀x ∈ S(x ∈ T )
Take mod 18 on both sides, S∞ = , |r| < 1
1−r Definition 6.2.1 (Empty Set) Definition 6.3.6 (Mutually Disjoint)
1 ≡ (2)18 + (−7)5 (mod 18) Triangle numbers: An empty set has no element, and is denoted ∅ or {}. Let V be a set of sets. The sets T ∈ V are mutually
Formally, where U is the universal set: disjoint iff every two distinct sets are disjoint. For-
(2)18 + (−7)5 ≡ 1 (mod 18) n
X n(n + 1)
Tn = k= ∀Y ∈ U (Y 6∈ ∅) mally,
(−7)5 ≡ 1 (mod 18) 2
k=1 Epp T6.24 ∀X, Y ∈ V (X 6= Y → X ∩ Y = ∅)
(11)5 ≡ 1 (mod 18)
Fibonacci numbers: An empty set is a subset of all sets. Definition 6.3.7 (Partition)
So, 5−1 mod 18 = 11.

0
 if k = 0 ∀S, S is a set, ∅ ⊆ S Let S be a set, and V a set of non-empty subsets of S.
∀n ∈ N, Fk = 1 if k = 1 Definition 6.2.2 (Set Equality) Then V is a partition of S iff
Corollary 4.7.4 (Special case: n is prime) 
F
k−1 + Fk−2 otherwise Two sets are equal iff they have the same elements. 1. The sets in V are mutually disjoint
If n = p is a prime number, then all integers a in the
2. The union of sets in V equals S
range 0 < a < p have multiplicative inverses modulo φk − (−φ)−k Proposition 6.2.3
p. = √ Definition 6.3.8 (Non-symmetric Difference)
5 For any two sets X, Y , X and Y are subsets of each
√ other iff X = Y . Formally, Let S, T be two sets. The (non-symmetric) difference
Epp T8.4.9 (Cancellation Law for mod. arith.) where φ = (1 + 5/2). of S and T denoted S − T or S \ T is the set whose
For all a, b, c, n ∈ Z, n > 1, and a and n are coprime, ∀X, Y ((X ⊆ Y ∧ Y ⊆ X) ←→ X = Y ) elements belong to S and do not belong to T . Formally,
Definition 5.4.1 Epp C6.2.5 (Empty Set is Unique)
ab ≡ ac (mod n) → b ≡ c (mod n) S − T = {y ∈ U | y ∈ S ∧ y 6∈ T }
A second-order linear homogeneous recurrence relation It’s what it says.
*Epp T8.4.10 (Fermat’s Little Theorem) with constant coefficients is a recurrence relation of the This is analogous to subtraction for numbers.
For any prime p and any integer a, ap ≡ a (mod p). form: Definition 6.2.4 (Power Set)
Definition 6.3.9 (Symmetric Difference)
p−1 The power set of a set S denoted P(S), or 2S ; is the set Let S, T be two sets. The symmetric difference of S
Alternatively, if p - a then a ≡ 1 (mod p). Fk = aFk−1 + bFk−2 whose elements are all possible subsets of S. Formally, and T denoted S T is the set whose elements belong
Definition 4.6.1 (Least Common Multiple) Where a, b ∈ R, b 6= 0; and ∀k ∈ Zk≥k0 for k0 ∈ Z. P(S) = {X | X ⊆ S} to S or T but not both. Formally,
For any non-zero integers a, b, their least common mul- Theorem 6.3.1 S T = {y ∈ U | y ∈ S ⊕ y ∈ T }
tiple, denoted lcm(a, b) is the positive integer m such - Second-order means recurrence relation goes up to If a set X has n elements, n ≥ 0, then P(X) has 2n This is analogous to the exclusive-or in predicate logic.
that: but not exceeding Fk−2 . elements.
- Linear means the highest power of the (Fk−r )m
term is m = 1. Definition 6.3.10 (Set Complement)
1. a | m and b | m Definition 6.3.1 (Union) Let A ⊆ U . Then, the complement of A denoted Ac is
- Homogeneous means C = 0 in the more general case Let S be a set of sets. T is the union of sets in S, iff
2. ∀c ∈ Z+ ((a | c) ∧ (b | c) → c ≤ m Fk = aFk−1 + bFk−2 + C. U − A.
each element of T belongs to some set in S. Formally,
- Constant coefficients means a, b does not depend on
Relations
[ [
Sequences k. T = S= X = {y ∈ U | ∃X ∈ S(y ∈ X)}
X∈S
Empty Sums & Products Definition 8.1.1 (Ordered Pair)
Epp T5.8.3 (Distinct-Roots Theorem) Proposition 6.3.2 Let S be a non-empty set, and x, y ∈ S. The ordered
By definition, when n < m, If a second-order linear homogeneous recurrence rela- Some properties of union, pair denoted (x, y) is a mathematical object where the
tion with constant coefficients has real roots r and s first element is x and the second is y.
n
S S
X for its characteristic equation, - ∅ = A∈∅ A = ∅
ai = 0 2
S (x, y) = (a, b) ⇐⇒ x = a ∧ y = b
i=m
t − at − b = 0 - {A} = A
Definition 8.1.2 (Ordered n-tuple)
n Then Fk can be written in closed form as - A∪∅=A
Y
=1 k k - A∪B =B∪A Generalise the ordered pair to n elements. The ordered
Fk = cr + ds
i=m - A ∪ (B ∪ C) = (A ∪ B) ∪ C n-tuple (x1 , x2 , · · · , xn ) consists of x1 , x2 , · · · , xn ele-
Where c, d ∈ R can be found by solving for known val- ments together with ordering.
Epp T5.1.1 - A∪A=A
ues of the sequence. Recall that the roots of a quadratic
For real numbered sequences am , am+1 , am+2 , ... and equation ax2 + bx + c are given by: - A ⊆ B ←→ A ∪ B = B (x1 , x2 , · · · , xn ) = (y1 , y2 , · · · , yn )
bm , bm+1 , bm+2 ..., c ∈ R, the following holds for any √
−b ± b2 − 4ac ⇐⇒ x1 = y1 , x2 = y2 , · · · , xn = yn
n≥m Definition 6.3.3 (Intersection)
x= Definition 8.1.3 (Cartesian Product)
n n n 2a Let S be a non-empty set of sets. T is the intersection
Let S, T be two sets. The Cartesian product (or cross
X X X
ak + bk = (ak + bl ) Epp T5.8.5 (Single-Roots Theorem) of sets in S, iff each element of T also belongs to all
the sets in S. Formally, product) of S and T denoted S × T is the set such that
k=m k=m k=m If a second-order linear homogeneous recurrence rela-
n n tion with constant coefficients has one single real root \ \ ∀X∀Y ((X, Y ) ∈ S × T ←→ (X ∈ S) ∧ (Y ∈ T ))
X X T = S= X
c· ak = c · ak r for its characteristic equation, For example,
X∈S
k=m k=m 2
t − at − b = 0 {1, 2, 3} × {a, b}
n
! n
! n = {y ∈ U | ∀X((X ∈ S) → (y ∈ X))}
Then Fk can be written in closed form as
Y Y Y
ak · bk = (ak · bk ) Proposition 6.3.4 = {(1, a), (1, b), (2, a), (2, b), (3, a), (3, b)}
k k
k=m k=m k=m Fk = cr + dkr Let A, B, C be sets. Some properties of intersection, Definition 8.1.4 (Generalised Cartesian Prod.)
Generalise the cartesian product for n sets. R is transitive (8.3.3) iff ∀x, y, z ∈ A((x R y ∧ 3. Eliminate all arrows implied by transitivity. Let  be a partial order on the set A. A is well ordered
A1 × A2 × · · · × An y R z) → x R z)). 4. Remove the direction of the arrows. iff every non-empty subset of A contains a minimum el-
ement. Formally,
= {(a1 , · · · , an ) | a1 ∈ A1 , · · · , an ∈ An } Definition 8.6.1 (Anti-symmetric) ∀S ∈ P(A)(S 6= ∅ → (∃x ∈ S ∀y ∈ S(x  y)))
Let V be a set of sets with which to apply the cartesian Let A be a set, and R ∈ A × A be a relation on A. R
product to. We can also write is anti-symmetric iff Functions
∀x ∈ A, ∀y ∈ A((x R y ∧ y R x) → x = y)
Y
S 18 Definition 7.1.1 (Function)
S∈V Definition 8.3.4 (Equivalence Relation) 9 Let f be a relation such that f ⊆ S × T . Then f is a
Definition 8.2.1 (Relations) A relation R is called an equivalence relation iff R is function from S to T denoted f : S → T iff
reflexive, symmetric, and transitive. 2
Let S, T be two sets. A binary relation from S to T ∀x ∈ S, ∃!y ∈ T (x f y)
denoted R is a subset of the cartesian product S × T . 3
Definition 8.3.5 (Equivalence Class) Intuitively, this means that every element in S must
The notation s R t stands for (s, t) ∈ R. s 
R t stands 1
Let x ∈ A. The equivalence class of x denoted [x] is have exactly one ‘outgoing arrow’.
for (s, t) 6∈ R.
the set of all elements y ∈ A that are in relation with
x. That is Definitions 7.1.[2-5]
Definitions 8.2.[2-4] (Dom, Im, coDom)
[x] = {y ∈ A | x R y} Let f : S → T be a function, x ∈ S and y ∈ T such
Let R ⊆ S × T be a binary relation from S to T . De-
note the domain (8.2.2) of R as Dom(R); the image that f (x) = y; U ⊆ S, and V ⊆ T .
Epp T8.3.4 (Partition by Equivalence Relation)
(or range, 8.2.3) as Im(R); and the co-domain (8.2.4) The above diagram represents the partial order for “di-
Let R be an equivalence relation on a set A. Then the vides” on the set A = {1, 2, 3, 9, 18}. That is x is a pre-image (7.1.2) of y.
as coDom(R). set of distinct equivalence classes form a partition of A.
Dom(R) = {s ∈ S | ∃t ∈ T (s R t)} ∀a, b ∈ A(a | b ←→ ∃k ∈ Z(b = ka))
The inverse image of the element (7.1.3) y is the set of
Epp L8.3.2 It can be represented by the following Hasse diagram.
Im(R) = {t ∈ T | ∃s ∈ S(s R t)} all its pre-images, i.e. {x ∈ S | f (x) = y}.
Let R be an equivalence relation on a set A, and let
coDom(R) = T a, b ∈ A. If a R b then [a] = [b].
The inverse image of the set (7.1.4) V is the set that
Proposition 8.2.5 18 contains all the pre-images of all the elements of V ,
Let R be a binary relation. Im(R) ⊆ coDom(R). Epp L8.3.3
9 i.e. {x ∈ S | ∃y ∈ V (f (x) = y)}.
Let R be an equivalence relation on a set A, and let
Definition 8.2.6 (Inverse) a, b ∈ A. Either [a] ∩ [b] = ∅ or [a] = [b].
The restriction (7.1.5) of f to U is the set
Let S, T be sets; R ⊆ S × T be a binary relation. The 2 {(x, y) ∈ U × T | f (x) = y}.
inverse of the relation R denoted R−1 is the relation Epp T8.3.1 (Equivalence Relation by Partition)
from T to S such that Given a partition S1 , S2 , cdots of a set A, there exists 3
an equivalence relation R on A whose equivalence Definition 7.2.1 (Injective, or One-to-one)
−1
∀s ∈ S, ∀t ∈ T (t R s ←→ s R t) classes make up precisely that partition. 1 Let f : S → T be a function. f is injective (or one-to-
Definition 8.2.7 (n-ary relation) one) iff
Generalise the binary relation for n sets Definition 8.5.1 (Transitive Closure) ∀y ∈ T, ∀x1 , x2 ∈ S((f (x1 ) = y ∧ f (x2 ) = y) → x1 = x2 )
S1 , S2 , · · · , Sn . An n-ary relation Let A be a set and R a relation on A. The transitive Definition 8.6.3 (Comparable)
Q on the n sets is Intuitively, this means that every element in T has
a subset of the cartesian product i Si . n is the arity closure of R denoted Rt is a relation that satisfies the Let  be a partial order on set A. a, b ∈ A are said to have at most one ‘incoming arrow’.
or degree of the relation. three properties: be comparable iff either a  b or b  a. Otherwise, a
and b are noncomparable.
Definition 7.2.2 (Surjective, or Onto)
Definition 8.2.8 (Composition) 1. Rt is transitive.
2. R ⊆ Rt . Let f : S → T be a function. f is surjective (or onto)
Let S, T, U be sets; and R ⊆ S × T , R0 ⊆ T × U Definition 8.6.4 (Total Order)
iff
be relations. The composition of R with R0 , denoted 3. If S is any other transitive relation such that Let  be a partial order on set A.  is said to be a
R0 ◦ R is the relation from S to U such that R ⊆ S, then Rt ⊆ S. total order iff  is a partial order, and all x, y ∈ A are ∀y ∈ T, ∃x ∈ S(f (x) = y)
0
∀x ∈ S, ∀z ∈ U (x R ◦R z ↔ (∃y ∈ T (x R y ∧ y R z)))
0 comparable. Formally,
Intuitively, the transitive the closure can be under- Intuitively, this means that every element in T has at
In other words, x ∈ S and z ∈ U are related iff there ∀x, y ∈ A(x  y ∨ y  x) least one ‘incoming arrow’.
stood as the smallest superset that is transitive.
is a ‘path’ from x to z via some intermediate y ∈ T . Similar definitions exist for the reflexive closure and Definition 8.6.5 (Maximal)
symmetric closure. Let  be a partial order on the set A. An element x is Definition 7.2.3 (Bijective)
Repeated Compositions a maximal element iff A function is bijective (or is a bijection) iff it is injec-
Proposition 8.5.2 ∀y ∈ A(x  y → x = y) tive and subjective. Intuitively, this means that every
n
K
R := R ◦ · · · ◦ R = R element in T has exactly one incoming arrow.
| {z } ∞ Definition 8.6.6 (Maximum)
n t
[ i
n R = R Let  be a partial order on the set A. An element T Definition 7.2.4 (Inverse)
i=1 is the maximum element iff
Proposition 8.2.9 (Associativity of Composition) Let f : S → T be a function and let f −1 be the inverse
00 0 00 0 00 0 Definition 8.6.2 (Partial Order) ∀x ∈ A(x  T ) relation of f from T to S. Then f is bijective iff f −1
R ◦ (R ◦ R) = (R ◦ R ) ◦ R = R ◦ R ◦ R is a function.
R is a partial order iff it is reflexive, anti-symmetric, Definition 8.6.7 (Minimal)
Proposition 8.2.10 (Inverse of Composition) and transitive. A set A is called a partially ordered Let  be a partial order on the set A. An element x is
0 −1 −1 0−1 set with respect to a relation  iff  is a partial order a minimal element iff Definition 7.3.1 (Composition)
(R ◦ R) =R ◦R
relation on A. Let f : S → T , g : T → U be functions. The compo-
Definitions 8.3.[1-3] (Properties of Relations) ∀y ∈ A(y  x → x = y) sition of f and g denoted g◦f is a function from S to U .
Let A be a set, and R ∈ A × A be a relation on A. Hasse Diagrams Definition 8.6.8 (Minimum)
The Hasse diagram is a simplified directed graph. Let  be a partial order on the set A. An element ⊥ Definition 7.3.2 (Identity)
R is reflexive (8.3.1) iff ∀x ∈ A(x R x). is the minimum element iff The identity function on a set A, IA is defined by,
1. Draw the directed graph so that all arrows point
∀x ∈ A(⊥  x) ∀x ∈ A(IA (x) = x)
R is symmetric (8.3.2) iff ∀x, y ∈ A(x R y → y R x). upwards.
2. Eliminate all self-loops Definition 8.6.9 (Well Ordered) Proposition 7.3.3
Let f : A → A be an injective function of A. Then If A, B, C are finite sets, then Given a, b ∈ R and n ∈ Z+ , 3. P (B ∩ C) = P (B) · P (C)
f −1 ◦ f = IA . N (A ∪ B) =N (A) + N (B) − N (A ∩ B) n   4. P (A ∩ B ∩ C) = P (A) · P (B) · P (C)
n
X n n−k k
(a + b) = a b
Combinatorics N (A ∪ B ∪ C) =N (A) + N (B) + N (C) k
k=0 In general, n events are mutually independent iff the
− N (A ∩ B) − N (A ∩ C) n
n
n−1
 n 
n−1 n probability of the intersection of any subset of events
Definitions & Notations =a + a b + ··· + ab +b is the product of the corresponding probabilities of
− N (B ∩ C) + N (A ∩ B ∩ C) 1 n−1
A sample space is the set of all possible outcomes of said events.
a random process or experiment. An event is a subset Pigeonhole Principle Probability
of a sample space. A function from one finite set to a smaller finite set Graphs
Axioms of Probability
cannot be one-to-one. There must be at least 2 ele- Let S be a sample space, and P a probability func-
For a finite set A, N (A) denotes the number of ele- ments in the domain that have the same image in the Graph
ments in A. tion from the set of all events in S to the set of real A graph G consists of 2 finite sets: a non-empty set
co-domain. numbers; A, B ⊆ S, V (G) of vertices and a set E(G) of edges, where each
An r-permutation of a set of n elements is an ordered edge is associated with a set consisting of either one
selection of r elements taken from the set. The number Generalised Pigeonhole Principle 1. 0 ≤ P (A) ≤ 1 or two vertices called its endpoints.
of r-permutations of a set of n elements is denoted For any function f from a finite set X with n elements 2. P (∅) = 0 and P (S) = 1
P (n, r). to a finite set Y with m elements and for any positive 3. If A, B are disjoint sets, i.e. A ∩ B = ∅, then An edge connects its two endpoints. Two vertices con-
integer k, if k < n/m, then there is some y ∈ Y such P (A ∪ B) = P (A) + P (B) nected by an edge are adjacent vertices. A vertex with
An r-combination of as set of n elements is a subset that y is the image of at least k + 1 distinct elements a self-loop is adjacent to itself. An edge is incident on
of r of the n elements, denoted n

r .
of X. Theorem 9.3.3 (Inclusion/Exclusion Principle) each of its endpoints, and two edges incident on the
If A, B, and C are any finite sets, then same endpoint are adjacent edges.
An r-combination with repetition allowed, or mul- Gen. Pigeonhole Principle, Contrapositive N (A ∪ B) = N (A) + N (B) − N (A ∩ B)
tiset of size r, chosen from a set X of n elements For an edge e incident on vertices v, w, we can write
For any function f form a finite set X with n elements N (A ∪ B ∪ C) = N (A) + N (B) + N (C)
is an unordered selection of elements taken from X e = {v, w}.
with repetition allowed; denoted as [xi1 , xi2 , · · · , xir ] to a finite set Y with m elements and for any positive
integer k, if for each y ∈ Y , f −1 (y) has at most k −N (A ∩ B) − N (A ∩ C)
where each xij is in X and some of the xij may equal Directed Graph
elements, then X has at most km elements; in other −N (B ∩ C) + N (A ∩ B ∩ C)
each other. A directed graph (or digraph) consists of 2 finite sets:
words n ≤ km.
Probability of the Complement a non-empty set V (G) of vertices and a set D(G) of
Equally Likely Probability Formula c
P (A ) = 1 − P (A) directed edges, where each edge is associated with an
If S is a finite sample space in which all outcomes are Theorem 9.5.1 (r-combinations from n) ordered pair of vertices called its endpoints.
Probability of the Union
equally likely and E is an event in S, then the proba- If n, r ∈ Z+ and r ≤ n, then the number of r −
bility of E, denoted P (E), is combinations that can be chosen from a set of n ele- P (A ∪ B) = P (A) + P (B) − P (A ∩ B) For a directed edge e associated with the pair (v, w)
ments is given by, Expected Value of vertices, we can write e = (v, w).
N (E)
P (E) =  n P (n, r) The expected value of a random experiment with dis-
N (S) = Simple Graph
crete real numbered outcomes a1 , a2 , · · · , an with cor-
Theorem 9.1.1 (Number of Elements) r r! A simple graph is an undirected graph that does not
responding probabilities p1 , p2 , · · · , pn is
If m and n are integers and m ≤ n, then there are n! have any loops or parallel edges.
=
X
n − m + 1 integers from m to n inclusive. r!(n − r)! ak pk
n Complete Graph
Theorem 9.2.1 (Multiplication Rule) Theorem 9.5.2 (Perm. w/ Indistinguishables) Conditional Probability A complete graph on n vertices, n > 0, denoted Kn ,
If an operation consists of k steps, and the first step For a set of n objects of which n1 are indistinguishable Let A, B ⊆ S. If P (A) 6= 0, then the conditional prob- is a simple graph with n vertices and exactly one edge
can be performed in n1 ways, the second in n2 ways, from each other, as are n2 , and n3 , ..., and nk , then ability of B given A, denoted P (B|A) is connecting each pair of distinct vertices. The number
..., the kth step in nk ways, then the entire operation the number of distinguishable permutations of the n of edges is Tn , the nth triangle number.
P (A ∩ B)
can be performed in n1 × n2 × · · · nk ways. objects is P (B|A) =
 n n − n  n − n − n − · · · − n − 1 P (A) Complete Bipartite Graph
1 1 2 k
Theorem 9.2.2 (Permutations) ··· A useful form of this equality is A complete bipartite graph on (m, n) vertices,
n1 n2 nk m, n > 0, denoted Km,n is a simple graph with
The number of permutations of a set with n (n ≥ 1) P (A ∩ B) = P (B|A) · P (A)
elements is n! n! distinct vertices v1 , v2 , · · · , vm and w1 , w2 , · · · , wn
= Bayes’ Theorem
n1 !n2 ! · · · nk ! that satisfies the properties:
Suppose a sample space S has mutually disjoint events
Theorem 9.2.3 (r-permutations from n)
Theorem 9.6.1 (Multisets of r) B1 , B2 , · · · , Bn . Suppose A is an event in S, and For all i, k = 1, 2, · · · , m and j, l = 1, 2, · · · , n,
If n, r ∈ Z and 1 ≤ r ≤ n, then the number of r- all events have non-zero probabilities. If k ∈ Z+ ,
permutations of a set of n elements is given by, The number of r-combinations with repitition allowed
that can be selected from a set of n elements is 1 ≤ k ≤ n, then 1. There is an edge from each vi to each wj .
P (n, r) = n(n − 1)(n − 2) · · · (n − r + 1) r + n − 1 P (A|Bk )P (Bk ) 2. There is no edge from any vi to any vk .
n! P (Bk |A) = Pn
r i=1 P (A|Bi )P (Bi )
3. There is no edge from any wj to any wl .
=
(n − r)! This equals the number of ways r objects can be Independent Events
Theorem 9.3.1 (Addition Rule) selected from n categories of objects with repetitions Let A, B ⊆ S, A, B be independent events iff Subgraph
Let A be a finite set equal to the union of k distinct allowed. A graph H is a subgraph of a graph G iff every vertex
P (A ∩ B) = P (A)P (B) in H is also a vertex in G, and every edge in H is
mutually disjoint sets A1 , A2 , · · · , Ak . Then,
Pairwise/Mutually Independent also an edge in G, and every edge in H has the same
N (A) = N (A1 ) + N (A2 ) + · · · + N (Ak ) Theorem 9.7.1 (Pascal’s Formula)
Let A, B, C ⊆ S. A, B, C are pairwise independent iff endpoints as it has in G.
+
Theorem 9.3.2 (Difference Rule) Let n, r ∈ Z , r ≤ n. Then they satisfy conditions 1–3 below. They are mutally
Let A be a finite set and B a subset of A. Then, n + 1  n  n independent iff they satisify all conditions below. Degree
= + The degree of v, a vertex of graph G, denoted deg(v),
N (A − B) = N (A) − B(N ) r r−1 r
1. P (A ∩ B) = P (A) · P (B) equals the number of edges that are incident on v,
Theorem 9.3.3 (Inclusion/Exclusion Principle) Theorem 9.7.2 (Binomial Theorem) 2. P (A ∩ C) = P (A) · P (C) with self-loops counted twice. The total degree of G is
the sum of the degrees of all vertices of G. A path from v to w is a trail that does not contain a Euler Trail Let G be a graph with connected components
repeated vertex. An Euler trail/path from v to w is a sequence of G1 , G2 , · · · , Gk . If there are ni vertices in each con-
Theorem 10.1.1 (Handshake Theorem) adjacent edges and vertices that starts at v, ends at nected component Gi and these vertices are numbered
The sum of the degrees of all the vertices of a graph G A closed walk is a walk that starts and ends at the w, passes through every vertex of G at least once, and consecutively, then the adjacency matrix of G has the
is twice the number of edges of G. same vertex. traverses every edge of G exactly once. form
A1 O ··· O O
X  
Total Degree of G = deg(v) ···
A circuit (or cycle) is a closed walk that contains at Corollary 10.2.5 O A2 O O
v∈V (G)
least one edge and does not contain a repeated edge.  . . . . 
 
Let v, w be distinct vertices of G. There is an Euler  . . .. . . 
= 2 × N (edges in G) trail from v to w iff G is connected, v and w have odd  . . . . . 
A simple circuit is a circuit that does not have any degree, and all other vertices of G have positive even
O O · · · Ak−1 O
Corollary 10.1.2
repeated vertex except the first and last. degree. O O ··· O Ak
The total degree of a graph is even.
Connectedness Hamiltonian Circuit where each Ai is the ni × ni adjacency matrix of Gi
Proposition 10.1.3
Two vertices v, w of a graph G are connected iff there A Hamiltonian circuit for a graph G is a simple circuit for all i = 1, 2, · · · , k, and the O’s represents matrices
In any graph there are an even number of vertices of
is a walk from v to w. that includes every vertex of G. That is, a Hamilto- whose entries are all 0.
odd degree.
nian circuit for G is a sequence of adjacent vertices
The graph G is connected iff ∀v, w ∈ V (G) there is a and distinct edges in which very vertex of G appears Scalar Product
Must Contain

walk from v to w. Then, G is either a tree or has a exactly once, except for the first and last, which are

b1j

≥ 1 Edge?

circuit. the same. b2j 



yes
yes

ai1 ai2 ··· ain  . 


no
no
no
no

 
Lemma 10.2.1 A Hamiltonian graph (or Hamilton graph) is a graph  . 
.
Let G be a graph. that contains a Hamiltonian circuit. There is no bnj
analogous criterion to T10.2.4 to determining whether
- If G is connected, then any two distinct vertices of = ai1 b1j + ai2 b2j + · · · + ain bnj
a given graph has a Hamiltonian circuit.
G can be conted by a path.
Matrix Multiplication
Start/End?

- If vertices v and w are part of a circuit in G and one


allowed
allowed

Proposition 10.2.6 Let A = (aij ), B = (bij ), then the matrix product


Same

edge is remd from the circuit, then there still exists


yes
yes
yes

of A × B, denoted AB, defined as (cij ), is the matrix


no

a trail from v to w in G If a graph G has a Hamiltonian circuit, then G has a


- If G is connected and G contains a circuit, then an subgraph H with the following properties, where
edge of the circuit can be removed without discon- cij = ai1 b1j + ai2 b2j + · · · + aik bkj
necting G. 1. H contains every vertex of G.
Intuitively, this means that the (i, j)th entry of AB
2. H is connected.
first, last only

Connected Component can be found by the scalar product of the ith row of A
Repeated

3. H has the same number of edges as vertices.


and the j th column of B.
Vertex?
allowed
allowed

allowed
allowed

A graph H is a connected component of a graph G iff


4. Every vertex of H has degree 2.
no

1. The graph H is a subgraph of H. Identity Matrix


2. The graph H is connected. Since the converse is not true, this proposition cannot The n × n identity matrix In (or I) is the n × n matrix
3. No connected subgraph of G has H has a sub- be used to check if a graph has a Hamiltonian circuit. in which all the entries of the main diagonal are 1’s,
graph and contains vertices or edges that are However, the contrapositive can be used to check if a and all other entries are 0’s.
not in H. graph does not have a Hamiltonian circuit.
Repeated

allowed

allowed
Edge?

nth Power of a Matrix


no
no

no
no

Euler Circuit Matrix For any n × n matrix A, the powers of A are defined
An Euler circuit for G is a circuit that contains every A m × n matrix A over a set S is a rectangular array as
vertex and every edge of G. That is, an Euler circuit of elements of S arranged into m rows and n columns.
(
for G is a sequence of adjacent vertices and edges in k I if k = 0
A =
AAk−1 for k ∈ Z+ , k ≥ 1
Simple Circuit

G that has at least one edge, starts and ends at the Two matrices A and B are equal iff A and B are the
Closed Walk

same vertex, uses every vertex of G at least once, and same size, and all the corresponding entries of A and
uses every edge of G exactly once. B are equal. Theorem 10.3.2
Let G be the graph with vertices v1 , v2 , · · · , vm and
Circuit

An Eulerian graph is a graph that contains an Euler Adjacency Matrix of a Directed Graph adjacency matrix A. Then, for each positive integer n
Walk

Path
Trail

circuit. Let G be a directed graph with ordered vertices and for all integers i, j = 1, 2, · · · , m, the (i, j)th entry
v1 , v2 , · · · , vn . The adjacency matrix of G is the n × n of An is the number of walks of length n from vi to
Theorem 10.2.2 matrix A = (aij ) over the set of non-negative integers vj .
If a graph has an Euler circuit, then every vertex of such that for all i, j = 1, 2, · · · , n,
the graph has positive even degree. Isomorphic Graph
Walk, Trails, Paths, etc. aij = the number of arrows from vi to vj Let G and G0 be graphs with vertex sets V (G), V (G0 )
Let G be a graph and v, w ∈ V (G). Contrapositive: if some vertex of a graph has odd Adjacency Matrix of an Undirected Graph and edge sets E(G), E(G0 ) respectively. G is isomor-
degree, then the graph does not have an Euler circuit. Let G be an undirected graph with ordered vertices phic to G0 iff there exists a one-to-one correspondence
A walk from v to w is a finite alternating sequence of v1 , v2 , · · · , vn . The adjacency matrix of G is the n × n (relabelling) g : V (G) → V (G0 ) and h : E(G) → E(G0 )
adjacent vertices and edges of G. It can be written Theorem 10.2.3 matrix A = (aij ) over the set of non-negative integers such that the edge-endpoint functions of G and G0 are
in the form v0 e1 v1 e2 · · · vn en w; or v0 v1 · · · vn w; or If a graph G is connected and the degree of every such that for all i, j = 1, 2, · · · , n, preserved. Formally, this means that
e1 e2 · · · en . vertex of G is a positive even integer, then G has an
Euler circuit. aij = the number of edges connecting vi and vj
∀v ∈ V (G), e ∈ E(G),
A trivial walk from v to v consists of the single vertex v. Symmetric Matrix v is endpoint of e ⇐⇒ g(v) is endpoint of h(e)
Theorem 10.2.4 A n×n matrix is symmetric iff for all i, j = 1, 2, · · · , n,
A trail from v to w is a walk from v to w that does A graph G has an Euler circuit iff G is connected and Theorem 10.4.1
aij = aji
not contain a repeated edge. every vertex of G has positive even degree. Let S be a set of graphs and R be the relation of graph
Theorem 10.3.1 isomorphism on S. Then R is an equivalence relation
on S. If w is a child of v, then v is the parent of w. Two A spanning tree for a graph G is a subgraph of G that
distinct vertices that are both children of the same contains every vertex of G and is a tree.
Theorem 10.4.2 (Invariant Properties) parent are called siblings.
Each of the following properties is an invariant for Proposition 10.7.1
graph isomorphism, where n, m, and k are all non- Given two distinct vertices v, w; if v lies on a unique Every connected graph has a spanning tree, and any
negative integers. path between w and the root, then v is an ancestor of two spanning trees for a graph have the same number
w, and w a descendant of v. of edges.
1. has n vertices;
2. has m edges; (Full) Binary Tree Weighted Graph
3. has a vertex of degree k; A binary tree is a rooted tree in which every parent A weighted graph is a graph for which each edge has
4. has m vertices of degree k; has at most two children. Each child is either a left an associated positive real number weight. The sum
5. has a circuit of length k; child xor right child. Every parent has at most one left of weights of all the edges is the total weight of a
child and one right child. A full binary tree is a binary weighted graph.
6. has a simple circuit of length k;
tree in which each parent has exactly two children.
7. has m simple circuits of length k;
Minimum Spanning Tree
8. is connected; The total number of vertices is the number of vertices A minimum spanning tree for a connected weighted
9. has an Euler circuit; that have a parent plus vertices that do not have a graph is a spanning tree that has the least possible
10. has a Hamiltonian circuit. parent; or equivalently the number of internal vertices total weight compared to all other spanning trees for
plus the terminal vertices. the graph. If G is a weighted graph and e is an edge
Planar Graph of G, then w(e) denotes the weight of e and w(G)
A planar graph is a graph that can be drawn on a Subtrees denotes the total weight of G.
two-dimensional plane without edges crossing. The left subtree of a parent v in in binary tree T
is the binary tree whose root is the left child of v, Algorithm 10.7.1 (Kruskal’s Algorithm)
Euler’s Formula whose vertices consist of the left child of v and all In this algorithm, the edges of a connected weighted
For a connected planar simple graph G = (V, E) with its descendants, and whose edges consists of all those graph are examined one by one in order of increas-
e = |E| and v = |V |, the number of faces f = e − v + 2. edges of T that connect the vertices of the left subtree. ing weight. At each stage, the edge being examined is
The right subtree is defined similarly. added to what will become the minimum spanning tree,
Tree provided that this addition does not create a circuit.
A graph is circuit-free iff it has no circuits. A graph is *Epp T10.6.1 (Full Binary Tree Theorem)
a tree iff it is circuit-free and connected. A trivial tree If T is a full binary tree with k internal vertices, then def kruskal(G):
is a graph that consists of a single vertex. A graph is T has a total of 2k + 1 vertices and has k + 1 terminal T = new Graph()
a forest iff it is circuit-free and not connected. vertices. edges = edges_of(G)
for edge in edges:
Lemma 10.5.1 Theorem 10.6.2 e = min(edge) # wrt weight
Any non-trivial tree has at least one vertex of degree 1. For non-negative integers h, if T is any binary tree with if T + e has no circuit:
height h and t terminal vertices, then T = T + e
Terminal & Internal Vertices h return T
t≤2
If a tree T has only one or two vertices, then each is
a terminal vertex (or leaf). If T has at least three log2 t ≤ h Algorithm 10.7.2 (Prim’s Algorithm)
vertices, then a vertex of degree 1 in T is called a ter- Binary Tree Traversal In this algorithm, a minimum spanning tree T is build
minal vertex (or leaf), and a vertex of degree greater Breadth-first search starts at the root and visits its by expanding outward in connected links from some
than 1 in T is called an internal vertex (or leaf). adjacent vertices, then moves to the next level. vertex. One edge and one vertex are added at each it-
eration. The edge added is the one of least weight that
Theorem 10.5.2 Depth-first search can be pre-order, in-order, or post- connects the vertices already in T with those not in T ,
Any tree with n > 0 vertices has n − 1 edges. order. In pre-order, print, traverse left then right; in and the vertex is the endpoint of this edge that is not
in-order, traverse left, print, then traverse right; in already in T .
Lemma 10.5.3 post-order, traverse left, right, then print.
Let C be any circuit in a connected graph G. If one def prims(G):
of the edges of C is removed from G, then the graph seed = random.choice(V(G))
The print operation can be represented by a ‘dot’ on a
that remains is still connected. T = new Graph(seed)
vertex in its tree diagram, and the order of prints can
vertices = V(G) - seed
be determined by tracing the outline of the diagram
Theorem 10.5.4 while V(T) != V(G):
anti-clockwise from the root. Draw the ‘dot’ on the
Let G be a connected graph with n vertices and n − 1 # find min edge connecting T to G - T
left, bottom, and right of the vertex for pre-order,
edges. G is a tree. e = least_edge(T, vertices)
in-order, and post-order respectively.
T = T + e
vertices = vertices - endpts(e)
Rooted Tree Reconstructing BT from Traversal Order
return T
A rooted tree is a tree in which there is one vertex that Given a sequence of nodes traversed in depth-first
is distinguished from the others as the root. The level pre-order, in-order, or post-order; it may be possible
of a vertex is the number of edges along the unique to reconstruct the binary tree. Note that in pre-order
path between it and the root. The height of a rooted and post-order, the first node traversed is always the
tree is the maximum level of any vertex of the tree. root node (of traversal). Then, the nodes to the left
of the identified root node in the in-order sequence all
Given the root or any internal vertex v of a rooted belong to the left subtree, and likewise for the right
tree, the children of v are all those vertices that are subtree. Repeat these observations recursively for each
adjacent to v and are one level farther away from the subtree until the full binary tree is constructed.
root than v.
Spanning Tree

You might also like