Logic, Proofs, Sequences, Graphs, Trees-1
Logic, Proofs, Sequences, Graphs, Trees-1
Proposition is a declarative sentence (that is, one that declares a fact) that is either true
or false, but not both.
Examples of propositions
can be true
Britain is a part of Europe
22 = 4
can be false - still a valid proposition
Earth is the nearest planet to the sun
22 = 10
not-propositions
x + 2 = 10 is not a proposition because it depends on x
“Please give me some water” is not a proposition because it is not a declarative
sentence - it is a request
“This statement is false” is a paradox - it is neither true, nor false
“I always tell lies” is a paradox - it is neither true, nor false
“What is the color of the sky” is a question, not a declarative sentence
Atomic propositions are propositions that can not be further divided into different
propositions.
example: p : India is a country
Compound propositions are propositions that are formed by combining one or more
atomic propositions using connectives.
example: q : India is a country, and it is a part of Asia
Logical Operators / Connectives
Truth Table The truth table shows the output for each possible truth value of inputs.
For k variables, the truth table will have 2k rows (since each variable has 2 possibilities -
T / F)
Connectives are the operators that are used to combine one or more propositions.
Example
p : It is snowing today
¬p : It is not snowing today
Truth Table
p ¬p
F T
T F
Conjunction / And (∧)
Example
p : It is snowing today
q : John is carrying an umbrella
p ∧ q : It is snowing today, and John is carrying an umbrella
Truth Table
p q p∧q
F F F
F T F
T F F
T T T
Disjunction / Or (∨)
Example
Truth Table
p q p∨q
F F F
F T T
T F T
T T T
Logical Equivalences (≡)
p∧F ≡F p⋅0=0
(p ∨ q) ∨ r ≡ p ∨ (q ∨ r) (p + q) + r = p + (q + r) Associative
(p ∧ q) ∧ r ≡ p ∧ (q ∧ r) (p ⋅ q) ⋅ r = p ⋅ (q ⋅ r)
p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r) p + qr = (p + q) ⋅ (q + r) Distributive
p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) p ⋅ (q + r) = pq + pr
p ∨ (p ∧ q) ≡ p p + pq = p Absorption
p ∧ (p ∨ q) ≡ p p ⋅ (p + q) = p
p ∨ ¬p ≡ T p+p=1 Negation
p ∧ ¬p ≡ F p⋅p=0
premise conclusion
Conditionals ( p → q )
p implies q q if p
if p, then q q whenever p
q follows from p
q provided that p
p→q implication
¬q → ¬p contrapositive
q→p converse
¬p → ¬q inverse
(p → q) ∧ (p → r) ≡ p → (q ∧ r)
(p → q) ∨ (p → r) ≡ p → (q ∨ r)
(p → q) ∧ (q → r) ≡ (p ∨ q) → r
(p → q) ∨ (q → r) ≡ (p ∧ q) → r
p ⟺ q ≡ (p → q) ∧ (q → p) bi-implication
p ⟺ q ≡ pq + pˉqˉ
(equivalent)
Predicates & Quantifiers
Examples:
To combine multiple facts, we always use implication (→) with forall (∀)
Existential Quantifier - Exists (∃)
∃x : P (x) means that P (x) is true for at least 1 value of x ∈ U (there might be more
for which it is true, but at least 1)
Examples:
Examples
∀x : [x =
0 → (∃y : x ⋅ y = 1)]
∀x : [x =
0 → ∃y : (x ⋅ y = 1 ∧ [¬∃z : (y =
z ∧ x ⋅ z = 1)])]
1)]
∀x : [Even(x) ⟺ ∃k : (x = 2 ⋅ k, k ∈ Z)]
De-Morgan’s Law
p
p→q
(p ∧ (p → q)) → q Modus ponens
∴q
¬q
p→q
(¬q ∧ (p → q)) → ¬p Modus tollens
∴ ¬p
p→q
q→r
((p → q) ∧ (q → r)) → (p → r) Hypothetical syllogism
∴p→r
p→q
(p → q) → (p → (p ∧ q)) Absorption (logic)
∴ p → (p ∧ q)
p
q
((p) ∧ (q)) → (p ∧ q) Conjunction introduction
∴p∧q
p∧q
(p ∧ q) → p Conjunction elimination
∴p
p
p → (p ∨ q) Disjunction introduction
∴p∨q
p→q
r→q ((p → q) ∧ (r → q) ∧ (p ∨
Disjunction elimination
p∨r r)) → q
∴q
p∨q
¬p
((p ∨ q) ∧ ¬p) → q Disjunctive syllogism
∴q
p∨p
(p ∨ p) → p Idempotency
∴p
p∨q
¬p ∨ r
((p ∨ q) ∧ (¬p ∨ r)) → (q ∨ r) Resolution (logic)
∴q∨r
p→q
Biconditional
q→p
((p → q) ∧ (q → p)) → (p ↔ q)
introduction
∴p↔q
Common Sets
Positive
{1, 2, 3, 4 …} = N
Integers (Z+ )
Negative
{−1, −2, −3 …}
Integers (Z− )
Non-Negative
{0, 1, 2, 3 …} = Z+ ∪ {0}
Integers
q
Rationals (Q) q=
0 and gcd(p, q) = 1 (that is, it can be converted to its
lowest terms)
to show p →q
assume that p is true
use axioms, definitions, and previously proven theorems, together with rules of inference
show that q must also be true
Direct Proof
Without loss of generality, consider an odd number n.
By definition of odd, we can write n as n = 2k + 1, k ∈ Z
n2 = (2k + 1)2
= 2 ⋅ (2k 2 + 2k) + 1
= 2m + 1 {m = 2k 2 + 2k
Example 2: Prove that if m and n are both perfect squares, then nm is also a
perfect square
Direct Proof
Consider two perfect squares m and n.
nm = s2 × t2
= (st)2
= k2 {k = st
to show p →q
use the contrapositive ¬q → ¬p, since it is equivalent to the implication
show that the contrapositive is true
Proof by Contraposition
Therefore,
3n + 2 = 3 ⋅ (2k) + 2
= 6k + 2
= 2 ⋅ (3k + 1)
= 2m {m = 3k + 1
Example 2: Prove that if n = ab, where a and b are positive integers, then a ≤ n or
b≤ n
Proof by Contraposition
Then,
ab = ( n + δ1 ) ⋅ ( n + δ1 )
{δ1 > 0, δ2 > 0
=n+ n ⋅ (δ1 + δ2 )
>n
Therefore, ab n
=
□
Proof by Contradiction
to prove p
assume (for the sake of contradiction) that p is false
show that this assumption leads to a contradiction
hence, p must be true
Proof by Contradiction
gcd(p, q) = 1
Now,
p2
2= squaring both sides
q2
2q 2 = p2
Therefore, we have that p2 is even, which means that p is even (by Lemma 1)
p2 = (2k + 1)2
= 2(2k 2 + 2) + 1
= 2m + 1 {m = 2k 2 + 2
Therefore, p2 is odd
□
Therefore,
2q 2 = p2
2q 2 = (2m)2
{∵ p is even
q 2 = 2m2
□
Proof by Constructive Evidence
to show ∃x : P (x)
find evidence for x which satisfies P (x)
Let a = 3, b = 4, c = 5
Then,
a2 + b2 = 32 + 42
= 25
= c2
to show ∃x : P (x)
do some magic! (no other way to put it)
Example 1: Show that there exist irrational numbers x and y such that xy is rational.
2
Consider n = 2 . Two cases arise.
2
Case 1: n = 2 is rational
2
Case 2: n = 2 is irrational
2
Let x = 2 and y = 2.
2
=( 2 )
2 2⋅ 2 2
□
Mathematical Induction
n(n + 1)
Example 1 - Prove that 1 + 2 + 3 + ⋯ + n =
2
Proof by Induction
n(n + 1)
Induction Hypothesis: H(n) :1+2+3+⋯+n= ,n ∈ N
2
Base Cases:
1(1 + 1)
1= . Therefore, H(1)✓
2
2(2 + 1)
1+2=3= . Therefore, H(2)✓
2
3(3 + 1)
1+2+3=6= . Therefore, H(3)✓
2
1 + 2 + 3 + ⋯ + n + (n + 1)
= [1 + 2 + 3 + ⋯ + n] + (n + 1)
=[ ] + (n + 1)
n(n + 1)
{∵ H(n)
2
(n + 1) ⋅ (n + 2)
=
2
∴ H(n + 1)
□
Strong Induction
similar to induction
assume everything below in the Induction Step
Example 1 - Show that if n is an integer greater than 1, then n can be written as the
product of primes
Induction Hypothesis: H(n) : n = pα1 1 ⋅ pα2 1 ⋯ pαk 1 where pi are prime numbers, and αi ∈ W
Base Cases:
2 = 21 . Therefore, H(2)✓
3 = 31 . Therefore, H(3)✓
4 = 22 . Therefore, H(4)✓
5 = 51 . Therefore, H(5)✓
6 = 21 ⋅ 31 . Therefore, H(6)✓
Case 1: (n + 1) is prime
Here, we already have (n + 1) = (n + 1)1 .
Case 2: (n + 1) is composite
By definition of compositie, we can write (n + 1) = ab where a, b ∈ N and a < n + 1 and b <
n+1
Now,
n + 1 = ab
a
b
□
Sequences and Sums
⟨a0 , a1 , a2 … an ⟩
a0 = first term
an = n-th term
$n = $ number of terms
sequences are always ordered
d = common difference
n n−1
∑ a + (i − 1)d
= ∑ a + id
i=1 i=0
n
= [2a + (n − 1)d]
2
n
= [first term + last term]
2
Geometric Progression (GP)
r = common ratio
n n−1
rn − 1
∑ ar i−1
= ∑ ari = a
r−1
i=1 i=0
Sum of ∞ terms of GP
i=0
Useful Summations
n(n + 1)
1+2+3+⋯+n =
2
(n + 1) (2n + 1)
12 + 22 + 32 + ⋯ + n2 = n⋅ ⋅
2 3
n(n + 1)(2n + 1)
=
6
2
n(n + 1)
3
1 +2 +3 +⋯+n 3 3 3
= [ ]
2
1 + 2 + 4 + 8 + ⋯ + 2n = 2n+1 − 1
3n+1 − 1
1 + 3 + 9 + 27 + ⋯ + 3n =
2
1 1 1
1+ + + + ⋯ ∞ terms = 2
2 4 8
1 1 1 1
1+ + + +⋯ ≈ loge n
2 3 4
n
Graphs
Types of graphs
v(v − 1)
Simple undirected No No 0≤e≤
2
v(v + 1)
Pseudo undirected Yes Yes 0≤e≤
2
If the edges have weights associated with them, then we call it a weighted graph (weighted simple undirected, weighted simple directed,
weighted mixed, …)
Basic Graph Definitions
Initial / Start Vertex For a directed edge (a, b) from a to b, the initial vertex is a
Terminal / End Vertex For a directed edge (a, b) from a to b, the initial vertex is b
Basic Graph Theorems
Handshaking
2e = ∑ degree(vi )
vi ∈ V
Theorem
Handshaking vi ∈ V
vi ∈ V
Theorem
This applies even for multi-edges and self loops.
Self loops count as 2 degree
Special Graphs
Simple v=n
Complete
undirected
Graph n(n − 1)
graph with all e=
Kn 2
possible edges
Cycle v=n
a closed loop
Cn
e=n
add a center
Wheel vertex to the v =n+1
Wn cycle and add e = 2n
spokes
Hypercube
n-dimensional v = 2n
(n-cube)
hypercube e = n ⋅ 2n−1
Qn
Bi-partite Graphs
vertex set V can be partitioned into two disjoint sets V1 and V2 such that there
Theorem: A simple graph is bipartite if and only if it is possible to assign one of two
different colors to each vertex of the graph so that no two adjacent vertices are
assigned the same color.
Matching
Rules of Matching
Induced Graph
The subgraph induced by a subset W of the vertex set V is the graph (W , F ), where
the edge set F contains an edge in E if and only if both endpoints of this edge are in
W.
Graph Union
The union of two simple graphs G1 = (V1 , E1 ) and G2 = (V2 , E2 ) is the simple
denoted by G1 ∪ G2
Adjacency List Representation
Undirected
Directed
Adjacency Matrix Representation
Undirected
two graphs are isomorphic if they can be re-drawn to look the same
The simple graphs G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are isomorphic if
that a and b are adjacent in G1 if and only if f (a) and f (b) are adjacent in
G2 , for all a, b ∈ V1 .
Example
Graph Connectivity - basic definitions
∗
A path p= v → u of length n from u to v in G is a sequence of n edges e1 , … , en such that there exists a
Path
sequence x0 = u, x1 , … , xn−1 , xn = v of vertices such that ei has the endpoints xi−1 and xi .
Simple Path path which does not contain the same edge more than once.
Circuit The path is a circuit if it begins and ends at the same vertex, that is, if u = v , and has length greater than zero
Simple Circuit circuit which does not contain the same edge more than once.
Connected Graph An undirected graph is called connected if there is a path between every pair of distinct vertices of the graph.
Disconnected
An undirected graph that is not connected is called disconnected.
Graph
Strongly Connected ∗ ∗
there is a path a → b and a path b → a for all vertices a, b ∈ V
Graph
Weakly Connected
A directed graph is weakly connected if the underlying undirected graph is connected
Graph
Theorem: There is a simple path between every pair of distinct vertices of a connected undirected graph.
Graph Connectivity - measures
Connected
a subgraph which is connected
Components
Strongly Connected ∗ ∗
there is a path a → b and a path b → a for all vertices a, b ∈ V
Components
Cut Vertex /
vertex which when removed makes a connected graph disconnected
Articulation Point
Vertex Cut set of vertices, which on removal make the connected graph disconnected
Cut Edge / Bridge edge which when removed makes a connected graph disconnected
Edge Cut set of edges which on removal make a connected graph disconnected
Vertex Connectivity: κ(G) is the minimum number of vertices that you need to remove to make the
κ(G) graph disconnected or to make the get a graph with a single vertex
Edge Connectivity: λ(G) is the minimum number of edges that you need to remove to make the
λ(G) graph disconnected
v∈V
Euler Paths & Circuits
Hamiltonian Circuit | Hamiltonian path which has same start and end vertex
Note: only the start/end vertex is repeated
Not known
Sufficient Conditions
if any condition matches, a Hamiltonian path exists. But it is not necessary that
every graph with a Hamiltonian path must satisfy these conditions
Dirac’s Theorem: If G is a simple graph with n vertices with n ≥ 3 such
that the degree of every vertex in G is at least n∕2, then G has a Hamilton
circuit.
≥ 3 such that
Ore’s Theorem: If G is a simple graph with n vertices with n
deg(u) + deg(v) ≥ n for every pair of nonadjacent vertices u and v in G,
then G has a Hamilton circuit.
Planar Graphs
A graph is called planar if it can be drawn in the plane without any edges crossing
otherwise, non-planar
Min Vertices: K5
Min Edges: K3,3
Euler’s Formula for Planar graphs
Connected
r = e−v + 2
General
r = e−v + k + 1
Corrolary 1
For connected planar simple graph with more than 3 vertices, e ≤ 3v−6
Corrolary 2
A connected planar simple graph has a vertex of degree not exceeding five.
Corrolary 3
If a connected planar simple graph has e edges and v vertices with v ≥ 3 and no
circuits of length three, then e ≤ 2v−4
Kuratowski’s Theorem
Coloring of a simple graph: color each vertex so that no two adjacent vertices are
assigned the same color
Chromatic number χ(G): least number of colors needed for a coloring of this
graph
4 color theorem
Theorem
An undirected graph is a tree if and only if there is a unique simple path between any
two of its vertices.
Forest
Rooted Tree
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.
m−ary: A rooted tree is called an m-ary tree if every internal vertex has no more than m
children.
Binary tree: m =2
Ternary tree: m = 3
full m−ary: The tree is called a full m-ary tree if every internal vertex has exactly m children.
Tree properties
n−1 (m−1)⋅n+1
n vertices has i = m
internal vertices and
l= m
leaves
each vertex except the root has a parent, and each parent has exactly m children
l leaves + l
m parents + l
m2 grandparents + ⋯ + 1 root
Spanning Trees
All possible spanning trees for graph G have the same number of edges and vertices.
A Spanning tree is a minimally connected sub-graph, which means if we remove any edge
from the spanning tree then it becomes disconnected.
A Spanning tree is a maximally acyclic sub-graph, which means if we add an edge to the
spanning tree then it becomes cyclic.
A Spanning tree always contains n − 1 edges, where n is the total number of vertices in the
graph G.
The total number of spanning trees that a complete graph of n vertices can have is nn−2 .
Theorem
1. Sort all the edges of the graph in the increasing order of their weight.
2. Pick the edge with the smallest weight.
3. Check if it forms a cycle with the spanning tree formed so far.
4. Include the current edge if it does not form any cycle.
Otherwise discard it.
5. Repeat step #3 until there v − 1 edges in the spanning tree
Prim’s Algorithm for MST