Course - Slides Discrete Structure
Course - Slides Discrete Structure
Discrete Structures
Textbook
Topics - Chapters
Outline
Grading Scale
AA 91 - 110
BA 86 - 90
BB 81 - 85
CB 76 - 80
CC 71 - 75
DC 66 - 70
DD 61 - 65
FD 51 - 60
FF 0 - 50
WEEK 1
Propositional Logic
Definitions
Examples
Logical Operators
Examples
P ¬P
T F
F T
P Q P ∧Q
T T T
T F F
F T F
F F F
P Q P ∨Q
T T T
T F T
F T T
F F F
P Q P→Q
T T T
T F F
F T T
F F T
P Q P↔Q
T T T
T F F
F T F
F F T
WEEK 2
Logic Part II
Definitions
Logical Equivalences
Logical Equivalences
Logical Equivalences
Logical Equivalences
Example
P Q R Q ∧R P ∨ (Q ∧ R) P ∨Q P ∨R (P ∨ Q) ∧ (P ∨ R)
T T T T T T T T
T T F F T T T T
T F T F T T T T
T F F F T T T T
F T T T T T T T
F T F F F T F F
F F T F F F T F
F F F F F F F F
Satisfiability
n-Queens
Predicate
Universal Quantifier
Existential Quantifier
¬∀xP(x) ≡ ∃x¬P(x)
¬∃xP(x) ≡ ∀x¬P(x)
Previous example: Let P(x) be the statement “|x| < 2”.
P(2) is False.
¬P(2) is True.
∃x¬P(x) is True.
¬∀xP(x) is True.
∀xP(x) is False.
Definitions
Modus Ponens
P
P→Q
∴Q
This is equivalent of saying
(P ∧ (P → Q)) → Q
Rules of Inference
Rules of Inference
Rules of Inference
Example 6
Step Reason
(1) ¬P ∧ Q Premise
(2) R→P Premise
(3) ¬R → S Premise
(4) S →T Premise
(5) ¬P (1) simplification
(6) ¬R (5) and (2) modus tollens
(7) S (6) and (3) modus ponens
(8) T (7) and (4) modus ponens
Example 13
Step Reason
(1) ∃x(C (x) ∧ ¬B(x)) Premise
(2) ∀x(C (x) → P(x)) Premise
(3) C (a) ∧ ¬B(a) Existensial instantiation from (1)
(4) C (a) Simplification from (3)
(5) C (a) → P(a) Universal instantiation from (2)
(6) P(a) (5) and (4) modus ponens
(7) ¬B(a) Simplification from (3)
(8) P(a) ∧ ¬B(a) (7) and (6) conjunction
(9) ∃x(P(x) ∧ ¬B(x)) Existential generalization from (8)
WEEK 3
Set Theory
Definition
A set is an unordered collection of distinct objects, called elements
or members of the set.
Notation
a ∈ A: a is an element of the set A.
a∈
/ A: a is not an element of the set A.
Examples
Empty set { } or ∅
Singleton set {’a set with one element’}
Venn diagram
Definition (A = B)
Two sets A and B are equal if they have the same elements. That
is,
∀x(x ∈ A ↔ x ∈ B)
Definition (A ⊆ B)
The set A is a subset of B if every element of A is also an element
of B. That is,
A ⊆ B ⇐⇒ ∀x(x ∈ A → x ∈ B)
Theorem
Two sets A and B are equal if and only if A is a subset of B and B
is a subset of A. That is,
A = B ⇐⇒ A ⊆ B and B ⊆ A
Proof.
The proof has two parts:
(⇒) : A = B implies A ⊆ B and B ⊆ A
(⇐) : A ⊆ B and B ⊆ A implies A = B
Assume that A = B.
First, we want to show that A ⊆ B. That is,
∀x(x ∈ A → x ∈ B)
Let x ∈ A be arbitrary.
Since A = B, that is ∀x(x ∈ A ↔ x ∈ B), we have
x ∈ A ↔ x ∈ B (by universal instantiation).
This implies that x ∈ A → x ∈ B.
Since x ∈ A, we get x ∈ B (by modus ponens).
Since x was an arbitrary element of A, we conclude that
A ⊆ B by universal generalization.
Next, we need to show that B ⊆ A. This part is similar to the
proof of A ⊆ B.
Dr. Ferit Toska Discrete Structures
Discrete Structures
Week 3: Set Theory
Definition (Cardinality)
Let S be a set. If there are exactly n distinct elements of S for
some n ∈ N, we say that S is a finite set with the cardinality n.
The cardinality of S is denoted by |S|
A set is said to be infinite if it is not finite.
P(S) = {A | A ⊂ S}
Examples
More Definitions
Definition
Cartesian Product: A × B = {(a, b) | a ∈ A and b ∈ B}
Union: A ∪ B = {x | (x ∈ A) ∨ (x ∈ B)}
Intersection: A ∩ B = {x | (x ∈ A) ∧ (x ∈ B)}
Difference: A − B = {x | (x ∈ A) ∧ (x ∈
/ B)}
Complement: Ā = {x ∈ U | x ∈
/ A} where U is the universal
set.
Examples
Set Identities
Examples
Set Identities
Examples
WEEK 4
Functions
Relations
Definition
Let A and B be sets. A relation R is a subset of A × B.
Example
Let A = {Istanbul,Ankara,Izmir, Adana} and
B = {London, Berlin, Athens}. Then,
F = {(Ist,Lon),(Ist,Ber),(Ist,Ath),(Ank,Ber),(Ank,Ath),(Izm,Ber)}
is a relation.
London Berlin Athens
Istanbul x x x
Ankara x x
Izmir x
Adana
Dr. Ferit Toska Discrete Structures
Discrete Structures
Week 4
Functions
Definition
Let f be a relation from A to B. Then,
f is said to be a function if for all x ∈ A there exists a unique
y ∈ B such that (x, y ) ∈ f . In other words,
if (x, y1 ), (x, y2 ) ∈ f , then y1 = y2 .
If (x, y ) ∈ f , we write f (x) = y and say that y is the image
of x and x is a preimage of x.
A is called the domain of f .
B is called the codomain of f .
The range of f is the set of all images of elements of A.
Example
Let f : Z −→ Z be a function that maps each integer to its
square. That is, f (x) = x 2 . Then,
The domain of f is the set of integers.
The codomain of f is the set of integers.
The range of f is the set of perfect squares {0, 1, 4, 9, 16, ...}.
Mouse dataset
Definition
Let f be a function from A to B. Then,
f is said to be one-to-one, or an injection, if
∀a1 ∀a2 (f (a1 ) = f (a2 ) → a1 = a2 ) or equivalently
∀a1 ∀a2 (a1 6= a2 → f (a1 ) 6= f (a2 )).
f is said to be onto, or a surjection if
(∀b ∈ B)(∃a ∈ A)(f (a) = b)
f is called a bijection if f is both one-to-one and onto.
Let f : {0, 1}∗ −→ {0, 1}∗ be a function that maps each string
u = abc where |a| = |b| = |c| to a. That is, f (u) = a. Then,
The domain of f :
The codomain of f :
The range of f :
Is f an injection, surjection,bijection?
Inverse functions
Definition
Let f be a function from A to B. Then, If f is a bijection, then the
inverse function of f is a function, denoted by f −1 , such that
f −1 (b) = a
when f (a) = b.
Compositions of functions
Definition
Let g be a function from A to B and f be a function from B to C .
Then, the composition of the functions f and g , denoted by
f ◦ g , is the function from A to C defined by
(f ◦ g )(a) = f (g (a))
7 8 9
4 5 6
1 2 3
Sequences
Definition
A sequence is a function from a subset of integers to a set S. We
use the notation an to denote the image of the integer n. We call
an a term of the sequence.
Examples
1
an = n
bn = 2 · 3n
cn = 7 + 2 · n
dn = 5 + (−1)n · dn−1 and d0 = 1 (range of this function?)
Fibonacci sequence
Ackermann function
more examples
Recurrence
Definition
A recurrence relation for the sequence {an } is an equation that
expresses an in terms of one or more of the previous terms of the
sequence.
Summation
more examples
WEEK 5-6
Algorithms
Algorithm
Definition (Algorithm)
An algorithm is a finite sequence of instructions for performing a
computation or for solving a problem.
Example
Define an algorithm for finding the largest apple in a basket.
Properties of Algorithms
Input
Output
Definiteness
Correctness
Finiteness
Effectiveness
Generality
Example
https://www.youtube.com/watch?v=cDA3_5982h8
Searching Algorithms
9 17 6 52 4 25 8 23
The Linear Search
The Binary Search
4 6 8 9 17 23 25 52
Sorting Algorithms
A nice animation:
https://www.youtube.com/watch?v=kPRA0W1kECg
There are many nice facts on sorting algorithms. Visit Wikipedia!
Post on the discussion board!
Growth of Functions
Definition (Big-O)
Let f and g be functions from the set of integers or the set of real
numbers to the set of real numbers. We say that f (x) is O(g (x))
if there are constants C and k such that |f (x)| ≤ C |g (x)|
whenever x > k.
Example
Let f (x) = x 2 + 5x + 3. Then, f (x) is O(x 2 ).
Example
Let f (x) = x 2 + 5x + 3. Then, f (x) is O(x 2 ).
Big-Omega
Definition
Let f and g be functions from the set of integers or the set of real
numbers to the set of real numbers. We say that f (x) is Ω(g (x))
if there are constants C > 0 and k such that |f (x)| ≥ C |g (x)|
whenever x > k.
Big-Theta
Definition
Let f and g be functions from the set of integers or the set of real
numbers to the set of real numbers. We say that f (x) is Θ(g (x))
if f (x) is O(g (x)) and f (x) is Ω(g (x)).
In that case, we say that f (x) and g (x) are of the same order.
Introduction
Example
Linear Search
Worst Case
Analyze the binary search algorithm.
Assume that the input size is n = 2k and x is searched.
Worst case: The algorithm runs “all the way” and exits
without finding x.
1 Is there a middle element am ?
2 Compare x and am
3 Update the end points
Repeat steps 1-3 until there is no middle point.
Each time we reduce the length of the list to its half.
2k , 2k−1 , ..., 21 , 20 .
That is k = log 2k = logn repeats.
worst case Θ(logn) time complexity.
Dr. Ferit Toska Discrete Structures
Discrete Structures
Week 5: Algorithms
Complexity of Algorithms
important notions
brute-force algorithms
greedy algorithms
polynomial complexity
tractable & intractable problems
class NP: non-deterministic polynomial time
NP-complete problems
decidable (solvable) & undecidable problems
Example
WEEK 7
Number Theory
Division
Definition
Let a, b ∈ Z. We say that a divides b, denoted by a | b if
(∃m ∈ Z)(a · m = b).
Example
Let n ∈ Z. List the positive integers d such that d | n.
n = 2: {1, 2}
n = 6: {1, 2, 3, 6}
n = 7: {1, 7}
n = 12: {1, 2, 3, 4, 6, 12}
Theorem
Let a, b, c ∈ Z such that a 6= 0. Then,
(i) if a | b and a | c, then a | (b + c)
(ii) if a | b, then a | m · b for all m ∈ Z
(iii) if a | b and b | c, then a | c.
Proof
Corollary
If a, b, c ∈ Z where a 6= 0, such that a | b and a | c, then for all
m, n ∈ Z, a | (mb + nc).
d: divisor
a: dividend
q: quotient
r : remainder
Modular Arithmetic
Definition
If a, b, m ∈ Z where m > 0, then a is congruent to b modulo m
if m | (a − b). We write a ≡ b (mod m).
Theorem
a ≡ b (mod m) if and only if the remainder from the division of a
to m, and the remainder from the division of b to m are equal.
Theorem
a ≡ b (mod m) if and only if ∃k ∈ Z such that a = b + km
Representations of Integers
Theorem
Let b, n ∈ N where b > 1. Then n can be expressed uniquely in the
form
n = ak b k + ak−1 b k−1 + ... + a1 b + a0
where k is nonnegative integer, a0 , a1 , ..., ak are nonnegative
integers less than b, and ak 6= 0.
(101101)2 = 1 · 25 + 0 · 24 + 1 · 23 + 1 · 22 + 0 · 21 + 1 · 20
= 32 + 8 + 4 + 1 = 45
Dr. Ferit Toska Discrete Structures
Discrete Structures
Representations of Integers
Prime Numbers
Prime Numbers
Definition
An integer p greater than 1 is called prime if the only positive
factors of p are 1 and p. A positive integer that is greater than 1
and is not prime is called composite.
Example
198 = 2 · 3 · 3 · 11
Theorem
If n is a composite integer, then n has a prime divisor less than or
√
equal to n.
Theorem
There are infinitely many primes.
Definition (gcd)
Let a, b be non-zero integers. The largest integer d such that d | a
and d | b is called the greatest common divisor of a and b, and
denoted by gcd(a, b).
Example
Find gcd(60, 210)
divisors of 60: A = {1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60}
divisors of 210:
B = {1, 2, 3, 5, 6, 7, 10, 14, 15, 21, 30, 35, 42, 70, 105, 210}
max(A ∩ B) = 30.
Definition
The integers a and b are relatively prime if gcd(a, b) = 1.
Definition (lcm)
The least common multiple of two positive integers a and b is
the smallest positive integer that is divisible by both a and b, and
denoted by lcm(a, b).
Theorem
Let a be b be positive integers. Then ab = gcd(a, b) · lcm(a, b)
Week 8:
Induction and Recursion
Peano Axioms
Robinson Arithmetic
1 ∀x (0 6= S(x))
2 ∀x, y (S(x) = S(y ) → x = y )
3 ∀x (x + 0 = x)
4 ∀x, y (x + S(y ) = S(x + y ))
5 ∀x (x · 0 = 0)
6 ∀x, y (x · S(y ) = x · y + x)
+ Mathematical Induction
7 For any propositional function P(n) (in the language of
arithmetic)
(P(0) ∧ ∀k (P(k) → P(k + 1))) → ∀n P(n)
Examples
n(n+1)
1 + 2 + ... + n = 2
1 + 2 + 22 + ... + 2n = 2n+1 −1
2n < n!, for all n ≥ 4
Mistaken Proofs
Every set of lines in the plane, no two of them are parallel, meet in
a common point.
Strong Induction
Example
example
Definition
The set {0, 1}∗ of strings is defined recursively by
λ ∈ {0, 1}∗ where λ is the empty string.
If w ∈ {0, 1}∗ and a ∈ {0, 1}, then wa ∈ {0, 1}∗ .
Example
Let u ∈ {0, 1}∗ be fixed. Then u ∗ is defined recursively by
u ∈ u∗
If w ∈ u ∗ , then wu ∈ u ∗
Example
A recursive algorithm for gcd(a, b) where 0 ≤ a < b:
if a = 0 then return b
else
find q, r such that b = a · q + r where 0 ≤ r < a
return gcd(r , a)
Week 9:
Counting
Relations
Product Rule
Sum Rule
Subtraction Rule
Division Rule
Pigeonhole Principle
Relations
Definition
Let A and B be sets. A relation R is a subset of A × B.
Example
Let A = {Istanbul,Ankara,Izmir, Adana} and
B = {London, Berlin, Athens}. Then,
F = {(Ist,Lon),(Ist,Ber),(Ist,Ath),(Ank,Ber),(Ank,Ath),(Izm,Ber)}
is a relation.
London Berlin Athens
Istanbul x x x
Ankara x x
Izmir x
Adana
Dr. Ferit Toska Discrete Structures
Discrete Structures
Week 9
Properties of Relations
p.608 pr.3
For each of these relations on the set {1, 2, 3, 4}, decide whether it
is reflexive, whether it is symmetric, whether it is antisymmetric,
and whether it is transitive.
a) {(2, 2), (2, 3), (2, 4), (3, 2), (3, 3), (3, 4)}
b) {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}
c) {(2, 4), (4, 2)}
d) {(1, 2), (2, 3), (3, 4)}
e) {(1, 1), (2, 2), (3, 3), (4, 4)}
f) {(1, 3), (1, 4), (2, 3), (2, 4), (3, 1), (3, 4)]}
Equivalence Relation
Definition
A relation on a set A is called an equivalence relation if it is
reflexive, symmetric, and transitive.
Definition
Let R be an equivalence relation on a set A. The set of all
elements that are related to an element a of A is called the
equivalence class of a, denoted by [a]R .
[a]R = {x ∈ A : (a, x) ∈ R}
Example
What are the equivalence classes of congruence modulo 3?
[0] = {
[1] = {
[2] = {
Theorem
Let R be an equivalence relation on a set A. These statements for
elements a and b of A are equivalent:
(i) aRb
(ii) [a] = [b]
(iii) [a] ∩ [b] 6= ∅
Order Relations
Definition
A relation R on a set S is called a partial order if it is reflexive,
antisymmetric, and transitive.
Example
(Z, ≤)
(P(A), ⊂)
(Z+ , a|b)
Definition
The elements a and b of a poset (S, ) are called comparable if
either a b or b a.
Definition
If (S, ) is a poset and every two elements of S are comparable, S
is called a totally ordered or linearly ordered set, and is called
a total order or a linear order.
Week 10:
Graph Theory
Examples
Examples
Examples
Examples
Examples
Graph Terminology
Definitions
Simple Results
Bipartite Graphs
Adjacency Matrix
1 2 0 1
2 0 3 0
0 3 1 1
1 0 1 0
Graph Isomorphism
Definition
The simple graphs G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are
isomorphic if there exists a bijection f between V1 and V2 with
the property that
{u, v } ∈ E1 ⇐⇒ {f (u), f (v )} ∈ E 2
Example
Path
Erdős Number
Definition
A graph is called connected if there is a path between every pair of
vertices of the graph.
Theorem
There is a simple path between every pair of distinct vertices of a
connected graph.
Bridges of Konigsberg
Results
Theorem
A connected multigraph with at least two vertices has an
Euler circuit if and only if its vertices has an even degree.
A connected multigraph has an Euler path but not an Euler
circuit if it has exactly two vertices of odd degree.
Definition
A simple path in a graph G that passes through every vertex
exactly once is called a Hamilton path.
A simple circuit in a graph G that passes through every vertex
exactly once is called a Hamilton circuit.
weighted graphs.
Dijkstra’s Algorithm
Dijkstra’s Algorithm
Week 12:
Trees
Definition
A tree is a connected graph with no simple circuits.
Theorem
An undirected graph is a tree if and only if there is a unique simple
path between any two of its vertices.
Two Examples
Rooted Trees
Definition
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.
Important notions:
parent
child
siblings
ancestors
descendants
leaf
internal vertices
subtree
Dr. Ferit Toska Discrete Structures
Discrete Structures
Week 12
Rooted Tree
Properties of Trees
Theorem
A tree with n vertices has n − 1 edges.
Theorem
A full m-ary tree with i internal vertices contains n = mi + 1
vertices.
Theorem
There are at most mh leaves in an m-ary tree of height h.
Applications
Binary Search
Decision Trees
Prefix Codes
Huffman Coding
Tree Traversal
Preorder traversal
Inorder traversal
Postorder traversal
Spanning Trees
Definition
Let G be a simple graph. A spanning tree of G is a subgraph of
G that is a tree containing every vertex of G .
Theorem
A simple graph is connected if and only if it has a spanning tree.
Depth-First Search
Breadth-First Search