HelpSheet CS1231S Full
HelpSheet CS1231S Full
Hi, I’m Chee Xiang, also known as Pallon. I have created this help sheet for my own study, and it is the
treasure and culmination of my efforts. However, for some reason, I have decided to share this help sheet
with other students, including you. One of the main reasons is that I hope it can help you in your studies.
Another fun reason is to observe how my little help sheet can spread throughout our community. You can
think of it as me performing a Breadth-First Search (BFS) with myself as the root node, trying to find the
maximum depth.
I'm sure it will also be fun to keep a record of who is in our community. Therefore, I have created a
contributor list that records those who have progressively contributed to the improvement of this help sheet
(of course, it starts with only me). If you're bored or interested, you can also check their LinkedIn profiles (if
they have provided them) to connect with them. You can find the contributor list here:
https://docs.google.com/spreadsheets/d/1r2SgdThPMcMoWAEyFPwaqrq1CjQ87ZfKuwDy0lADPJM/edit#
gid=0
Feel free to click on this link to provide me with feedback on this help sheet:
https://docs.google.com/forms/d/1taARJqNnGrxbzEunaVD6IhviVO5hTVbMv6D66nSnaJw/edit
Lastly, please note that this help sheet is not perfect, and it could contain errors or undergo changes in
versions, despite all the contributors and me doing our best to maintain its correctness. The latest version of
the help sheet can be retrieved at https://github.com/PallonCX/CS1231S-Helpsheet. Please use it at your
own risk.
Wishing you all the best in your studies!
Proofs:
Type of Proof Pattern Usage
Proof by construction 1. Let / Consider -When a specific value with some
(Direct proof) 2. Note that (The thing let above have some properties is required to suffice the
property) proof
3. Also, (With the property, we can conclude that) -To proof existential statement (Find
a specific value or give directions to
find)
Disproof by counter 1. Let -To show a statement is false (Often
example 2. Therefore, (With the property of the thing let for universal statement)
above, the statement is not true) -One counter-example is sufficient
Proof by exhaustion / 1. Let (Specific values from cases, such as 0, 1) -Number of cases is finite
Proof by cases / Proof 1.1 (Show that everything let above suffice the
by brute force statement)
2. Therefore, (Conclude)
Proof by deduction 1. Let (An abstract value, such as n, k) -Number of cases is infinite
(Direct proof) 1.1 (Show that the thing let above suffice the -General problem
statement)
2. Therefore, (Conclude)
Proof by contradiction 1. Suppose not, that is, (The negation of the -The statement to prove is absence
(Indirect proof) statement) of form
1.1 (Show that we can deduce something that -Direct proof is difficult
contradicts the assumption)
2. Therefore, the assumption that (The negation of
the statement) is false.
3. Hence (The statement we want to prove)
Proof by 1. Contrapositive statement: (The contraposition -Conditional statement that is hard to
contraposition of statement) prove in the original direction
2. (Prove the contrapositive statement)
3.Hence, (The original statement is true)
Proof by Mathematical 1. Let 𝑃(𝑛) ≡ … (Set up predicate.)
Induction 2. Basis step: …
3. Assume 𝑃(𝑘) is true for some 𝑘 (Inductive
Hypothesis)
4. Inductive step: (Start from k + 1, and use
*Implication law: p ® q º ~p Ú q
*Variant absorption laws: 𝑝∧(~𝑝∨𝑞)≡𝑝∧𝑞 or 𝑝∨(~𝑝∧𝑞)≡𝑝∨𝑞
Logical Not / If-then / Implies: If and only if: And: Ù Or: Ú Exclusiv
connectiv Negation: ~ ® « *We use “but” e-or
es in English (Special)
sometimes
Truth (p Ú q) Ù
tables ~ (p Ù q)
Converse error / Fallacy of affirming the Inverse error Valid argument with a false
consequence premise (Logical problem in
premise)
Symbol: Universal quantifier / " denotes “for all” (or “for any”, “for every”, “for each”)
Symbol: Existential quantifier / $ denotes “there exists”, “there is a”, “we can find a”, “there is at least one”, “for
some”, and “for at least one”.
* The words “such that” or “s.t.” are inserted just before the predicate. (May omit)
*$! is used to denote “there exists a unique” or “there is one and only one”.
Theorem 4.2.1 (5th: 4.3.1): Every integer is a rational number. (Constructive Proof)
Theorem 4.2.2 (5th: 4.3.2): The sum of any two rational numbers is rational. (Constructive Proof)
Proposition 4.6.4 (5th: 4.7.4): For all integers 𝑛, if 𝑛2 is even than 𝑛 is even. (Proof by contraposition)
Theorem 6.2.4: An empty set is a subset of every set, i.e. ∅⊆𝐴 for all sets 𝐴.
Definition: Partition:
Lecture #5 Slides #29 Division of set into nonoverlapping (or disjoint) pieces.
Lecture #5 Slides #30 If A is called a union of mutually disjoint subsets A1, A2, A3, and A4, then the collection of sets
{A1, A2, A3, A4} is said to be a partition of A.
Theorem 6.3.1: Suppose 𝐴 is a finite set with 𝑛 elements, then 𝒫(𝐴) has 2$ elements. In other words, |𝒫(𝐴)| = 2|,| .
(Proof by mathematical induction)
Assignment #1 Question #6 :
(a) 𝐴⊆𝐵⇔𝒫(𝐴)⊆𝒫(𝐵). (Proved)
(b) (𝐴∪𝐵=𝐴∪𝐶)⇒𝐵=𝐶. (Disproved)
(c) (𝐴∩𝐵=𝐴∩𝐶)⇒𝐵=𝐶. (Disproved)
(d) (𝐴∪𝐵=𝐴∪𝐶)∧(𝐴∩𝐵=𝐴∩𝐶)⇒𝐵=𝐶. (Proved)
Common questions:
1. Find power set – Just list out, can check by number of element
2. Prove set equality – Noted does the question mention set operation (also called element method, which is the
definition of sets and some propositional logic) or set identities
3. Find partition – Non-empty subsets + Mutually disjoint + Every element in exactly one of the component
Made by Tan Chee Xiang (Pallon)
Version 1.0
Made by Tan Chee Xiang (Pallon)
Version 1.0
Lecture 6: Relations
Definition: Relation Lecture #6 Slides #6:
Let 𝐴 and 𝐵 be sets. A (binary) relation from 𝑨 to 𝑩 is a subset of 𝑨×𝑩. Given an ordered pair (𝑥,𝑦) in 𝐴×𝐵, 𝒙 is
related to 𝒚 by 𝑹, or 𝒙 is 𝑹-related to 𝒚, written 𝒙 𝑹 𝒚, iff (𝒙,𝒚)∈𝑹.
* 𝑥 𝑅 𝑦 means (𝑥, 𝑦) ∈ 𝑅, 𝑥 𝑅 𝑦 means (𝑥, 𝑦) ∉ 𝑅
Definition: Partial Order Relation (Symbol ≼ (Curly less than or equal to)) Lecture #6 Slides #68:
Let 𝑅 be a relation on a set 𝐴. Then 𝑅 is a partial order relation (or simply partial order) iff 𝑅 is reflexive,
antisymmetric and transitive.
*May view as a set of tasks
Proposition: A smallest element is minimal / A largest element is maximal. Lecture #6 Slides #83:
Consider a partial order ≼ on a set 𝐴. Any smallest element is minimal and any largest element is maximal.
Definition: Total Order Relations Lecture #6 Slides #86:
If 𝑅 is a partial order relation on a set 𝐴, and for any two elements 𝑥 and 𝑦 in 𝐴, either 𝑥 𝑅 𝑦 or 𝑦 𝑅 𝑥, then 𝑅 is a total
order relation (or simply total order) on 𝐴. 𝑅 is a total order iff 𝑅 is a partial order and ∀𝑥,𝑦∈𝐴 (𝑥 𝑅 𝑦 ∨𝑦 𝑅 𝑥).
*Hasse diagram of total order is one single line (chain)
Definition: Linearization of a partial order Lecture #6 Slides #87:
Let ≼ be a partial order on a set 𝐴. A linearization of ≼ is a total order ≼∗ on
𝐴 such that ∀𝑥, 𝑦 ∈ 𝐴 (𝑥 ≼ 𝑦 ⇒ 𝑥 ≼∗ 𝑦).
*Linearization of a total order is the total order itself.
*If two elements are not comparable, their order can be interchangeable as long
as does not violate the conditions.
Tutorial #5 Question #6: Every asymmetric relation is antisymmetric. (asymmetry property forces the antisymmetry
property to be vacuously true.)
Tutorial #5 Question #7: Consider a set 𝐴 and a total order ≼ on 𝐴. Show that all minimal elements are smallest.
Tutorial #5 Question #10: In all partially ordered sets, any two comparable elements are compatible.
Common questions:
1. Find relation – Use definition of relation, definition of inverse relation, definition of composition of relations
2. Find equivalence class – Use definition of equivalence class, definition of ~
3. Proof equivalence – Proof Reflexivity, Symmetry, Transitivity
Composition with an Identity Function Theorem 7.3.1: Let 𝑓: 𝑋 → 𝑌. 𝑓 ∘ 𝑖𝑑6 = 𝑓 and 𝑖𝑑7 ∘ 𝑓 = 𝑓.
Composition of a Function with Its Inverse Theorem 7.3.2: Let 𝑓: 𝑋 → 𝑌. 𝑓 .' ∘ 𝑓 = 𝑖𝑑6 and 𝑓 ∘ 𝑓 .' = 𝑖𝑑7 .
Composition of Injections Theorem 7.3.3: If 𝑓: 𝑋 → 𝑌 and 𝑔: 𝑌 → 𝑍 are both injective, then 𝑔 ∘ 𝑓 is injective.
Composition of Surjections Theorem 7.3.4: If 𝑓: 𝑋 → 𝑌 and 𝑔: 𝑌 → 𝑍 are both surjective, then 𝑔 ∘ 𝑓 is surjective.
Tutorial #6 Question #6: Let 𝑓:𝐵→𝐶. If function 𝑔 with domain 𝐶 such that 𝑔∘𝑓 is injective, 𝑓 is injective.
Tutorial #6 Question #7: Let 𝑓:𝐵→𝐶. If function 𝑒 with codomain 𝐵 such that 𝑓∘𝑒 is surjective, 𝑓 is surjective.
Tutorial #6 Question #9: Let 𝑓:𝐴→𝐵 be a function. Let 𝑋⊆𝐴 and 𝑌⊆𝐵. 𝑋⊆𝑓−1(𝑓(𝑋)). 𝑓(𝑓−1(𝑌))⊆𝑌.
Common question:
1. Determine whether a relation is a function: Proof by the two condition of function or disproof by counterexample
2. Determine whether a function is bijection: Proof injective and surjective or Theorem 7.2.3: If 𝑓: 𝑋 → 𝑌 is a
bijection, then 𝑓 .' : 𝑌 → 𝑋 is also a bijection. In other words, 𝑓: 𝑋 → 𝑌 is bijective iff 𝑓 has an inverse.
3. Len(): Careful that the argument is element or set
4. Determine whether a function has inverse: Theorem 7.2.3: If 𝑓: 𝑋 → 𝑌 is a bijection, then 𝑓 .' : 𝑌 → 𝑋 is also a
bijection. In other words, 𝑓: 𝑋 → 𝑌 is bijective iff 𝑓 has an inverse.
5. Determine well-defined: Proof [𝑥1]*[𝑦1]=[𝑥2]*[𝑦2] by Lemma Rel.1.
Corollary 7.4.4 (Contrapositive of Theorem 7.4.3): Any set with an uncountable subset is uncountable.
Proposition 9.3 Lecture #9 Slides #43: Every infinite set has a countably infinite subset.
Tutorial #8 Question #2: 𝐵 be a countably infinite set and 𝐶 a finite set. 𝐵 ∪ 𝐶 is countable.
Tutorial #8 Question #3: Suppose 𝐴1, 𝐴2, ⋯ are finite sets. Then ⋃n 𝑖=1 𝐴𝑖 is finite for any 𝑛 ≥ 2.
Tutorial #8 Question #4: Suppose 𝐴1,𝐴2,𝐴3,⋯ are countable sets. ⋃n 𝑖=1 𝐴𝑖 is countable for any 𝑛∈ℤ+.
Tutorial #8 Question #7: A set 𝐵 is infinite if and only if there is 𝐴⊊𝐵 such that |𝐴|=|𝐵|.
Principle of Sum (or the Addition Principle) Lecture #10 Slides #31:
If we have m ways of doing something and n ways of doing another thing and we cannot do both at the same time,
then there are m+n ways to choose one of these actions.
Formula for the Probability of the Complement of an Event Lecture #10 Slides #48:
If S is a finite sample space and A is an event in S, then 𝑃(𝐴̅) = 1 − 𝑃(𝐴)
Definition: Generalized Pigeonhole Principle (Contrapositive Form) Lecture #10 Slides #65:
For any function f from a finite set X with n elements 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 elements, then X has at most km elements; in other words, n £ km.
Tutorial #9 Question #6: In general, the number of circular permutations of 𝑛 objects is (𝑛−1)!
Common question:
1. Possibilities for tournament play - Possibility tree
2. No. of Personal Identification Numbers (PINs) / Pick card - Multiplication rule (& addition rule or difference rule
sometimes)
3. No. of subset - Multiplication rule
4. No. of ways to choose people - Multiplication rule or Possibility tree
5. Permutations of the letters in a word - Permutation
6. Counting elements of a general union - Inclusion / Exclusion rule
7. Birthday problem / Last initial problem – PHP
8. Decimal expansions of fraction (the decimal expansion of any rational number either terminates or repeats.) – PHP
9. Student computer problem – PHP (Contrapositive)
10. Circular table problem – (S1) Put the first type of element in to permutation (S2) The space between the elements
are allowed to choose and permutatation *Treat empty chair as a person
Definition: Multiset / r-Combinations with Repetition Allowed Lecture #11 Slides #18:
An r-combination with repetition allowed, or multiset of size r, chosen from a set X of n elements is an unordered
selection of elements taken from X with repetition allowed. If X = {𝑥' , 𝑥( , ⋯ , 𝑥$ }, we write an r-combination with
repetition allowed as ¥𝑥## , 𝑥#$ , ⋯ , 𝑥#, ¦ where each 𝑥#- is in X and some of the 𝑥#- may equal each other.
Definition: Pairwise Independent and Mutually Independent Lecture #11 Slides #79:
Let A, B and C be events in a sample space S. A , B and C are pairwise independent, if and only if, they satisfy
conditions 1 – 3 below. They are mutually independent if, and only if, they satisfy all four conditions below.
(1) P(A Ç B) = P(A) × P(B) (2) P(A Ç C) = P(A) × P(C) (3) P(B Ç C) = P(B) × P(C) (4) P(A Ç B Ç C) = P(A) × P(B) ×
P(C)
Proposition 10.1.3: In any graph there are an even number of vertices of odd degree.
Definition: Indegree and outdegree of a Vertex of a Directed Graph Lecture #12 Slides #26:
Let G=(V,E) be a directed graph and v a vertex of G. The indegree of v, denoted deg-(v), is the number of directed
edges that end at v. The outdegree of v, denoted deg+(v), is the number of directed edges that originate from v. Note
that ∑Q∈S 𝑑𝑒𝑔. (𝑣) = ∑Q∈S 𝑑𝑒𝑔- (𝑣) = |𝐸|.
Lemma 10.2.1: Let G be a graph. (1) If G is connected, then any two distinct vertices of G can be connected by a path.
(2) If vertices v and w are part of a circuit in G and one edge is removed from the circuit, then there still exists a trail
from v to w in G.
(3) If G is connected and G contains a circuit, then an edge of the circuit can be removed without disconnecting G.
Contrapositive Version of Theorem 10.2.2: If some vertex of a graph has odd degree, then the graph does not have an
Euler circuit.
Theorem 10.2.3: If a graph G is connected and the degree of every vertex of G is a positive even integer, then G has
an Euler circuit.
Theorem 10.2.4: A graph G has an Euler circuit if and only if G is connected and every vertex of G has positive even
degree.
Corollary 10.2.5: Let G be a graph, and let v and w be two distinct vertices of G. There is an Euler trail from v to w if
and only if G is connected, v and w have odd degree, and all other vertices of G have positive even degree.
Definition: Hamiltonian Circuit Lecture #12 Slides #49:
Given a graph G, a Hamiltonian circuit for G is a simple circuit that includes every vertex of G. (That is, every
vertex appears exactly once, except for the first and the last, which are the same.)
*Note that although an Euler circuit for a graph G must include every vertex of G, it may visit some vertices more
than once and hence may not be a Hamiltonian circuit.
*On the other hand, a Hamiltonian circuit for G does not need to include all the edges of G and hence may not be an
Euler circuit.
Definition: Hamiltonian Graph Lecture #12 Slides #49:
A Hamiltonian graph (also called Hamilton graph) is a graph that contains a Hamiltonian circuit.
Proposition 10.2.6: If a graph G has a Hamiltonian circuit, then G has a subgraph H with the following properties:
(1) H contains every vertex of G. (2) H is connected. (3) H has the same number of edges as vertices. (4) Every vertex
of H has degree 2.
Theorem 10.3.2: If G is a graph with vertices v1, v2, …, vm and A is the adjacency matrix of G, then for each positive
integer n and for all integers i, j = 1, 2, …, m, the ij-th entry of An = the number of walks of length n from vi to vj.
Kuratowski’s Theorem: A finite graph is planar if and only if it does not contain a subgraph that is a subdivision of
the complete graph 𝐾V or the complete bipartite graph 𝐾),) .
Euler’s Formula: For a connected planar simple graph G = (V, E) with e = |E| and v = |V|, if we let f be the number of
faces or regions, then f = e – v + 2
Definition: Complement of graph Tutorial #10 Question #10:
If 𝐺 is a simple graph, the complement of 𝐺, denoted 𝐺̅, is obtained as follows: the vertex set of 𝐺̅ is identical to
the vertex set of 𝐺. However, two distinct vertices 𝑣 and 𝑤 of 𝐺̅ are connected by an edge if and only if 𝑣 and 𝑤
are not connected by an edge in 𝐺.
Lemma 10.5.1: Any non-trivial tree has at least one vertex of degree 1. (Proof: Pick a vertex of tree and choose the
adjacent vertice without repetition until there’s no adjacent vertice. The algorithm must eventually terminate because
the set of vertices of the tree T is finite and T is circuit-free.)
Definition: Terminal vertex (leaf) and internal vertex Lecture #13 Slides #9:
Let T be a tree. If T has only one or two vertices, then each is called a terminal vertex (or leaf). If T has at least three
vertices, then a vertex of degree 1 in T is called a terminal vertex (or leaf), and a vertex of degree greater than 1 in T
is called an internal vertex.
Theorem 10.5.2: Any tree with n vertices (n > 0) has n – 1 edges. (Proof by Mathematical Induction: In the inductive
step, find a vertex with degree 1 and exclude it from the graph to use the inductive hypothesis)
Lecture #13 Slides #12: A non-trivial tree has at least 2 vertices of degree 1. (Prove with Theorem 10.5.2 and The
Handshake Theorem by contradiction)
Lemma 10.5.3: If G is any connected graph, C is any circuit in G, and one of the edges of C is removed from G, then
the graph that remains is still connected. (Same as Lemma 10.2.1(3))
Theorem 10.5.4: If G is a connected graph with n vertices and n – 1 edges, then G is a tree. (Proof: Since G is
connected, prove by contradiction that G is circuit-free: Use Lemma 10.5.3 to remove edges in circuit until the
subgraph is circuit-free, then by Theorem 10.5.2 it has n – 1 edges)
Definition: Binary Tree, Full Binary Tree Lecture #13 Slides #22:
A binary tree is a rooted tree in which every parent has at most two children. Each child is designated either a left
child or a right child (but not both), and every parent has at most one left child and one right child. A full binary tree
is a binary tree in which each parent has exactly two children.
Definition: Left Subtree, Right Subtree Lecture #13 Slides #22:
Given any parent v in a binary tree T, if v has a left child, then the left subtree of v is the binary tree whose root is the
left child of v, whose vertices consist of the left child of v and all its descendants, and whose edges consist of all those
edges of T that connect the vertices of the left subtree. The right subtree of v is defined analogously.
Theorem 10.6.2: For non-negative integers h, if T is any binary tree with height h and t terminal vertices (leaves), then
t £ 2h. Equivalently, log2 t £ h. (Proof by strong mathematical induction: In inductive step, assume one child and two
child cases)
Term: Tree traversal Lecture #13 Slides #36:
Tree traversal (also known as tree search) is the process of visiting each node in a tree data structure exactly once in a
systematic manner. There are two types of traversal: breadth-first search (BFS) or depth-first search (DFS).
Proposition 10.7.1: (1) Every connected graph has a spanning tree. (2) Any two spanning trees for a graph have the
same number of edges.
Definition: Weighted Graph, Minimum Spanning Tree Lecture #13 Slides #48:
A weighted graph is a graph for which each edge has an associated positive real number weight . The sum of the
weights of all the edges is the total weight of the graph. A minimum spanning tree for a connected weighted graph
is a spanning tree that has the least possible total weight compared to all other spanning trees for the graph. 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 total weight of G.
*If some edges have the same weight, more than one minimum spanning tree can occur.
Definition: Self-complementary graph Tutorial #11 Definition #2:
A self-complementary graph is isomorphic with its complement.
Lemma 10.5.5: Let 𝐺 be a simple, undirected graph. Then if there are two distinct paths from a vertex 𝑣 to a different
vertex 𝑤, then 𝐺 contains a cycle (and hence 𝐺 is cyclic).
Tutorial #11 Question#2: Let 𝐺 be a simple graph with 𝑛 vertices where every vertex has degree at least ⌊𝑛2⌋. 𝐺 is
connected. (Proof by contradiction)
Tutorial #11 Question#5: Let 𝐺 = (𝑉, 𝐸) be a simple, undirected graph. If 𝐺 is connected, then |𝐸| ≥ |𝑉| − 1.
(Proof by Proposition 10.7.1 and Theorem 10.5.2 )
Tutorial #11 Question#6: Let 𝐺 = (𝑉, 𝐸) be a simple, undirected graph. If 𝐺 is acyclic, then |𝐸| ≤ |𝑉| − 1. (Proof
by assuming connected and not connected, addition rule and Theorem 10.5.2 )
Tutorial #11 Question#7: Let 𝐺 = (𝑉, 𝐸) be a simple, undirected graph. 𝐺 is a tree if and only if there is exactly
one path between every pair of vertices.