cs1231 Reference Cheat Sheet PDF
cs1231 Reference Cheat Sheet PDF
CS1231: Reference • De Morgan’s laws: Rules of Inference (Wei Quan) – Stmt is false iff Q(x) false for at least
¬(p ∧ q) ≡ ¬p ∨ ¬q one x ∈ D
Proof Language ¬(p ∨ q) ≡ ¬p ∧ ¬q • Conjunction Intro – A, B, ∴ A ∧ B
• Existential Stmt (3.1.4):
• ∃!: Exists a unique... • Conjunction Elim – A ∧ B, ∴ A, B ∃x ∈ D, such that Q(x)
Conditional Statements
• ≡: Logical Equivalence: identical truth • Disjunction Intro – A, ∴ A ∨ B, B ∨ A – Equivlent to Q(x1 )∨Q(x2 )∨...∨Q(xn )
table (Definition 2.1.6) • p → q ≡ ¬p ∨ q – Stmt is true iff Q(x) true for at least
• Disjunction Elim :
• Contrapositive (Def 2.2.2): A ∨ B, A → C, B → C, ∴ C one x ∈ D
Order of Operations
p → q ≡ ¬q → ¬p – Stmt is false iff Q(x) false ∀x ∈ D
• ¬, followed by ∧∨, followed by →↔ • Contradiction Intro – A, ¬A, ∴ Cont.
• Converse (2.2.3): q → p • Implicit Quantification: =⇒ ⇐⇒
• Contradiction Elim:
Proving Methods • Inverse (2.2.4): ¬p → ¬q – P (x) =⇒ Q(x):
A → Contradiction, ∴ ¬A
truth set P (x) ⊂ truth set Q(x)
• Construction: just sub in all x ∈ D • p → q 6≡ (q → p ≡ ¬p → ¬q) • Double Negation Elim – ¬¬A, ∴ A – P (x) ⇐⇒ Q(x):
• Counterexample: show one condition • Only If (2.2.5): p only if q ≡ p → q truth set P (x) ≡ truth set Q(x)
that leads to contradiction
• Biconditional (2.2.6):
Fallacies
p ↔ q ≡ (p → q) ∧ (q → p)
Negation of Quantified Stmt
• Contraposition: • Converse Error: p → q, q, ∴ p
To prove P → Q, prove ¬Q → ¬P • Negation of Universal Stmt
• Necessary & Sufficient Cond (2.2.7): • Inverse Error: p → q, ¬p, ∴ ¬q
(Thm 3.2.1)
• Contradiction: To prove A, prove ¬A r necessary s ≡ r → s
is not true (Clearly this is absurd) r sufficient s ≡ ¬r → ¬s • Sound & Unsound Argument: Sound iff ∼ (∀x ∈ D, P (x)) ≡ ∃x ∈ D, s.t. ∼ P (x)
valid and premises are true
• Negation of Existential Stmt
Thm 2.1.1 Logical Equivalences Valid Arguments (Thm 3.2.1)
Predicates & Quantified Stmt
(Aaron, pp 21 - 22) • Argument (2.3.1): If all premise true, ∼ (∃x ∈ D, s.t. P (x)) ≡ ∀x ∈ D, ∼ P (x)
conclusion must be true • Predicate (3.1.1): A predicate sen-
• Commutative Law: p ∧ q ≡ q ∧ p tence contains a finite number of vari- Universal Conditional Stmt
• Syllogism: Two premises and one con- ables and becomes a stmt when specific
• Associative Law: clusion ∀x ∈ D, P (x) =⇒ Q(x)
values are subst in the vars. The do-
(p ∧ q) ∧ r ≡ p ∧ (q ∧ r) (same with ∨)
• Modus Ponens: p → q, p, ∴ q main of a predicate var is the set of all • Vacuously True: iff P (x) false ∀x ∈ D
• Distributive Law: values that may be subst in place of the
• Modus Tollens: p → q, ¬q, ∴ ¬p var. • Contrapositive:
p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r)
∀x ∈ D, ∼ Q(x) =⇒ ∼ P (x)
(swap ∨ & ∧)
• Truth Set (3.1.2): If P(x) is a predicate
Rules of Inference • Converse: ∀x ∈ D, Q(x) =⇒ P (x)
• Identity Law: p ∧ t ≡ p or p ∨ c ≡ p and Dx ≡ D, the truth set is the set of
• Generalization: p, ∴ p ∨ q all elements of D that make P (x) true • Inverse: ∀x ∈ D, ∼ P (x) =⇒ ∼ Q(x)
• Negation Law: p∨¬p ≡ t or p∧¬p ≡ c when they are subst for x. The truth set
• Specialization: p ∧ q, ∴ p • Refer to 2.2.5 and 2.2.7 for only if, nec-
• Double Negation Law: ¬(¬p) ≡ p of P (x) is {x ∈ D|P (x)}.
essary & sufficient conditions
• Elimination: p ∨ q, ¬p, ∴ q • Universal Stmt (3.1.3): ∀x ∈ D, Q(x)
• Idempotent Law: p ∧ p ≡ p (same for • Universal Modus Ponens & Tollens:
∨) • Transitivity: p → q, q → r, ∴ p → r ∀x ∈ D, P (x) =⇒ Q(x), P (a) for a ∈ D
– Equivalent to Q(x1 ) ∧ Q(x2 ) ∧ ... ∧
• Proof by Division into Cases: Q(x ) ∴ Q(a)
• Universal Bound Law: n
p ∨ q, p → r, q → r, ∴ r (∼ Q(a), ∴∼ P (a) for tollens)
p ∨ t ≡ t or p ∧ c ≡ c – Stmt is true iff Q(x) true ∀x ∈ D
Created using LATEX 2ε 1 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
• Even & Odd (Def 1.6.1, Proofs Handout, TS): • Bézout’s Identity (Thm 4.5.3): • T2 (Possibility of Subtraction): Given a, b, ∃!x such that
Let a, b ∈ Z, not both zero, & d = gcd(a, b). a + x = b. This x is denoted by b − a.
n is even ⇐⇒ ∃k ∈ Z such that n = 2k Then, ∃x, y ∈ Z s.t.: • T3: b − a = b + (−a) T4: −(−a) = a
n is odd ⇐⇒ ∃k ∈ Z such that n = 2k + 1
ax + by = d • T5: a(b − c) = ab − ac T6: 0 · a = a · 0 = 0
• Divisibility (Def 1.3.1, PH):
• Relatively Prime/Coprime (Def 4.5.4): • T7 (Cancellation Law for Multiplication):
d | n ⇐⇒ ∃k ∈ Z, s.t. n = dk
a, b ∈ Z are coprime ⇐⇒ gcd(a, b) = 1 ab = ac, a 6= 0 =⇒ b = c
• Thm 4.1.1 (pg 4, Number Theory Week 4, TS) :
• Prop 4.5.5: • T8 (Possibility of Division):
∀a, b, c ∈ Z, if a | b & a | c, then ∀x, y ∈ Z, a | (bx + cy)
a, b ∈ Z, not both zero, if c is common divisor of a & b, Given a, b with a 6= 0, ∃!x such that ax = b. This x is
• Prop 4.2.2 (p9, NTW4, TS): then c | gcd(a, b) denoted b/a and is called the quotient of b and a
For any two primes p and p0 , if p | p0 then p = p0 • T9: a 6= 0 =⇒ b/a = b · a−1
• NTP2, p38: ∀a, b ∈ Z+ , a | b ⇐⇒ gcd(a, b) = a
• Thm 4.2.3 (pg 16, NTW4): • T10: a 6= 0 =⇒ (a−1 )−1 = a
• L.C.M. (Def 4.6.1, NTP2, p41):
If p is prime and x1 , x2 , ..., xn are any integers s.t.:
a, b ∈ Z \ {0}, their l.c.m, denoted lcm(a, b), is m ∈ Z+
• T11 (Zero Product Property): ab = 0 =⇒ a ∨ b = 0
p | x1 x2 ...xn , s.t.
• T12 (Rule for Multiplication with Negative Signs):
then p | xi for some xi (1 ≤ i ≤ n) a|m&b|m (3)
(−a)b = a(−b) = −(ab), (−a)(−b) = ab
∀c ∈ Z+ , if a | c & b | c, then m ≤ c (4) a −a a
• Lower Bound (Def 4.3.1, NTP2, p3): &− = =
b b −b
b ∈ Z is lower bound for set X ⊆ Z if b ≤ x, ∀x ∈ X • NTP2, p43: ∀a, b ∈ Z+ , gcd(a, b) | lcm(a, b) a ac
• T13 (Equivalent Fractions Property): = ; b, c 6= 0
• Well Ordering Principle (Thm 4.3.2, NTP2, p5): b bc
If non-empty set S ⊆ Z has lower/upper bound, then S Theorems By Epp a c
has a least/greatest element • T14 (Rule for Addition of Fractions): + =
b d
• Thm 4.3.1: ∀a, b ∈ Z+ , if a | b then a ≤ b ad + bc
• Uniqueness of least element (Prop 4.3.3, NTP2, p8): ; b, d 6= 0
bd
If set S ⊆ Z has least/greatest element, then • Thm 4.3.3: ∀a, b, c ∈ Z, if a | b and b | c then a | c
least/greatest elem is unique • T15 (Rule for Multiplication of Fractions):
• Thm 4.3.5: Given any integer n > 1, ∃k ∈ Z+ , distinct a c ac
primes p1 , p2 , ..., pk & positive integers e1 , e2 , ..., ek , s.t. · = , b 6= 0, d 6= 0
• Quotient-Remainder Thm (Thm 4.4.1): b d bd
Given any a ∈ Z & any b ∈ Z+ , ∃!q, r ∈ Z s.t.: • T16 (Rule for Division of Fractions):
n = pe11 pe22 pe33 ...pekk
a
a = bq + r & 0 ≤ r < b and any other exp for n as a product of prime numbers b ad
c = bc , b 6= 0, c 6= 0, d 6= 0
is identical to this (except ordering)
• G.C.D. (Def 4.5.1, NTP2, p21): √ d
Let a, b ∈ Z, not both zero, g.c.d. of a, b, gcd(a, b), is • Thm 4.7.1: 2 is irrational • T17 (Trichotomy Law): a < b, b < a or a = b, ∀a, b ∈ R
d ∈ Z satisfying:
• Prop 4.7.3: • T18 (Transitive Law): a < b, b < c =⇒ a < c
d|a&d|b (1) For any a ∈ Z and any prime p, if p | a then p - (a + 1)
• T19: a < b =⇒ a + c < b + c
∀c ∈ Z, if c | a & c | b then c ≤ d (2) • Thm 4.7.4: The set of primes is infinite
Created using LATEX 2ε 2 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Created using LATEX 2ε 3 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Then
1. (a ± b) ≡ (c ± d) (mod n)
2. ab ≡ cd (mod n)
3. am ≡ cm (mod n), ∀m ∈ Z+
If m ∈ Z+ , then,
Created using LATEX 2ε 4 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Created using LATEX 2ε 5 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
• Empty Set is Unique (Col 6.2.5, Epp): ∀Y ((Y ∈ T ) ↔ ∀Z((Z ∈ S) → (Y ∈ Z))) ∀X(X ∈ S − T ⇐⇒ (X ∈ S ∧ ∼(X ∈ T )))
∀X1 ∀X2 , ((∀Y (∼(Y ∈ X1 )) ∧ (∀Y ∼(Y ∈ X2 )) → X1 = X2 )
We write it as:
• Power Set (Def 6.3.4, Slides): \ \ • Symmetric Difference [XORing] (Def 6.4.9, Slides):
S T = S= X Let S, T be two sets. The symmetric difference of S
Given set S, the power set of S, denoted P(S) or 2 ,
X∈S and T , denoted S T is the set whose elements belong
is the set whose elements are all the subsets of S, noth-
ing less and nothing more. to S or T but not both
• Proposition 6.4.4 (Slides):
That is, given set S, if T = P(S), then
– A∩∅=∅ ∀X(X ∈ S T ↔ (X ∈ S ⊕ X ∈ T ))
∀X((X ∈ T ) ↔ (X ⊆ S) – A∩B =B∩A
– A ∩ (B ∩ C) = (A ∩ B) ∩ C (associative)
• No. of elements in Power Set (Thm 6.3.1, Epp) • Set Complement (Def 6.4.10, Slides):
– A⊆B ↔A∩B =A Let U be the Universal set, let A ⊆ U. Then, the com-
For all integers n ≥ 0, if a set X has n elements, then
P(X) has 2n elements. – A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) plement of A, denoted Ac , is U − As
– A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
Created using LATEX 2ε 6 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Created using LATEX 2ε 7 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
• Binary relations (Def 8.2.1): • Associativity of Composition (Prop 8.2.9): • Partition induced by an equivalence relation
Let S, T be two sets. A binary relation from S to T , Let S, T, U, V be sets. Let R ⊆ S × T , R0 ⊆ T × U , (Thm 8.3.4, Epp):
denoted R, is a subset of the Cartesian product S × T R00 ⊆ U × V be relations. Therefore, Let R be an equivalence relation on a set A. Then, the
set of distinct equivalence classes form a partition of A.
N.B. s R t is (s, t) ∈ R and s R t is (s, t) 6∈ R R00 ◦ (R0 ◦ R) = (R00 ◦ R0 ) ◦ R = R00 ◦ R0 ◦ R
• Lemma 8.3.2, Epp:
Properties of Binary Relations • Proposition 8.2.10: Let R be an equivalence relation on a set A and let a, b
Let S, T, U be sets. Let R ⊆ S × T and R0 ⊆ T × U be be two elements in A. If a R b then [a] = [b]
Let R ⊆ S × T be a binary relation from S to T
relations.
• Domain (Def 8.2.2): (R0 ◦ R)−1 = |R−1 {z
◦ R0−1} • Lemma 8.3.3, Epp:
The domain of R is the set reversed order If R is an equivalence relation on a set A and a, b are
elements in A, then, either [a] ∩ [b] = ∅ or [a] = [b].
Dom(R) = {s ∈ S | ∃t ∈ T (s R t)} Properties of Relations on a Set
• Equivalence relation induced by a partition (Thm
Let A be a set and R ⊆ A × A be a relation. We say that
• Image (Def 8.2.3): 8.3.1, Epp):
R is a relation on A.
The image of R is the set Given a partition S1 , S2 , ... of a set A, there exists an
• Reflexive (Def 8.3.1) equivalence relation R on A whose equivalence classes
Im(R) = {t ∈ T | ∃s ∈ S(s R t)} R is reflexive ⇐⇒ ∀x ∈ A, (x R x) make up precisely that partition.
Created using LATEX 2ε 8 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Created using LATEX 2ε 9 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Created using LATEX 2ε 10 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Combinations unordered selection of elements taken from X with rep- • Expected Value
etition allowed. If X = {x1 , x2 , . . . , xn }, we write an r- Suppose the possible outcomes of an experiment, or
• r-combination
combination with repetition allowed as [xi1 , xi2 , . . . , xir ] random process, are real numbers a1 , a2 , . . . , an which
Let n, r be non-negative integers with r ≤ n. An r-
where each xij is in X and some of the xij may equal occur with probabilities p1 , p2 , . . . , pn . The expected
combination of a set of n elements is a subset of r of
each other value of the process is
the n elements. nr , denotes the no. of subsets of size
n
r, that can be chosen from a set of n elements. • No. of r-combinations with repetition (Thm 9.6.1) X
ak pk = a1 p1 + a2 p2 + . . . + an pn
n The no. of r-combination with repetition allowed
k=1
• Formula for (Thm 9.5.1) (multisets of size r) that can be selected from a set of n
r elements is • Conditional Probability
The no. of subsets of size r (r-combinations) that can
r + n − 1
Let A and B be events in a sample space S. If P (A) 6= 0,
be chosen from a set of n elements, nr , is given by the
r then the conditional probability of B given A, de-
formula noted P (B | A) is
n P (n, r) This equals the number of ways r objects can be selected
=
r r! from n categories of objects with repetitions allowed P (A ∩ B)
P (B | A) =
or, equivalently P (A)
• Pascal’s Formula (Thm 9.7.1)
+
n n! Suppose n, r ∈ Z & r ≤ n. Then • Bayes’ Theorem (Thm 9.9.1)
= Suppose that a sample space S is a union of mutually
r r!(n − r)!
n+1 n n
= + disjoint events B1 , B2 , . . . , Bn .
where n, r are non-negative integers with r ≤ n. r r−1 r Suppose A is an event in S, and suppose A and all the
• Permutations with sets of indistinguishable ob- Bi have non-zero probabilities.
• Binomial Theorem (Thm 9.7.2)
jects (Thm 9.5.2) If k ∈ Z with 1 ≤ k ≤ n, then
Given any a, b ∈ R and any non-negative integer n,
Suppose a collection consists of n objects of which P (A | Bk ) · P (Bk )
n P (Bk | A) =
X n P (A | B1 ) · P (B1 ) + . . . + P (A | Bn ) · P (Bn )
n1 of type 1 & are indistinguishable from each other (a + b)n = an−k bk
n2 of type 2 & are indistinguishable from each other k
k=0 • Independent Events
..
n
n
If A, B are events in a sample space S, then A and B
. = an + an−1 b1 + . . . + a1 bn−1 + bn
nk of type k & are indistinguishable from each other 1 n−1 are independent iff P (A ∩ B) = P (A) · P (B)
Created using LATEX 2ε 11 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
CS1231: Graphs
Basic Definitions • Subgraph of a Graph Trails, Paths and Circuits
A graph H is said to be a subgraph of graph G, iff,
• Graph Let G be a graph and let v, w be vertices of G.
every vertex in H is also a vertex in G, every edge in H
A graph G consists of 2 finite sets: a nonempty set is also an edge in G, and every edge in H has the same • Walk
V (G) of vertices and a set E(G) of edges, where each endpoints as it has in G. A walk from v to w is a finite alternating sequence of
edge is associated with a set consisting of either one or
adjacent vertices and edges of G. Thus, a walk has the
two vertices called its endpoints. • Complete Bipartite Graphs
form
A complete bipartite graph on (m, n) vertices,
A edge is said to connect its endpoints; two vertices v0 e1 v1 e2 . . . vn−1 en vn
where m, n > 0, denoted Km,n , is a simple graph with
that are connected by an edge are called adjacent ver- distinct vertices v1 , v2 , . . . , vm and w1 , w2 , . . . , wn that where the v’s represent vertices, the e’s represent edges,
tices; and a vertex that is an endpoint of a loop is said satisfies the following properties: v0 = v, vn = w and for all i ∈ {1, 2, . . . , n}, vi−1 and vi
to be adjacent to itself. are the endpoints of ei
For all i, k = 1, 2, . . . , m and for all j, l = 1, 2, . . . , n,
An edge is said to be incident on each of its endpoints,
• Trivial Walk
and two edges incident on the same endpoint are called 1. There is an edge from each vertex vi to each vertex
A trivial walk from v to v consists of the single vertex v
adjacent edges. wj
We write e = {v, w} for an edge e incident on vertices 2. There is no edge from any vertex vi to any other • Trail
vertex vk A trail from v to w is a walk from v to w that does
v and w.
3. There is no edge from any vertex w to any other not contain a repeated edge
j
• Directed Graph vertex wl • Path
A directed graph, or digraph, G, consists of 2 finite A path from v to w is a trail that does not contain a
• Degree of a Vertex and Total Degree of a Graph
sets: a nonempty set V(G) of vertices and a set D(G) repeated vertex
Let G be a graph and v a vertex of G. The degree
of directed edges, where each edge is associated with
of v, denoted deg(v), equals the number of edges that • Closed Walk
an ordered pair of vertices called its endpoints.
are incident on v, with an edge that is a loop counted A closed walk is a walk that starts and ends at the
If edge e is associated with the pair (v, w) of vertices, twice. same vertex
then e is said to be the (directed) edge from v to w. The total degree of G is the sum of the degrees of all
We write e = (v, w). the vertices of G. • Circuit/Cycle
A circuit/cycle is a closed walk thtat contains at
• Simple Graph • Handshake Theorem (Thm 10.1.1) least one edge and does not contain a repeated edge
A simple graph is a undirected graph that does not If G is any graph, then the sum of the degrees of all
have any loops or parallel edges. the vertices of G equals twice the number of edges of G. • Simple Circuit/Cycle
Specifically, if the vertices of G are v1 , v2 , . . . , vn , where A simple circuit/cycle is a circuit that does not have
• Complement of Simple Graph (Tutorial 10) n ≥ 0, then any other repeated vertex except first and last
If G is a simple graph, the complement of G, denoted
Total degree of G = deg(v1 ) + deg(v2 ) + . . . + deg(vn ) • Triangle
G0 , is obtained as follows: The vertex set of G0 is identi-
cal to the vertex set of G. However, two distinct vertices = 2 · (the no. of edges of G) A simple circuit of length three is called a triangle
0
v and w of G are connected by an edge iff v & w are • Connectedness
• Corollary 10.1.2
not connected by an edge in G. Vertices v and w in graph G are connected iff there is
The total degree of a graph is even
a walk from v to w
• Complete Graph • Proposition 10.1.3
A complete graph on n vertices, n > 0, denoted Kn , In any graph there are an even numer of vertices of odd • Connected Graph
is a simple graph with n vertices and exactly one edge degree The graph G is connected, iff, given any two vertices
connecting each pair of distinct vertices. v and w in graph G, there is a walk from v to w
Created using LATEX 2ε 12 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
• Lemma on Connectedness • Theorem 10.2.4: USE THIS FOR EULER Matrix Representation of Graphs
Let G be a graph A graph G has an Euler circuit ⇐⇒ G is connected
• Matrix
and every vertex of G has positive even degree
1. If G is connected, then any two distinct vertices in An m × n matrix A over a set S is a rectangular array
G can be connected by a path of elements of S arranged into m rows and n columns
• Euler Trail
2. If vertices v and w are part of a circuit in G and Let G be a graph, and let v and w be two distinct ver- • Adjacency Matrix of a Directed Graph
one edge is removed from the circuit, then there tices of G. An Euler trail/path from v to w is a Let G be a directed graph with ordered vertices
still exists a trail from v to w in G sequence of adjacent edges and vertices that starts at v1 , v2 , . . . , vn . The adjacency matrix of G is the n×n
v, ends at w, passes through every vertex of G at least matrix A = (aij ) over the set of non-negative integers
3. If G is connected and G contains a circuit, then an
once, and traverses every edge of G exactly once. such that
edge of the circuit can be removed without discon-
nected G aij = the number of arrows from vi to vj
• Corollary 10.2.5
• Connected Component Let G be a graph and let v and w be two distinct ver- for all i, j = 1, 2, . . . , n.
A graph H is a connected component of a graph G tices of G. There is an Euler trail from v to w ⇐⇒ G
• Adjacency Matrix of an Undirected Graph
iff, is connected, v and w have odd degree, and all other
let G be an undirected graph with ordered verices
vertices of G have positive even degree.
1. The graph H is a subgraph of G v1 , v2 , . . . , vn . The adjacency matrix of G is the n×n
matrix A = (aij ) over the set of non-negative integers
2. The graph H is connected such that
3. No connected subgraph of G has H as a subgraph
Hamiltonian Circuits
aij = the number of edges connecting vi and vj
and contains vertices or edges that are not in H • Hamiltonian Circuit
Given a graph G, a Hamiltonian circuit for G is a for all i, j = 1, 2, . . . , n.
Euler Circuits simple circuit that includes every vertex of G. • Symmetric Matrix
That is, a Hamiltonian circuit for G is a sequence of ad- An n × n square matrix A = (aij ) is called symmetric
• Euler Circuit
jacent vertices and distinct edges in which every vertex ⇐⇒ for all i, j = 1, 2, . . . , n
Let G be a graph. An Euler circuit for G is a circuit
that contains every vertex and every edge of G. of G appears exactly once, except for the first and aij = aji
last, which are the same.
That is, an Euler circuit for G is a sequence of adja- (i.e. mirror image along main diagonal)
cent vertices and edges in G that has at least one edge, N.B. Hamiltonian circuit does not have to use all edges,
starts and ends at the same vertex, uses every vertex of but since it is a circuit, it cannot use the same edge more • Theorem 10.3.1
G at least once, and uses every edge of G exactly once. than once. Let G be a graph with connected componenets
G1 , G2 , . . . , Gk . If there are ni vertices in each con-
• Theorem 10.2.2 • Proposition 10.2.6 nected component Gi and these vertices are numbered
If a graph is an Euler circuit, then every vertex of the If a graph G has a Hamiltonian circuit, then G has a consecutively, then the adjacency matrix of G has the
graph has positive even degree subgraph H with the following properties: form:
A1 O O O O
• Contrapositive of 10.2.2 O A2 O . . . O O
1. H contains every vertex of G
O O A3 O O
If some vertex of a graph has odd degree, then the graph
does not have an Euler circuit 2. H is connected
.. .. ..
. . .
• Theorem 10.2.3 3. H has the same number of edges as vertices O O O ... O Ak
If a graph G is connected and the degree of every ver- where each Ai is ni × ni adjacency matrix of Gi for all
tex of G is a positive even integer, then G has an 4. Every vertex of H has degree 2 i = 1, 2, . . . , k, and the O’s represent matrices whose
Euler circuit entries are all 0s
Created using LATEX 2ε 13 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Created using LATEX 2ε 14 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Created using LATEX 2ε 15 License: Creative Commons BY-NC-SA 4.0 International License.
created by Syed Abdullah
Spanning Trees & Shortest Paths • Prim’s Algorithm (Alg 10.7.2) – D(u) ← v
Input: G [a connected weighted graph with n vertices] (c) Find a vertex x in F with the smallest label.
• Spanning Tree
Algorithm: Add vertex x to V (T ), and add edge {D(x), x}
A spanning tree for a graph G is a subgraph of G that
contains every vertex of G and is a tree to E(T ). v ← x
1. Pick a vertex v of G and let T be the graph with
this vertex only Output: L(z) [this is the length of the shortest path
• Proposition 10.7.1
2. Let V be the set of all vertices of G except v. from a to z]
1. Every connected graph has a spanning tree 3. For i = 1 to n − 1
2. Any two spanning trees for a graph have the same (a) Find an edge e of G such that (1) e connects
no. of edges T to one of the vertices in V , and (2) e has
the least weight of all edges connecting T to a
• Weighted Graph vertex in V . Let w be the endpoint of e that
A weighted graph is a graph for which each edge has is in V
an associated positive real number weight. The sum
(b) Add e and w to the edge and vertex sets of T ,
of the weights of all edges is the total weight of the
delete w from V .
graph
Output: T [T is the MST for G]
• Minimum Spanning Tree
A minimum spanning tree for a connected weighted • Dijkstra’s Algorithm (Alg 10.7.3)
graph is a spanning tree that has the least possible to- Input: G [a connected weighted graph with positive
tal weight compared to all other spanning trees for the weight for every edge], ∞ [a no. greater than the sum
graph of the weights of all the edges in G], w(u, v) [the weight
of edge {u, v}], a [the source vertex], z [the dest vertex]
• w(e) & w(G) Algorithm:
If G is a weighted graph and e is an edge of G, then
w(e) denotes the weight of e and w(G) denotes the 1. init T to be the graph with vertex a and no edges.
total weight of G Let V (T ) be the set of vertices of T , and let E(T )
be the set of edges of T
• Kruskal’s Algorithm (Alg 10.7.1)
Input: G [a connected weighted graph with n vertices] 2. Let L(a) = 0, and for all vertices in G except a, let
Algorithm: L(u) = ∞ [The number L(x) is called the label of
x]
1. Init T to have all the vertices of G and no edges 3. Init v to equal a and F to be {a}. [The symbol v
2. Let E be the set of all edges of G, and let m = 0 is used to denote the vertex most recently added
to T ]
3. While (m < n − 1)
4. Let Adj(x) denote the set of vertices adjacent to
(a) Find an edge e in E of least weight vertex x
(b) Delete e from E
5. while (z 6∈ V (T ))
(c) If addition of e to the edge set of T does not
produce a circuit, then add e to the edge set (a) F ← (F − {v}) ∪ {vertices ∈ Adj(v) and
of T and set m = m + 1 6∈ V (T )} [Set F is set of fringe vertices]
(b) For each vertex u ∈ Adj(v) and 6∈ V (T ),
4. End While
– If L(v) + w(v, u) < L(u) then
Output: T [T is the MST for G] – L(u) ← L(v) + w(v, u)
Created using LATEX 2ε 16 License: Creative Commons BY-NC-SA 4.0 International License.