Discrete STR Merged
Discrete STR Merged
Discrete STR Merged
• A = {1,2,3}
• A = {x:x is the collection of 3 positive integer less than 4}
Representation of a Set
• There are two ways to represent a set - Tabular form
representation { a, b, …} and Set builder form{x: x satisfies
some property.}
• Example 3 : The set of three positive integers less than 4
can be represented as {1,2,3} as well as in the form {𝒙 ∈
𝑵: 𝒙 < 𝟒}.
• {x:x is the positive integer less than 4} Set builder form
• Example 4 : The set of all real numbers between 1 and 2
can be represented {𝒙 ∈ 𝑹: 𝟏 < 𝒙 < 𝟐}.
Representation of a Set
• Membership of an element 𝑎 in a set 𝐴 is represented as
𝑎 ∈ 𝐴 if 𝑎 is an element of the set 𝐴 and 𝑎 ∉ 𝐴 if 𝑎 is not
an element of the set 𝐴.
• Example 5: Consider the set 𝐴 = 1,2,3,4 , then 3 ∈ 𝐴 but
5 ∉ 𝐴.
Subset: Let A and B be any two sets. A B iff x A x B
• Example 6: The set 𝐴 = 1,2,3,4 , is a subset of the set of all Natural
numbers N = 1,2,3,4,5,6, … .
A = 1,2,3,4,5,6 . B= 1,2,3,4
B is subset of A
Properties of Set
• Equal set: Two sets A and B are said to be equal set iff (AB
& B A)A=B
• Example 7: Consider the sets A={1,2,3}, B={3,1,2}, C={1,3}
and D={3}. Then
• A B, D A, C A, also B A. Therefore A = B.
• Proper subset: A is said to be a proper subset of B iff A is
subset of B but A is not equal to B, denoted as A⊂B.
• Example 8: Consider the sets A={1,2,3}, C={1,3}. Then
• 𝐶 ⊆ 𝐴 , 𝐶 ≠ 𝐴. Therefore C is a proper subset of A denoted
as 𝐶 ⊂ 𝐴 .
Properties of Set
• Universal set: The set which contains all the objects under
investigation in any application of set theory is called the
Universal set represented as E,U or X
A ={1,2,3,4,5,6,7,8,9}
B = {2,3,4} C = {1,3,9} D = {3,4,6,7}
A is the universal Set
Empty or Null set: The set which contains no element is called the
empty set represented as ∅ 𝑜𝑟 { } A = {} or ∅
• Example 9: The set 𝑥: 𝑥 ∈ 𝑁, 𝑥 2 = −1 has no elements.
• Power set: Consider a set 𝐴, then the set of all the subsets of A is
known as the power set of A, represented as P(A).
Examples
• A 3 elements =8
Index set or Index
• Sometimes the elements of a set are used to label the elements of another set
such sets are called the index set.
• Let 𝐴𝑖 be a non-empty set for each 𝑖 ∈ 𝐼. Here the sets 𝐴1 , 𝐴2 ,…,𝐴𝑛 are called
indexed set and the set 𝐼 is called the index set and 𝑖 ∈ 𝐼 of 𝐴𝑖 is called an index.
Also the family of sets 𝐴𝑖 𝑖∈𝐼 is called the indexed family of sets.
• 𝐼 = 1,2,3,4 , A = 𝐴1 , 𝐴2 , 𝐴3 , 𝐴4
Operations on sets
• Intersection of sets: The intersection of two sets A and B is
the set of all the elements which are common in both the
sets. Mathematically, 𝐴 ∩ 𝐵 = 𝑥: 𝑥 ∈ 𝐴 𝑎𝑛𝑑 𝑥 ∈ 𝐵 .
• Union of sets: The union of two sets A and B is the set of all
the elements which are either in A or in B. Mathematically,
𝐴 ∪ 𝐵 = 𝑥: 𝑥 ∈ 𝐴 𝑜𝑟 𝑥 ∈ 𝐵 .
• Example 11:Consider the sets A={1,2,3,4}, B={3,4,5,6}. Then
𝐴 ∩ 𝐵 = 3,4 , and 𝐴 ∪ 𝐵 = 1,2,3,4,5,6 .
Operations on sets
• Disjoint sets: Two sets A and B are said to be disjoint iff
they have no elements in common, i.e., 𝐴 ∩ 𝐵 = ∅.
• Example 14: Consider the sets A={1,2,3,5}, B={3,4,5,6}. Then 𝐴 − 𝐵 = 1,2 and
𝐵 − 𝐴 = 4,6 .
Hence A⨁𝐵 = 𝐴 − 𝐵 ∪ 𝐵 − 𝐴 = {1,2,4,6}.
Venn Diagram
A Venn diagram is a pictorial representation of sets in which sets
are represented by enclosed areas in the plane. The universal set
U is represented by the interior of a rectangle, and the other sets
are represented by disks lying within the rectangle.
A U U
B A B
U
B
B U
A A
Properties
Let A, B and C are subsets of the universal set U, then
1. 𝐴 ∪ 𝐵 = 𝐵 ∪ 𝐴 and 𝐴 ∩ 𝐵 = 𝐵 ∩ 𝐴
2. 𝐴 ∪ 𝐵 ∪ 𝐶 = 𝐴 ∪ 𝐵 ∪ 𝐶 &
(𝐴 ∩ 𝐵) ∩ 𝐶 = 𝐴 ∩ (𝐵 ∩ 𝐶(Associative)
4. A ∩ 𝐴′ = ∅ and 𝐴 ∪ 𝐴′ = 𝑈 (Complement
laws)
𝐴 ∪ 𝐴 = 𝐴 & 𝐴 ∩ 𝐴 = 𝐴 (law of tautology)
𝐴 ∪ 𝑈 = 𝑈 & 𝐴 ∩ ∅ = ∅(law of absorption)
U = { 1,2,3,4,5}
A = {1,2} 𝐴′ = 3,4,5
A u U = {1,2,3,4,5}
A ∩ 𝐴′ = {}
𝐴 ∪ 𝐴′ = {1,2,3,4,5}
𝐴 ∩ 𝑈 = {1,2} = A
Properties
𝐴 ∪ 𝐵 ∩ 𝐶 = 𝐴 ∪ 𝐵 ∩ (𝐴 ∪ 𝐶)&
𝐴 ∩ (𝐵 ∪ 𝐶) = (𝐴 ∩ 𝐵) ∪ (𝐴 ∩ 𝐶)(Distributive)
𝐼𝑓 𝐴 ∪ 𝐵 =U and 𝐴 ∩ 𝐵 = ∅, then B = A′
𝐴′ ′ = 𝐴 (law of involution)
(𝐴 ∪ 𝐵)′ = 𝐴′ ∩ 𝐵′&
(𝐴 ∩ 𝐵)′ = 𝐴′ ∪ 𝐵′ (De Morgan’s laws)
𝐴 ∪ 𝑈 = 𝑈&𝐴 ∩ ∅ = ∅(law of absorption)
𝐼𝑓 𝐴 ∪ 𝐵 =U and 𝐴 ∩ 𝐵 = ∅, then B = A′
U = {1,2,3,4,5,6}
A={1,2,3} B = {4,5,6}
𝐴′ = 4,5,6
C = {1,2,3,4,2,3,5,6}
C = {1,2,3,4,5,6}
U = {1,2,3,4,5,6,7,8,9,10}
A={1,2,3}
B={3,4,5}
Prove that (𝐀 ∪ 𝐁)′ = 𝐀′ ∩ 𝐁′
Proof: To prove this we are to prove that (A ∪ B)′ ⊆ A′ ∩
B′&A′ ∩ B′ ⊆ (A ∪ B)′.
Let x ∈ A ∪ B ′ ⇒ x ∉ A ∪ B
⇒ x ∉ A and x ∉ B
⇒ x ∈ A′ and x ∈ B′
⇒ x ∈ A′ ∩ B′
⇒ (A ∪ B)′ ⊆ A′ ∩ B′
Let x ∈ A ∩ B ′ ⇒ x ∉ A ∩ B
⇒ x ∉ Aor x ∉ B
⇒ x ∈ A′or x ∈ B′
⇒ x ∈ A′ ∪ B′
⇒ (A ∩ B)′ ⊆ A′ ∪ B′
Now, let x ∈ A′ ∪ 𝐵′ ⇒ x ∈ A′or x ∈ B′
⇒ x ∉ Aor x ∉ B
⇒x∉A∩B
⇒x∈ A∩B ′
⇒ A′ ∪ B′ ⊆ (A ∩ B)′
⇒ A ∩ B ′ = A′ ∪ B′
Cardinality of Set
A={4,5,6,7,1} |A|= 5
B=
Inclusion-Exclusion Principle
• Inclusion-Exclusion Principle: Given sets 𝐴1 , 𝐴2 , … 𝐴𝑛 , the
cardinality of the union is the sum of the individual
cardinalities, minus all the cardinalities of intersections of
two sets, plus the cardinalities of intersections of three
sets, minus the cardinalities of intersections of four sets,
etc. This alternating sum ends with plus or minus the
cardinality of the intersection of all 𝑛 sets.
• Mathematically for three sets A, B and C 𝐴 ∪ 𝐵 ∪ 𝐶 =
𝐴 + 𝐵 + 𝐶 − 𝐴∩𝐵 − 𝐴∩𝐶 − 𝐵∩𝐶 +
𝐴∩𝐵∩𝐶 .
Inclusion-Exclusion Principle
• Suppose we have two finite sets 𝐴 and 𝐵.Then what is the
cardinality of 𝐴∪𝐵?
• If we take the sum of the individual cardinalities, then we
count all the elements in the intersection twice. Therefore,
we have to subtract that cardinality to obtain the correct
answer as 𝐴 ∪ 𝐵 = 𝐴 + 𝐵 − 𝐴 ∩ 𝐵 .
• Example 18: Consider the sets A={2,4,6,7,8} and B={2,4,9}.
Then 𝐴 ∪ 𝐵 = 𝐴 + 𝐵 − 𝐴 ∩ 𝐵 =5+3-2=6. As 𝐴 ∪ 𝐵 =
2,4,6,7,8,9 .
• The generalization of this formula to an arbitrary number
of sets is called the inclusion-exclusion principle.
Principle of duality
• Let E be an equation of set algebra, then the dual of E
represented as E* is the equation obtained by replacing
each occurrence of ∪,∩, 𝑈, ∅ in E by ∩,∪, ∅, 𝑈 respectively.
• Example 19: Dual of (U ∩ 𝐴) ∪ (𝐵 ∩ 𝐴) = A is
• (∅ ∪ 𝐴) ∩ (𝐵 ∪ 𝐴) = 𝐴.
• Theorem (The Principle of Duality): Let E denote a theorem
or identity dealing with the equality of two set expressions.
Then E* is also a theorem/identity.
• Example 20: (𝐴 ∪ 𝐵)′ = 𝐴′ ∩ 𝐵′& (𝐴 ∩ 𝐵)′ = 𝐴′ ∪ 𝐵′ (De
Morgan’s laws)
Minset & Maxset
• Minset:Let {𝐵1 , 𝐵2 , … 𝐵𝑛 } be a set of subsets of a set A. Sets
of the form 𝐷1 ∩ 𝐷2 ∩ ⋯ ∩ 𝐷𝑛 , where each 𝐷𝑖 , may be
either 𝐵𝑖 or 𝐵𝑖 ′is called a minset generated by 𝐵1 , 𝐵2 , … 𝐵𝑛 .
• Maxset: Dualof minset is called maxset.
• Use the principle of duality and the definition of minset to
write the definition of maxset.
• Example 20:Let 𝑈 = −2, −1, 0, 1, 2 , 𝐵1 = 0, 1, 2 , and
𝐵2 = 0,2 . Then 𝐵1 ∩ 𝐵2 = 0,2 , 𝐵1 ′ ∩ 𝐵2 = ∅, 𝐵1 ∩
𝐵2 ′ = 1 and 𝐵1 ′ ∩ 𝐵2 ′ = −2, −1 .
Ordered Pairs & n-tuples
• Ordered pair:An ordered pair of elements is written in the form (a, b) (or <a, b>)
which is distinct from (b, a) unless a = b.
• Equality of ordered pairs:(a,b) = (c,d) iff a = c & b = d
• {1,2} = {2,1} = {1,1,2}
but (1,2) (2,1) (1,1,2)
• Ordered triple:ordered triple (a,b,c)
• n-tuple: 𝑥1 , 𝑥2 , 𝑥3 , … , 𝑥𝑛
Cartesian Products-
• Let A & B be any two sets. The set of all ordered pairs such that
the first member of the ordered pair is an element of A & second
member is an element of B is called the Cartesian product of A
and B denoted as 𝐴 × 𝐵 .
• i.e., 𝐴 × 𝐵 = {(𝑎, 𝑏): (𝑎𝐴) 𝑎𝑛𝑑 ( 𝑏𝐵)}.
• 𝐴 (𝐵 𝐶) = {(𝑎, (𝑏, 𝑐)): (𝑎 𝐴) 𝑎𝑛𝑑 (𝑏, 𝑐) 𝐵 𝐶}.
• 𝐴 𝐵 𝐵 𝐴.
• Example 21: Consider the sets 𝐴 = {𝑎, 𝑏} &𝐵 = {1,2,3} find
𝐴 × 𝐵, 𝐵 × 𝐴, and 𝐴 × 𝐴 .
• 𝐴 × 𝐵 = {(𝑎, 1), (𝑎, 2), (𝑎, 3), (𝑏, 1), (𝑏, 2), (𝑏, 3)}
• 𝐵 × 𝐴 = {(1, 𝑎), (1, 𝑏), (2, 𝑎), (2, 𝑏), (3, 𝑎), (3, 𝑏)}
• 𝐴 × 𝐴 = {(𝑎, 𝑎), (𝑎, 𝑏), (𝑏, 𝑎), (𝑏, 𝑏)}
Properties of Cartesian Product
A x A = { (x,x),(x,y), (y,x),(y,y)}
Example
X = { 1, 2} |x| = 2
Y = { a, b} |y| = 2
X x Y = {(1,a),(1,b),(2,a), (2,b)} |X x Y| = 4
Y x X = { (a, 1), (a,2), (b,1), (b,2)}
Note:
• XxYYxX
• |
• | X x Y | = |X| .|Y|
Determine:
1 1
X xX = 1,1 , 1,2 , 2,1 , (2,2) , M =
1 1
YxY =?
𝐴 = 1,2,3,4,5,6
𝑅= 𝑎, 𝑏 ∈ 𝑅: 𝑎 𝑑𝑖𝑣𝑖𝑑𝑒𝑠 𝑏
𝑅= 𝑎, 𝑏 ∈ 𝐴: 𝑎 𝑑𝑖𝑣𝑖𝑑𝑒𝑠 𝑏
R={
(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(2,2),(2,4),(2,6),(3,3),(3,6),(4,4),(5,5),(6,
6)}
Relation : Definition
Definition(Relation): For sets A,B U , any subset of A B is called
a relation from A to B. Any subset of A A is called a binary
relation on A.
{(2,4),(2,6),(3,3),(3,6),(4,4)}
Another Example:
• Let R be the relation on X = {1,2,3,4} defined by (x,y) R
if x y,
x, y X.
1 2
A Loop
3
Exercise: 4
• The Relation R on X = {a, b, c, d} is
R = {(a,a), (b,c), (c,b), (d,d)}
What would the digraph to represent this relation look
like?
Let R = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4),
(3,3), (3,4),} be a relation on A={1,2,3,4}
Let R = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4),
(3,3), (3,4),} be a relation on A={1,2,3,4}
Representing Relations using a Matrix
Let A = { a1 , a 2 ,..., a m } and B={ b1 , b2 ,..., bn }
Let R be relation from A to B. Then R is represented by
a matrix M R = [ mij ]mn where
1 if ( ai , b j ) R
mij =
0 if ( ai , b j ) R
The matrix M R is called the matrix of R.
Example : Let A = {1,2,3,4} and B = { x, y , z}
Let R = {(1, y ), ( 2, z ), (3, x ), (3, y ), ( 4, x ), ( 4, z )} be a relation from A to B.
Then M R is given by
0 1 0
x y z 0 0 1
1
MR = .
0 1 0 1 1 0
2 0 0 1
1 1
3 1 1 0 0
4 1 0 1
Types of Relations:
• Reflexive and Irreflexive
• Symmetric
• Antisymmetric
• Transitive
Reflexive and Irreflexive
• A relation R on a set A is called reflexive
if (a, a) R for every a A
e.g.
R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4),(4,4)}
is Reflexive. [ A = {1,2,3,4} ] while
R*={(1,1),(1,2),(1,3),(1,4),(2,3),(2,4),(3,3),(3,4)}
is not a reflexive relation on A.
• A relation R on a set A is called irreflexive if
(a,a) does not belong to R for any a A.
R’={(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)} is irreflexive relation on A.
Symmetric and Anti-symmetric
• A relation R on a set A, is called symmetric if whenever (a,b) R,
then (b,a) R
Example:
R2 = {(a,a), (b,c), (c,b), (d,d)} is symmetric.
Is R2 also Reflexive?
• A relation R on a set A is called anitsymmetric if
whenever (a, b) and (b, a) R then a=b.
Antisymmetric (continued)
• Is R2 = {(a, a), (b, c), (c, b), (d, d)} is antisymmetric?
No. Both (b,c) and (c,b) are in R.
• If a relation R on X has no members of the form (x, y) with xy, then R
is antisymmetric. WHY?
• Let R = {(a,a), (b,b), (c,c)}
then R is antisymmetric
Is R also Symmetric? Yes.
Solution: S o R = {(1,0),(1,1),(2,1),(2,2),(3,0),(3,1)}.
EXAMPLE
Find R R, R S R
Equivalence relations
• A relation on a set A is called an equivalence relation if it is
reflexive, symmetric, and transitive
Example 1:
• Consider relation R = { (a,b) | len(a) = len(b) }
on set of strings of English letters
• Where len(a) means the length of string a
• It is reflexive: len(a) = len(a)
• It is symmetric: if len(a) = len(b), then len(b) = len(a)
• It is transitive: if len(a) = len(b) and len(b) = len(c), then len(a) = len(c)
• Thus, R is a equivalence relation
Example 2: Let R be the relation on the set of real numbers such
that a R b iff a-b is an integer. Is R an equivalence relation?
(Ex!)
Examples:
• Which of these relations on {0, 1, 2, 3} are equivalence relations?
Determine the properties of an equivalence relation that the others lack
a) { (0,0), (1,1), (2,2), (3,3) }
Has all the properties, thus, is an equivalence relation
b) { (0,0), (0,2), (2,0), (2,2), (2,3), (3,2), (3,3) }
Not reflexive: (1,1) is missing
Not transitive: (0,2) and (2,3) are in the relation, but not (0,3)
c) { (0,0), (1,1), (1,2), (2,1), (2,2), (3,3) }
Has all the properties, thus, is an equivalence relation
d) { (0,0), (1,1), (1,3), (2,2), (2,3), (3,1), (3,2) (3,3) }
Not transitive: (1,3) and (3,2) are in the relation, but not (1,2)
e) { (0,0), (0,1) (0,2), (1,0), (1,1), (1,2), (2,0), (2,2), (3,3) }
Not symmetric: (1,2) is present, but not (2,1)
Not transitive: (2,0) and (0,1) are in the relation, but not (2,1)
Partial Order relation: Introduction
• An equivalence relation is a relation that is reflexive, symmetric, and transitive
Comparability
• The elements a and b of a poset (S, ) are called
comparable if either a b or b a.
– Meaning if (a,b) R or (b,a) R
– It can’t be both because is antisymmetric
• Unless a = b, of course
– If neither a b nor b a, then a and b are incomparable
• Meaning they are not related to each other
• If all elements in S are comparable, the relation is a total
ordering
Comparability examples
• Let be the less than or equals operator ≤
• In the poset (Z+,≤), are the integers 3 and 9
comparable?
– Yes, as 3 ≤ 9
• Are 7 and 5 comparable?
– Yes, as 5 ≤ 7
• As all pairs of elements in Z+ are comparable, the
poset (Z+,≤) is a total order
– Also called as totally ordered poset, linearly ordered set,
chain, etc.
Equalities between Relations
.
Definition: Function
• Definition: A function f from a set A to a set B is an assignment of exactly one
element of B to each element of A.
• We write f(a)=b if b is the unique element of B assigned by the function f to the
element a A.
• If f is a function from A to B, we write
f: A → B
This can be read as ‘f maps A to B’
• Note the subtlety
• Each and every element of A has a single mapping
• Each element of B may be mapped to by several elements in A or not at all
Terminology
• Let f: A → B and f(a)=b. Then we use the following terminology:
• A is the domain of f, denoted dom(f)
• B is the co-domain of f
• b is the image of a
• a is the preimage (antecedent) of b
• The range of f is the set of all images of elements of A, denoted rng(f)
Function: Visualization
Range
Preimage Image, f(a)=b
f
a b
A B
Domain Co-Domain
A function, f: A → B
More Definitions (1)
• Definition: Let f1 and f2 be two functions from a set A to R. Then f1+f2
and f1f2 are also function from A to R defined by:
• (f1+f2)(x) = f1(x) + f2(x)
• f1f2(x)= f1(x)f2(x)
• Example: Let f1(x)=x4+2x2+1 and f2(x)=2-x2
• (f1+f2)(x) = x4+2x2+1+2-x2 = x4+x2+3
• f1f2(x) = (x4+2x2+1)(2-x2)= -x6+3x2+2
Image of a set: Example
• Let:
• A = {a1,a2,a3,a4,a5}
• B = {b1,b2,b3,b4,b5}
• f={(a1,b2), (a2,b3), (a3,b3), (a4,b1), (a5,b4)}
• S={a1,a3}
• Draw a diagram for f
• What is the:
• Domain, co-domain, range of f?
• Image of S, f(S)?
More Definitions (3)
• Definition: A function f whose domain and co-domain are subsets of
the set of real numbers (R) is called
• strictly increasing if f(x)<f(y) whenever x<y and x and y are in the domain of f.
• strictly decreasing if f(x)>f(y) whenever x>y and x and y are in the domain of f.
• A function that is increasing or decreasing is said to be monotonic
Outline
• Definitions & terminology
• Properties
– One-to-one (injective)
– Onto (surjective)
– One-to-one correspondence (bijective)
– Exercices (5)
• Inverse functions (examples)
• Operators
• Important functions
Definition: Injection
• Definition: A function f is said to be one-to-one or injective (or an
injection) if
x and y in in the domain of f, f(x)=f(y) x=y
• Intuitively, an injection simply means that each element in the range
has at most one preimage (antecedent)
• It is useful to think of the contrapositive of this definition
x y f(x) f(y)
Definition: Surjection
• Definition: A function f: A→B is called onto or surjective (or an
surjection) if
bB, aA with f(a)=b
• Intuitively, a surjection means that every element in the codomain is
mapped into (i.e., it is an image, has an antecedent)
• Thus, the range is the same as the codomain
Definition: Bijection
• Definition: A function f is a one-to-one correspondence (or a
bijection), if is both one-to-one (injective) and onto (surjective)
• One-to-one correspondences are important because they endow a
function with an inverse.
• They also allow us to have a concept cardinality for infinite sets
• Let’s look at a few examples to develop a feel for these definitions…
Functions: Example 1
A B
a1 b1
a2 b2
a3 b3
a4 b4
A B
a1 b1
a2 b2
a3 b3
a4 b4
• Is this a function
• One-to-one (injective)? Why?
No, b1 has 2 preimages
• Onto (surjective)? Why?
No, b4 has no preimage
Functions: Example 3
A B
a1 b1
a2 b2
a3 b3
b4
• Is this a function
• One-to-one (injective)? Why?
Yes, no bi has 2 preimages
• Onto (surjective)? Why?
No, b4 has no preimage
Functions: Example 4
A B
a1 b1
a2 b2
a3 b3
a4 b4
• Is this a function
• One-to-one (injective)?
Thus, it is a bijection or a
• Onto (surjective)?
one-to-one correspondence
Exercice 1
• Let f:Z→Z be defined by
f(x)=2x-3
• What is the domain, codomain, range of f?
• Is f one-to-one (injective)?
• Is f onto (surjective)?
• Clearly, dom(f)=Z. To see what the range is, note that:
b rng(f) b=2a-3, with aZ
b=2(a-2)+1
Exercise 1 (cont’d)
• Thus, the range is the set of all odd integers
• Since the range and the codomain are different (i.e., rng(f) Z), we
can conclude that f is not onto (surjective)
• However, f is one-to-one injective. Using simple algebra, we have:
f(x1) = f(x2) 2x1-3 = 2x2-3 x1= x2 QED
Exercise 2
• Let f be as before
f(x)=2x-3
but now we define f:N →N
• What is the domain and range of f?
• Is f onto (surjective)?
• Is f one-to-one (injective)?
• By changing the domain and codomain of f, f is not
even a function anymore. Indeed, f(1)=21-3=-1N
Exercice 3
• Let f:Z→Z be defined by
f(x) = x2 - 5x + 5
• Is this function
• One-to-one?
• Onto?
Exercice 3: Answer
• It is not one-to-one (injective)
f(x1)=f(x2) x12-5x1+5=x22 - 5x2+5 x12 - 5x1 = x22 - 5x2
x12 - x22 = 5x1 - 5x2 (x1 - x2)(x1 + x2) = 5(x1 - x2)
(x1 + x2) = 5
Many x1,x2 Z satisfy this equality. There are thus an infinite number of solutions. In
particular, f(2)=f(3)=-1
• It is also not onto (surjective).
The function is a parabola with a global minimum at (5/2,-5/4). Therefore, the function fails to map to any
integer less than -1
• What would happen if we changed the domain/codomain?
Exercise 4
• Let f:Z→Z be defined by
f(x) = 3x3 – x
• Is this function
• One-to-one (injective)?
• Onto (surjective)?
f is one-to-one
• To check if f is one-to-one, again we suppose that for x1,x2 Z we
have f(x1)=f(x2)
f(x1)=f(x2) 3x13-x1=3x23-x2
3x13 - 3x23 = x1 - x2
3 (x1 - x2)(x12 +x1x2+x22)= (x1 - x2)
(x12 +x1x2+x22)= 1/3
which is impossible because x1,x2 Z
thus, f is one-to-one
f is not onto
• Consider the counter example f(a)=1
• If this were true, we would have
3a3 – a=1 a(3a2 – 1)=1 where a and (3a2 – 1) Z
• The only time we can have the product of two integers equal to 1 is
when they are both equal to 1 or -1
• Neither 1 nor -1 satisfy the above equality
• Thus, we have identified 1Z that does not have an antecedent and f is not
onto (surjective)
Outline
• Definitions & terminology
– function, domain, co-domain, image, preimage (antecedent), range,
image of a set, strictly increasing, strictly decreasing, monotonic
• Properties
– One-to-one (injective), onto (surjective), one-to-one correspondence
(bijective)
– Exercices (5)
• Inverse functions (examples)
• Operators
– Composition, Equality
• Important functions
– identity, absolute value, floor, ceiling, factorial
Inverse Functions (1)
• Definition: Let f: A→B be a bijection. The inverse function of f is the
function that assigns to an element bB the unique element aA
such that f(a)=b
• The inverse function is denote f-1.
• When f is a bijection, its inverse exists and
f(a)=b f-1(b)=a
Inverse Functions (2)
• Note that by definition, a function can have an inverse if and only if it
is a bijection. Thus, we say that a bijection is invertible
• Why must a function be bijective to have an inverse?
• Consider the case where f is not one-to-one (not injective). This means that
some element bB has more than one antecedent in A, say a1 and a2. How
can we define an inverse? Does f-1(b)=a1 or a2?
• Consider the case where f is not onto (not surjective). This means that there
is some element bB that does not have any preimage aA. What is then f-
1(b)?
Inverse Functions: Representation
f(a)
a b
f -1(b)
A B
Domain Co-Domain
A function and its inverse
Inverse Functions: Example 1
• Let f:R→R be defined by
f(x) = 2x – 3
• What is f-1?
1. We must verify that f is invertible, that is, is a bijection. We prove that is
one-to-one (injective) and onto (surjective). It is.
2. To find the inverse, we use the substitution
• Let f-1(y)=x
• And y=2x-3, which we solve for x. Clearly, x= (y+3)/2
• So, f-1(y)= (y+3)/2
Inverse Functions: Example 2
• Let f(x)=2x
• What should the domain/codomain be for this function to be a bijection?
• What is the inverse?
• The function should be f:R→R+
• Let f-1(y)=x and y=2x, solving for x we get x=log2(y). Thus, f-1(y)=log2(y)
• What happens when we include 0 in the codomain?
• What happens when restrict either sets to Z?
• If f x = 3x − 5, then f −1 x is
Function Composition (1)
• The value of functions can be used as the input to other functions
• Definition: Let g:A→B and f:B →C. The composition of the functions
f and g is
(f g) (x)=f(g(x))
• fg is read as ‘f circle g’, or ‘f composed with g’, ‘f following g’, or just ‘f
of g
Function Composition (2)
• Because (f g)(x)=f(g(x)), the composition f g cannot be defined
unless the range of g is a subset of the domain of f
f g is defined rng(g) dom(f)
• The order in which you apply a function matters: you go from the
inner most to the outer most
• It follows that f g is in general not the same as g f
Composition: Graphical Representation
(f g)(a)
g(a) f(g(a))
a g(a) f(g(a))
A B C
Answer: b)362880
Answer: d)180
Answer: c) 720
Review
5C =10
2
The order of outcomes is important, so this situation
involves permutations.
26 x 6 x 10 x 10 =15600
The order of outcomes is important, so this situation
involves permutations.
3x2x1=6
The order of outcomes is important, so this situation
involves permutations.
3x2x1=6
The order of outcomes is not important, so this
situation involves combinations.
4C =6
2
The order of outcomes is important, so this situation
involves permutations.
8 x 7 x 6 = 336
The order of outcomes is not important, so this
situation involves combinations.
15𝐶4 = 1365
The order of outcomes is not important, so this
situation involves combinations.
13𝐶4 = 715
The order of outcomes is not important, so this
situation involves combinations.
12C = 792
5
The order of outcomes is not important, so this
situation involves combinations.
11C = 330
4
The order of outcomes is important, so this situation
involves permutations.
12𝑃4 = 11,880
Pigeon Hole Principle
Example
Pigeonhole Principle
102
So, if a million students take a national test with say 100 questions,
many must have the same score (in expectation 10,000). So, would need
at least a million questions to get a chance of a unique score for
everyone.
Generalized Pigeonhole Principle
36
G.P.P. Example
• Given: There are 280 people in the party. Without knowing anybody’s
birthday, what is the largest value of n for which we can prove that at
least n people must have been born in the same month?
• Answer:
280/12 = 23.3 = 24
38
Thank
you
Discrete Structure/AM103 Mr Pankaj 1
Discrete Structure/AM103 Mr Pankaj 2
Definition of Recurrence Relation
Solution:
Step 1: Characteristic equation: an = rn → rn = rn-1 + 2rn-2
→
r2 = r +2
Characteristic equation:
r2 − r − 2 = 0
Step 2: Roots are: r = 2 or r = −1.
Solution:
Step 1: Characteristic equation: an = rn → rn = rn-1 + 2rn-2
→
r2 = r +2
Characteristic equation:
r2 − r − 2 = 0
Step 2: Roots are: r = 2 or r = −1.
f(x) = n = = + + + + ..................
nn 2 3
a x 1 * x 1 x x x
n =0 n =0
1
= (binomial generating function)
1− x
xn xn
g ( x) = a n = 1 *
n =0 n! n =0 n!
x2 x3
= 1+ x + + + ..........
2! 3!
= ex (exponential generating function)
Discrete Structure/AM103 Mr Pankaj 5
Discrete Structure/AM103 Mr Pankaj 6
Find the generating function for the sequence
1,0,1,0,1,...............
f ( x) = 1 /(1 + 3 x)
= (1 + 3 x) −1 = 1 − (3 x) + (3 x) 2 − (3 x) 3 + (3 x) 4 − ..........
0 for 0 r 2 3 − 2 r for 0 r 1
ar = − r and br =
2 + 5 for r 3 r + 2 for r 2
3 − 2 r for 0 r 1
cr = ar + br = 4 for r = 2
2 − r + r + 7 for r 3
0 for 0 r 2
cr = ar * br = − r
r 2 + 2 − r +1
+ 5r + 10 for r 3
( )
= a n x + a0 x = 3n 2n − an −1 x n
n
n =1 n =1
= 3n 2 x − an −1 x n
n n
n =1 n =1
(
= 3 2 x + 2 ( 2 x ) + 3 ( 2 x ) + .. − xf
2 3
) ( x)
Discrete Structure/AM103 Mr Pankaj 22
Example2
(1 + x ) f ( x ) = 6 x (1 − 2 x )
2
f ( x ) = 6 x (1 − 2 x ) (1 + x )
2
2 4 2
= − −
(1 − 2 x ) 2 3 (1 − 2 x ) 3 (1 + x )
Discrete Structure/AM103 Mr Pankaj 26
As f(x)=anxn, so an= coeff. of xn in f(x)
2 4 2
= coeff x n
− −
(1 − 2 x )
2
3(1 − 2 x ) 3(1 + x )
2n 2
= (n + 1)2 n +1
− 4 − (− 1)n
3 3
1 n +1 2
= n + 2 − (− 1)
n
3 3
Discrete Structure/AM103 Mr Pankaj 27
Discrete Structure/AM103 Mr Pankaj 28
Discrete Structure/AM103 Mr Pankaj 29
Discrete Structure/AM103 Mr Pankaj 30
Logics
1
• A proposition(statement) is a declarative
sentence (a sentence that declares a fact) that is
either true or false, but not both.
• Are the following sentences propositions?
(Yes)
– Toronto is the capital of Canada.
– Read this carefully. (No)
– 1+2=3 (Yes)
(No)
– x+1=2
– What time is it? (No)
2
3
Propositional Logic
• Propositional Logic – the area of logic that
deals with propositions
• Propositional Variables – variables that
represent propositions: p, q, r, s
– E.g. Proposition p – “Today is Friday.”
• Truth values – T, F
4
Logical Operators
Logical operators are used to form new propositions
from two or more existing propositions. The logical
operators are also called connectives.
• Negation
• Conjunction
• Disjunction
• Exclusive OR
• Conditional statement
• Biconditional statement
5
Negation(¬)
Let p be a proposition. The negation of p, denoted by ¬p, is the statement
“It is not the case that p.”
The proposition ¬p is read “not p.” The truth value of the negation of p, ¬p
is the opposite of the truth value of p.
• Examples
– Find the negation of the proposition “Today is Friday.” and express this
in simple English.
Solution: The negation is “It is not the case that today is Friday.”
In simple English, “Today is not Friday.” or “It is not
Friday today.”
– Find the negation of the proposition “At least 10 inches of rain fell
today in Miami.” and express this in simple English.
Solution: The negation is “It is not the case that at least 10 inches
of rain fell today in Miami.”
In simple English, “Less than 10 inches of rain fell today 6
in Miami.”
Truth Table
7
Conjunction(Λ)
Let p and q be propositions. The conjunction of p and q, denoted by p
Λ q, is the proposition “p and q”. The conjunction p Λ q is true when
both p and q are true and is false otherwise.
• Examples
– Find the conjunction of the propositions p and q where p is the
proposition “Today is Friday.” and q is the proposition “It is raining
today.”, and the truth value of the conjunction.
Solution: The conjunction is the proposition “Today is Friday and it
is raining today.” The proposition is true on rainy Fridays.
8
Truth table of conjunction
9
Disjunction(ν)
Let p and q be propositions. The disjunction of p and q, denoted by p ν
q, is the proposition “p or q”. The conjunction p ν q is false when both
p and q are false and is true otherwise.
10
Truth Table
11
Exclusive or( )
Let p and q be propositions. The exclusive or of p and q, denoted by p q,
is the proposition that is true when exactly one of p and q is true and is
false otherwise.
The Truth Table for The Truth Table for The Truth Table for the
the Conjunction of the Disjunction of Exclusive Or (XOR) of
Two Propositions. Two Propositions. Two Propositions.
p q pΛq p q pνq p q p q
T T T T T T T T F
T F F T F T T F T
F T F F T T F T T
F F F F F F F F F
12
13
Conditional Statements
Let p and q be propositions. The conditional statement p → q, is the
proposition “if p, then q.” The conditional statement is false when p is
true and q is false, and true otherwise. In the conditional statement p
→ q, p is called the hypothesis (or antecedent or premise) and q is
called the conclusion (or consequence).
14
Example
15
Other conditional statements:
– Converse of p → q : q → p
– Contrapositive of p → q : ¬ q → ¬ p
– Inverse of p → q : ¬ p → ¬ q
16
Example
17
Biconditional Statement
Let p and q be propositions. The biconditional statement p ↔ q is the
proposition “p if and only if q.” The biconditional statement p ↔ q is
true when p and q have the same truth values, and is false otherwise.
Biconditional statements are also called bi-implications.
19
Compound Statement
Compound statement is a statement built
out of simple statements using logical.
20
Truth Tables of Compound Propositions
T T F T T T
T F T T F F
F T F F F T
F F T T F F
21
Precedence of Logical Operators
• We can use parentheses to specify the order in which logical operators in
a compound proposition are to be applied.
• To reduce the number of parentheses, the precedence order is defined
for logical operators.
22
English and Logic
23
Translating English Sentences
Solution: Let p, q, and r represent “You can ride the roller coaster,”
“You are under 4 feet tall,” and “You are older than
16 years old.” The sentence can be translated into:
(q Λ ¬ r) → ¬p.
24
• Example: How can this English sentence be translated into a logical
expression?
“You can access the Internet from campus only if you are a
computer science major or you are not a freshman.”
Solution: Let p, q, and r represent “You can access the Internet from
campus,” “You are a computer science major,” and “You are
a freshman.” The sentence can be translated into:
p → (q ν ¬r).
25
Logic and Bit Operations
38
Logical Equivalences
The compound propositions p and q are called logically equivalent if p ↔
q is a tautology. The notation p ≡ q denotes that p and q are logically
equivalent.
• Compound propositions that have the same truth values in all possible
cases are called logically equivalent.
• Logically equivalent can proved by truth table or by laws of logics
• Example: Show that ¬p ν q and p → q are logically equivalent.
Truth Tables for ¬p ν q and p → q .
p q ¬p ¬p ν q p→q
T T F T T
T F F F F
F T T T T
F F T T T 39
Exercise
Note
• In general, 2n rows are required if a compound proposition involves n
propositional variables in order to get the combination of all truth values.
41
Constructing New Logical Equivalences
43
Universal Quantifiers
44
Existential Quantifiers
45
Negation of Predicates
46
Argument
48
Example
49
Example
50
51
52
Example: Test the validity of:
If my brother stands first in class, I will give him a watch . Either he
stood first or I was out of station .I did not give him a watch this time.
Therefore I was out of station .
53
Rewrite the following argument symbolically and determine the validity
of it.
If john graduates ,he gets the job. John does not get the job. Therefore
John doesn't graduate
54
55
Lattice
Discrete Structure/AM103 1
Partial Orderings
Discrete Structure/AM103 2
Partially Ordered Set (POSET)
Discrete Structure/AM103 3
Example (1)
2
3
Discrete Structure/AM103 4
Comparable / Incomparable
Discrete Structure/AM103 5
Example
Discrete Structure/AM103 6
• In the poset (Z+,≤), are the integers 3 and 9 comparable?
– Yes, as 3 ≤ 9
• Are 7 and 5 comparable?
– Yes, as 5 ≤ 7
• As all pairs of elements in Z+ are comparable, the poset (Z+,≤) is a total
order
– a.k.a. totally ordered poset, linear order, or chain
Discrete Structure/AM103 7
• In the poset (Z+,|) with “divides” operator |, are the integers 3 and 9
comparable?
– Yes, as 3 | 9
• Are 7 and 5 comparable?
– No, as 7 | 5 and 5 | 7
Discrete Structure/AM103 8
Totally Ordered, Chains
Discrete Structure/AM103 9
Discrete Structure/AM103 10
Hasse Diagrams
Discrete Structure/AM103 11
Hasse Diagram
Discrete Structure/AM103 12
For the poset ({1,2,3,4,6,8,12}, |)
Discrete Structure/AM103 13
Discrete Structure/AM103 14
Maximal and Minimal Elements
Discrete Structure/AM103 15
Discrete Structure/AM103 16
Discrete Structure/AM103 17
Discrete Structure/AM103 18
Discrete Structure/AM103 19
Greatest Element
Least Element
Discrete Structure/AM103 20
Upper bound, Lower bound
Discrete Structure/AM103 21
Upper Bound of:
ub{2,6}={6,12}
ub{4,8}={8}
ub{2,6}= {6,12}
Ub{3,4}={12}
Ub{8,12}= no upper bound
Ub{2,3,6}={6,12}
Ub{1,2,4}={4,8,12}
Lower Bounds:
lb{2,6}={1,2}
lb{4,8}={1,2,4}
lb{3,4}={1}
lb{8,12}= {4,2,1}
lb{2,3,6}={1}
lb{1,2,4}={1,2}
Discrete Structure/AM103 22
Least Upper Bound,
Greatest Lower Bound
Discrete Structure/AM103 23
Upper Bound and least upper bound of:
ub{2,6}={6,12} lub{2,6}={6}
ub{4,8}={8} lub{4,8}={8}
ub{2,6}= {6,12}
Ub{3,4}={12}
Ub{8,12}= no upper bound
Ub{2,3,6}={6,12} lub{2,3,6}={6}
Ub{1,2,4}={4,8,12} lub{1,2,4}={4}
lb{2,6}={1,2} glb{2,6}={2}
lb{4,8}={1,2,4} glb{4,8}={4}
lb{3,4}={1} glb{3,4}={1}
lb{8,12}= {4,2,1} glb{8,12}={4}
lb{2,3,6}={1} glb{2,3,6}={1}
lb{1,2,4}={1,2}
Discrete Structure/AM103 24
Discrete Structure/AM103 25
Discrete Structure/AM103 26
Lattices
Discrete Structure/AM103 27
Examples 21 and 22, p. 575 in Rosen.
Discrete Structure/AM103 28
Z+={1,2,3…………..}
Discrete Structure/AM103 29
Discrete Structure/AM103 30
Discrete Structure/AM103 31
Discrete Structure/AM103 32
Discrete Structure/AM103 33
Discrete Structure/AM103 34
Discrete Structure/AM103 35
Discrete Structure/AM103 36
Discrete Structure/AM103 37
Discrete Structure/AM103 38
Discrete Structure/AM103 39
Discrete Structure/AM103 40
Discrete Structure/AM103 41
Discrete Structure/AM103 42
D20=(D20,/)=divisors of 20={1,2,4,5,10,20}
Discrete Structure/AM103 43
Discrete Structure/AM103 44
Discrete Structure/AM103 45
Discrete Structure/AM103 46
Discrete Structure/AM103 47
D30={1,2,3,5,6,10,15,30}
Discrete Structure/AM103 48
Discrete Structure/AM103 49
Discrete Structure/AM103 50
Discrete Structure/AM103 51
Discrete Structure/AM103 52
Discrete Structure/AM103 53
Discrete Structure/AM103 54
Discrete Structure/AM103 55
Discrete Structure/AM103 56
Discrete Structure/AM103 57
Discrete Structure/AM103 58
Discrete Structure/AM103 59
Discrete Structure/AM103 60
Boolean Algebra
Boolean Algebra/Lattice
✓Introduction
✓Definition of Graphs
✓Types of Graphs
✓Order & Size of Graphs
✓Degree of Vertex
✓Source & Sink
Definition of Graphs
V = {A, B, C, D, E, F}
E = {(A, B), (A, C), (A, F), (B, C), (C, D),
(C, E), (D, E), (F, E)}
Adjacent Vertices
Directed Graphs
A graph in which
every edge is
directed is called
directed graph or
digraph.
Undirected Graphs
A graph in which
every edge is
undirected is called
undirected graph.
TYPES OF GRAPHS (ctd…)
Mixed Graphs
A mixed graph
in which both
directed and
undirected
edges may exist.
TYPES OF GRAPHS (ctd…)
Self Loops
Order = 4 Size = 3
deg(a) = 2
deg(b) = 2
deg(c) = 3
deg(d) = 1
A vertex A vertex V
V with with zero
zero outdegree
indegree is called
is called sink
source
Some RESULTS
RESULT 1
deg v = 2|E|
RESULT 2
RESULT 3
RESULT 4
Degree sequence of a
graph is the list of degree
of all the vertices of the
graph. Usually we list the
degrees in non increasing
order, that is from largest
degree to smallest
degree.
Outline of Presentation
✓Walk
✓Trail
✓Path
✓Cycle
✓Distance
✓Eccentricity
✓Diameter
WALK
1 – 2 – 4 – 5 – 3 is a walk from
1 to 3
1 – 2 – 3 -– 4 – 5 – 3 is a walk
from 1 to 3
1 – 2 – 3 – 1 – 2 – 4 – 5 – 3 is a walk
from 1 to 3
1 – 2 – 3 – 4 – 5 – 3 is a trail from
1 to 3.
1 – 2 – 3 – 4 – 5 – 3 – 1 is a closed
trail.
PATH
1 – 2 – 3 – 4 – 5 is a path
from 1 to 5.
1 – 2 – 4 – 5 – 3 is a path
from 1 to 3.
CIRCUIT
1 – 2 – 3 – 4 – 5 – 3 – 1 is a
circuit.
1 – 3 – 5 – 4 – 3 – 2 – 1 is a
circuit.
CYCLE
1 – 2 – 4 – 5 – 3 – 1 is a
cycle.
1 – 3 – 5 – 4 – 2 – 1 is
a cycle.
DISTANCE
Distance
between two
vertices in a
graph is the
number of
edges in a
shortest path
connecting
them.
ECCENTRICITY
Way to solve :
Find eccentricity of all vertices and then find
maximum of all.
Regular graph
• If each vertex of a graph G has the same degree as every
other vertex.
13
Complete graph
• A simple graph in which there is exactly one edge between
each pair of distinct vertices is called a complete graph. In a
complete graph, every pair of vertices are adjacent.
15
Planar Graphs
A graph is said to be planar if it can be drawn in a plane
such that no two edges cross each other.
Non-Planar Graphs
A graph is said to be non-planar if it can be drawn in a
plane such that two edges cross each other.
16
Maps
A particular planar representation of a finite planar
multigraph is called a Map.
Region
The map so drawn divides the plane into various areas
bounded by edges which cannot be further subdivided.
17
i) Infinite Region
If the area of the region is infinite, then that region is
called infinite region.
3V – E ≥ 6.
21
Question:
Is the complete graph K4 planar ?
Solution:
22
The complete graph K4
contains 4 vertices and 6
edges.
hence 3 * 4 – 6 = 6, which
satisfies the property of
planar graphs.
Therefore, K4 is a planar
graph.
• V - E + R = 2 (Euler’s Formula)
Pseudo-graph
• The graphs in which loops and parallel edges are allowed.
26
Weighted graph
• The graph in which weights are assigned to each
edge.
27
Traversable graphs
• A graph is traversable if you can draw a path between all
the vertices without retracing the same path.
28
EULER’S FORMULA
A formula which is used to check the planarity of the given graph is called Euler’s formula.
The general formula is :
|V|-|E|+ |R| = 2
Where, V is the number of vertices in the graph.
E is the number of edges in the graph.
R is the regions in the graph.
A formula which is used to check the planarity of the given graph is called Euler’s formula.
The general formula is :
|V|-|E|+ |R| = 2
Where, V is the number of vertices in the graph.
E is the number of edges in the graph.
R is the regions in the graph.
• Problem Statement
A traveler needs to visit all the cities from a list, where distances between all the cities are known
and each city should be citvisited just once. What is the shortest possible route that he visits each city
exactly once and returns to the origin y?
A salesman visits number of cities during his trips. We denote the cities by vertices and the roads between
the cities by edges. We obtained a connected graph, then assign a real number w(e1),with every edge
e1,called the weight of the edge(distance between the cities).Then we get a weighted graph. There are
numerous Hamiltonian circuits corresponding to this graph. For instance, if there are “n” cities, then there
1
will be (n − 1)! Hamiltonian circuits. However, the salesman problem is to determine that
2
Hamiltonian circuits that has least sum of distance(weight)
ALGORITHM:
2. Then select one vertex say u2 from the n − 1 vertices not selected so far, which is nearest to
u1 . Denote the walk (u1 u2 u1 ) by w2
3.Again select one vertex say u3 from among the n − 2 vertices not selected so far which is nearest to
walk w2 = (u1 u2 u1 ) . Denote the walk (u1 u2 u3 u1 ) by w3
Continuing the process in this manner until all the vertices are selected. Then
wn will give the Hamiltonian cicuit of G
EXAMPLE OF TRAVELLING SALESMAN PROBLEM
Clearly cycle with length 120 is shortest , so 𝑤5 = (𝑢1 𝑢2 𝑢5 𝑢3 𝑢4 𝑢1 ) is the shortest of these and hence the
solution is
𝑤𝑚𝑖𝑛. =120 as shown in fig.
Traversable Graph :A graph is traversable if you can draw a path between all the vertices
without retracing the same path.
or
Konigsberg Bridge problem
Figure (2)
Figure (1)
There are four Land masses A , B , C , D joined by seven bridges as shown in Figure ( 1).
The problem is to start from anyone of 4 land masses A , B , C , D walk across each bridge exactly once. No one could
design such a tour and Euler explained this problem.
EULER’S THEOREM (KONIGSBERG CASE)
No walking tour of KONIGSBERG can be designed so that each bridge is used exactly once.
KONIGSBERG bridge problem can be represented graphically as shown in figure:
Vertex a b c d e f
Color C1 C2 C1 C2 C1 C2
From here,
Minimum number of colors used to color the given graph are 2.
Graph 1 Therefore, Chromatic Number of the given graph = 2.
Therefore, The given graph may be properly colored using 2 colors as
shown below-
Graph 2
Graph coloring by Welsh Powell Algorithm
Algorithm
Step 1: Find the degree of all the vertices
Step 2: Order the vertices in G in decreasing order of degree.
Step 3: Use one color for the first vertex and color them in sequential order each vertex
on the list that is not adjacent to a vertex previously colored with this color.
Step 4: Start again from top of list and repeat third step using the second color.
Step 5: Repeat until all vertices are colored.
Vertex v111v2 v3 v4 v5 v6 v7
Degree 5 3 3 4 4 4 3
These are the example with 1 vertex, 2,3 vertices respectively, for trees.
Trivial Tree is a tree with only one vertex.
Properties:
1. There is only one path between a pair of vertices of a tree.
2. In a tree with more than one vertex, there are at least two vertices of degree 1.
3. In a tree with n vertices, n≥ 1 ℎ𝑎𝑣𝑒 "𝑛 − 1“ edges.
BINARY TREES
Here, degree of root i.e ‘r’ and node ‘d’ are three while others have
‘0’ to ‘3’ .
Rooted Tree:
• It is a connected graph without any cycle, having a vertex ‘r’ called root of the tree, denoted by
T.
• There is a unique path from root r , to each vertex v in T ,which determines the direction to
each edge. Thus, we can say it is a graph.
• The length (number of edges) of the path from root to vertex is called the level or depth of that
vertex.
Parent of (e) = a
Children of (g) = j , k
Siblings of (j) = k
Parent of (c) =
Children of (g) =
Siblings of (h) =
Leaves are
Q. Find parent of c, children of g, siblings of h, all leaves of the
given graph.
Parent of (c) = b
Children of (g) = h , i , j
Siblings of (h) = i , j
Leaves are d , e , f , k , i , l , m
Tree Terminology
Spanning Tree:
A sub-graph T of a connected graph G whose all the vertices are connected by using selected edges
to make a tree T
Example:
Q. Draw all spanning trees of the graph.
Solution:
(ii)
(i)
(iii) (iv)
Thank
you
TREE
• Preorder Traversal: The preorder traversal of a binary tree is a recursive process. The
preorder traversal of a tree is
Answer: b
Explanation: In a preorder traversal of a binary tree first is to visit the root, second
traverse the left subtree of the tree and third traverse the right subtree of the tree.
Q. Write preorder , inorder , postorder of following tree:
Solution:
Preorder: Root-Left subtree-Right subtree
Inorder
Solution:
Inorder: Left subtree-Root-Right subtree
Post Order:
.
Post Order:
.Q. Write preorder , inorder , postorder of following tree:
(ii) In order : d b e a f c g
Solution:
AB
Preorder : A B C D E F G H J K I
Inorder: Left subtree-Root-Right subtree
Q. Construct the binary tree whose inorder and preorder traversal are:
Inorder: E A C I F H D B G
Preorder: F A E I C D H G B Preorder: Root-Left subtree-Right subtree
Solution: Inorder: Left subtree-Root-Right subtree
Q. Construct the binary tree whose inorder and preorder traversal are:
Inorder: E A C I F H D B G
Preorder: F A E I C D H G B
Solution:
Inorder: E A C I F H D B G Inorder: Left subtree-Root-Right subtree
Preorder: F A E I C D H G B Preorder: Root-Left subtree-Right subtree
Solution:
.
Q. Construct tree from following traversals:
Inorder: DCEBFAHGI
Postorder: D E C F B H I G A
Inorder: Left subtree-Root-Right subtree
Inorder: D C E B F A H G I Postorder:Left subtree-Right subtree-Root
Postorder: D E C F B H I G A
Last letter of Postorder is A i.e root of the tree is ‘A’.