Discrete Structures
Discrete Structures
Quantifiers
The variable of predicates is quantified by quantifiers. There are two types of
quantifier in predicate logic − Universal Quantifier and Existential Quantifier.
Universal Quantifier
Universal quantifier states that the statements within its scope are true for every
value of the specific variable. It is denoted by the symbol ∀∀.
∀xP(x)∀xP(x) is read as for every value of x, P(x) is true.
Example − "Man is mortal" can be transformed into the propositional
form ∀xP(x)∀xP(x) where P(x) is the predicate which denotes x is mortal and the
universe of discourse is all men.
Existential Quantifier
Existential quantifier states that the statements within its scope are true for some
values of the specific variable. It is denoted by the symbol ∃∃.
∃xP(x)∃xP(x) is read as for some values of x, P(x) is true.
Example − "Some people are dishonest" can be transformed into the propositional
form ∃xP(x)∃xP(x) where P(x) is the predicate which denotes x is dishonest and the
universe of discourse is some people.
Nested Quantifiers
If we use a quantifier that appears within the scope of another quantifier, it is called
nested quantifier.
Example
∀ a∃bP(x,y)∀ a∃bP(x,y) where P(a,b)P(a,b) denotes a+b=0a+b=0
∀ a∀b∀cP(a,b,c)∀ a∀b∀cP(a,b,c) where P(a,b)P(a,b) denotes a+
(b+c)=(a+b)+ca+(b+c)=(a+b)+c
Note − ∀a∃bP(x,y)≠∃a∀bP(x,y)
Connectives
In propositional logic generally we use five connectives which are −
OR (∨∨)
AND (∧∧)
Negation/ NOT (¬¬)
Implication / if-then (→→)
If and only if (⇔⇔).
OR (∨∨) − The OR operation of two propositions A and B (written as A∨BA∨B) is
true if at least any of the propositional variable A or B is true.
The truth table is as follows −
A B A∨B
AND (∧∧) − The AND operation of two propositions A and B (written as A∧BA∧B) is
true if both the propositional variable A and B is true.
The truth table is as follows −
A B A∧B
A ¬A
True False
False True
A B A→B
A B A⇔B
Tautologies
A Tautology is a formula which is always true for every value of its propositional
variables.
Example − Prove [(A→B)∧A]→B[(A→B)∧A]→B is a tautology
The truth table is as follows −
A B A→B (A → B) ∧ A [( A → B ) ∧ A] → B
Contradictions
A Contradiction is a formula which is always false for every value of its propositional
variables.
Example − Prove (A∨B)∧[(¬A)∧(¬B)](A∨B)∧[(¬A)∧(¬B)] is a contradiction
The truth table is as follows −
A B A∨B ¬A ¬B (¬ A) ∧ ( ¬ B) (A ∨ B) ∧ [( ¬ A) ∧ (¬ B)]
Contingency
A Contingency is a formula which has both some true and some false values for
every value of its propositional variables.
Example − Prove (A∨B)∧(¬A)(A∨B)∧(¬A) a contingency
The truth table is as follows −
A B A∨B ¬A (A ∨ B) ∧ (¬ A)
Propositional Equivalences
Two statements X and Y are logically equivalent if any of the following two
conditions hold −
The truth tables of each statement have the same truth values.
Hypothesis, p
Conclusion, q
As mentioned earlier, it is denoted as p→qp→q.
Example of Conditional Statement − “If you do your homework, you will not be
punished.” Here, "you do your homework" is the hypothesis, p, and "you will not be
punished" is the conclusion, q.
Inverse − An inverse of the conditional statement is the negation of both the
hypothesis and the conclusion. If the statement is “If p, then q”, the inverse will be “If
not p, then not q”. Thus the inverse of p→qp→q is ¬p→¬q¬p→¬q.
Example − The inverse of “If you do your homework, you will not be punished” is “If
you do not do your homework, you will be punished.”
Converse − The converse of the conditional statement is computed by
interchanging the hypothesis and the conclusion. If the statement is “If p, then q”,
the converse will be “If q, then p”. The converse of p→qp→q is q→pq→p.
Example − The converse of "If you do your homework, you will not be punished" is
"If you will not be punished, you do your homework”.
Contra-positive − The contra-positive of the conditional is computed by
interchanging the hypothesis and the conclusion of the inverse statement. If the
statement is “If p, then q”, the contra-positive will be “If not q, then not p”. The
contra-positive of p→qp→q is ¬q→¬p¬q→¬p.
Example − The Contra-positive of " If you do your homework, you will not be
punished” is "If you are punished, you did not do your homework”.
Duality Principle
Duality principle states that for any true statement, the dual statement obtained by
interchanging unions into intersections (and vice versa) and interchanging Universal
set into Null set (and vice versa) is also true. If dual of any statement is the
statement itself, it is said self-dual statement.
Example − The dual of (A∩B)∪C(A∩B)∪C is (A∪B)∩C(A∪B)∩C
Normal Forms
We can convert any proposition in two normal forms −
P→Q¬Q∴¬PP→Q Modus
¬Q∴¬P Tollens
Addition
If P is a premise, we can use Addition rule to derive P∨QP∨Q.
P∴P∨QP∴P∨Q
Example
Conjunction
If P and Q are two premises, we can use Conjunction rule to derive P∧QP∧Q.
PQ∴P∧QPQ∴P∧Q
Example
Simplification
If P∧QP∧Q is a premise, we can use Simplification rule to derive P.
P∧Q∴PP∧Q∴P
Example
"He studies very hard and he is the best boy in the class", P∧QP∧Q
Therefore − "He studies very hard"
Modus Ponens
If P and P→QP→Q are two premises, we can use Modus Ponens to derive Q.
P→QP∴QP→QP∴Q
Example
Example
Disjunctive Syllogism
If ¬P¬P and P∨QP∨Q are two premises, we can use Disjunctive Syllogism to derive
Q.
¬PP∨Q∴Q¬PP∨Q∴Q
Example
Hypothetical Syllogism
If P→QP→Q and Q→RQ→R are two premises, we can use Hypothetical Syllogism
to derive P→RP→R
P→QQ→R∴P→RP→QQ→R∴P→R
Example
Constructive Dilemma
If (P→Q)∧(R→S)(P→Q)∧(R→S) and P∨RP∨R are two premises, we can use
constructive dilemma to derive Q∨SQ∨S.
(P→Q)∧(R→S)P∨R∴Q∨S(P→Q)∧(R→S)P∨R∴Q∨S
Example
Destructive Dilemma
If (P→Q)∧(R→S)(P→Q)∧(R→S) and ¬Q∨¬S¬Q∨¬S are two premises, we can use
destructive dilemma to derive ¬P∨¬R¬P∨¬R.
(P→Q)∧(R→S)¬Q∨¬S∴¬P∨¬R(P→Q)∧(R→S)¬Q∨¬S∴¬P∨¬R
Example
Set - Definition
A set is an unordered collection of different elements. A set can be written explicitly
by listing its elements using set bracket. If the order of the elements is changed or
any element of a set is repeated, it does not make any changes in the set.
Representation of a Set
Sets can be represented in two ways −
The set is represented by listing all the elements comprising it. The elements are
enclosed within braces and separated by commas.
Example 1 − Set of vowels in English alphabet, A={a,e,i,o,u}A={a,e,i,o,u}
Example 2 − Set of odd numbers less than 10, B={1,3,5,7,9}B={1,3,5,7,9}
The set is defined by specifying a property that elements of the set have in
common. The set is described as A={x:p(x)}A={x:p(x)}
Example 1 − The set {a,e,i,o,u}{a,e,i,o,u} is written as −
A={x:x is a vowel in English alphabet}A={x:x is a vowel in English alphabet}
Example 2 − The set {1,3,5,7,9}{1,3,5,7,9} is written as −
B={x:1≤x<10 and (x%2)≠0}B={x:1≤x<10 and (x%2)≠0}
If an element x is a member of any set S, it is denoted by x∈Sx∈S and if an element
y is not a member of set S, it is denoted by y∉Sy∉S.
Example − If S={1,1.2,1.7,2},1∈SS={1,1.2,1.7,2},1∈S but 1.5∉S1.5∉S
Cardinality of a Set
Cardinality of a set S, denoted by |S||S|, is the number of elements of the set. The
number is also referred as the cardinal number. If a set has an infinite number of
elements, its cardinality is ∞∞.
Example − |{1,4,3,5}|=4,|{1,2,3,4,5,…}|=∞|{1,4,3,5}|=4,|{1,2,3,4,5,…}|=∞
If there are two sets X and Y,
|X|=|Y||X|=|Y| denotes two sets X and Y having same cardinality. It occurs when the
number of elements in X is exactly equal to the number of elements in Y. In this case,
there exists a bijective function ‘f’ from X to Y.
|X|≤|Y||X|≤|Y| denotes that set X’s cardinality is less than or equal to set Y’s
cardinality. It occurs when number of elements in X is less than or equal to that of Y.
Here, there exists an injective function ‘f’ from X to Y.
|X|<|Y||X|<|Y| denotes that set X’s cardinality is less than set Y’s cardinality. It occurs
when number of elements in X is less than that of Y. Here, the function ‘f’ from X to Y is
injective function but not bijective.
If |X|≤|Y|If |X|≤|Y| and |X|≥|Y||X|≥|Y| then |X|=|Y||X|=|Y|. The sets X and Y are
commonly referred as equivalent sets.
Types of Sets
Sets can be classified into many types. Some of which are finite, infinite, subset,
universal, proper, singleton set, etc.
Finite Set
Infinite Set
Subset
Proper Subset
The term “proper subset” can be defined as “subset of but not equal to”. A Set X is a
proper subset of set Y (Written as X⊂YX⊂Y) if every element of X is an element of
set Y and |X|<|Y||X|<|Y|.
Example − Let, X={1,2,3,4,5,6}X={1,2,3,4,5,6} and Y={1,2}Y={1,2}. Here
set Y⊂XY⊂X since all elements in YY are contained in XX too and XX has at
least one element is more than set YY.
Universal Set
Singleton set or unit set contains only one element. A singleton set is denoted
by {s}{s}.
Example − S={x|x∈N, 7<x<9}S={x|x∈N, 7<x<9} = {8}{8}
Equal Set
If two sets contain the same elements they are said to be equal.
Example − If A={1,2,6}A={1,2,6} and B={6,1,2}B={6,1,2}, they are equal as
every element of set A is an element of set B and every element of set B is an
element of set A.
Equivalent Set
If the cardinalities of two sets are same, they are called equivalent sets.
Example − If A={1,2,6}A={1,2,6} and B={16,17,22}B={16,17,22}, they are
equivalent as cardinality of A is equal to the cardinality of B. i.e. |A|=|B|=3|A|=|
B|=3
Overlapping Set
Two sets that have at least one common element are called overlapping sets.
In case of overlapping sets −
n(A∪B)=n(A)+n(B)−n(A∩B)n(A∪B)=n(A)+n(B)−n(A∩B)
n(A∪B)=n(A−B)+n(B−A)+n(A∩B)n(A∪B)=n(A−B)+n(B−A)+n(A∩B)
n(A)=n(A−B)+n(A∩B)n(A)=n(A−B)+n(A∩B)
n(B)=n(B−A)+n(A∩B)n(B)=n(B−A)+n(A∩B)
Example − Let, A={1,2,6}A={1,2,6} and B={6,12,42}B={6,12,42}. There is a
common element ‘6’, hence these sets are overlapping sets.
Disjoint Set
Two sets A and B are called disjoint sets if they do not have even one element in
common. Therefore, disjoint sets have the following properties −
n(A∩B)=∅n(A∩B)=∅
n(A∪B)=n(A)+n(B)n(A∪B)=n(A)+n(B)
Example − Let, A={1,2,6}A={1,2,6} and B={7,9,14}B={7,9,14}, there is not a
single common element, hence these sets are overlapping sets.
Venn Diagrams
Venn diagram, invented in 1880 by John Venn, is a schematic diagram that shows
all possible logical relations between different mathematical sets.
Examples
Set Operations
Set Operations include Set Union, Set Intersection, Set Difference, Complement of
Set, and Cartesian Product.
Set Union
The union of sets A and B (denoted by A∪BA∪B) is the set of elements which are
in A, in B, or in both A and B. Hence, A∪B={x|x∈A OR x∈B}A∪B={x|
x∈A OR x∈B}.
Example − If A={10,11,12,13}A={10,11,12,13} and B = {13,14,15}{13,14,15},
then A∪B={10,11,12,13,14,15}A∪B={10,11,12,13,14,15}. (The common element
occurs only once)
Set Intersection
The intersection of sets A and B (denoted by A∩BA∩B) is the set of elements which
are in both A and B. Hence, A∩B={x|x∈A AND x∈B}A∩B={x|x∈A AND x∈B}.
Example − If A={11,12,13}A={11,12,13} and B={13,14,15}B={13,14,15},
then A∩B={13}A∩B={13}.
The set difference of sets A and B (denoted by A–BA–B) is the set of elements
which are only in A but not in B. Hence, A−B={x|x∈A AND x∉B}A−B={x|
x∈A AND x∉B}.
Example − If A={10,11,12,13}A={10,11,12,13} and B={13,14,15}B={13,14,15},
then (A−B)={10,11,12}(A−B)={10,11,12} and (B−A)={14,15}(B−A)={14,15}.
Here, we can see (A−B)≠(B−A)(A−B)≠(B−A)
Complement of a Set
The complement of a set A (denoted by A′A′) is the set of elements which are not in
set A. Hence, A′={x|x∉A}A′={x|x∉A}.
More specifically, A′=(U−A)A′=(U−A) where UU is a universal set which contains
all objects.
Example − If A={x|x belongstosetofoddintegers}A={x|
x belongstosetofoddintegers} then A′={y|y doesnotbelongtosetofoddintegers}A′={y|
y doesnotbelongtosetofoddintegers}
Cartesian Product / Cross Product
Power Set
Power set of a set S is the set of all subsets of S including the empty set. The
cardinality of a power set of a set S of cardinality n is 2n2n. Power set is denoted
as P(S)P(S).
Example −
For a set S={a,b,c,d}S={a,b,c,d} let us calculate the subsets −
Subsets with 0 elements − {∅}{∅} (the empty set)
Subsets with 1 element − {a},{b},{c},{d}{a},{b},{c},{d}
Subsets with 2 elements − {a,b},{a,c},{a,d},{b,c},{b,d},{c,d}{a,b},{a,c},{a,d},
{b,c},{b,d},{c,d}
Subsets with 3 elements − {a,b,c},{a,b,d},{a,c,d},{b,c,d}{a,b,c},{a,b,d},{a,c,d},
{b,c,d}
Subsets with 4 elements − {a,b,c,d}{a,b,c,d}
Hence, P(S)=P(S)=
{{∅},{a},{b},{c},{d},{a,b},{a,c},{a,d},{b,c},{b,d},{c,d},{a,b,c},{a,b,d},
{a,c,d},{b,c,d},{a,b,c,d}}{{∅},{a},{b},{c},{d},{a,b},{a,c},{a,d},{b,c},{b,d},{c,d},{a,b,c},
{a,b,d},{a,c,d},{b,c,d},{a,b,c,d}}
|P(S)|=24=16|P(S)|=24=16
Note − The power set of an empty set is also an empty set.
|P({∅})|=20=1|P({∅})|=20=1
Partitioning of a Set
Partition of a set, say S, is a collection of n disjoint subsets, say P1,P2,…PnP1,P2,…
Pn that satisfies the following three conditions −
PiPi does not contain the empty set.
[Pi≠{∅} for all 0<i≤n][Pi≠{∅} for all 0<i≤n]
The union of the subsets must equal the entire original set.
[P1∪P2∪⋯∪Pn=S][P1∪P2∪⋯∪Pn=S]
The intersection of any two distinct sets is empty.
[Pa∩Pb={∅}, for a≠b where n≥a,b≥0][Pa∩Pb={∅}, for a≠b where n≥a,b≥0]
Example
Let S={a,b,c,d,e,f,g,h}S={a,b,c,d,e,f,g,h}
One probable partitioning is {a},{b,c,d},{e,f,g,h}{a},{b,c,d},{e,f,g,h}
Another probable partitioning is {a,b},{c,d},{e,f,g,h}{a,b},{c,d},{e,f,g,h}
Bell Numbers
Bell numbers give the count of the number of ways to partition a set. They are
denoted by BnBn where n is the cardinality of the set.
Example −
Let S={1,2,3}S={1,2,3}, n=|S|=3n=|S|=3
The alternate partitions are −
1. ∅,{1,2,3}∅,{1,2,3}
2. {1},{2,3}{1},{2,3}
3. {1,2},{3}{1,2},{3}
4. {1,3},{2}{1,3},{2}
5. {1},{2},{3}{1},{2},{3}
Hence B3=5B3=5
Relations may exist between objects of the same set or between objects of two or
more sets.
Examples
Let, A={1,2,9}A={1,2,9} and B={1,3,7}B={1,3,7}
Case 1 − If relation R is 'equal to' then R={(1,1),(3,3)}R={(1,1),(3,3)}
Dom(R) = {1,3},Ran(R)={1,3}{1,3},Ran(R)={1,3}
Case 2 − If relation R is 'less than' then R={(1,3),(1,7),(2,3),(2,7)}R={(1,3),(1,7),
(2,3),(2,7)}
Dom(R) = {1,2},Ran(R)={3,7}{1,2},Ran(R)={3,7}
Case 3 − If relation R is 'greater than' then R={(2,1),(9,1),(9,3),(9,7)}R={(2,1),
(9,1),(9,3),(9,7)}
Dom(R) = {2,9},Ran(R)={1,3,7}{2,9},Ran(R)={1,3,7}
Example
Permutations
A permutation is an arrangement of some elements in which order matters. In
other words a Permutation is an ordered Combination of elements.
Examples
xy,yx,xz,zx,yz,zyxy,yx,xz,zx,yz,zy.
We have to form a permutation of three digit numbers from a set of
numbers S={1,2,3}S={1,2,3}. Different three digit numbers will be formed when we
arrange the digits. The permutation will be = 123, 132, 213, 231, 312, 321
Number of Permutations
The number of permutations of ‘n’ different things taken ‘r’ at a time is denoted
by nPrnPr
nPr=n!(n−r)!nPr=n!(n−r)!
where n!=1.2.3.…(n−1).nn!=1.2.3.…(n−1).n
Proof − Let there be ‘n’ different elements.
There are n number of ways to fill up the first place. After filling the first place (n-1)
number of elements is left. Hence, there are (n-1) ways to fill up the second place.
After filling the first and second place, (n-2) number of elements is left. Hence, there
are (n-2) ways to fill up the third place. We can now generalize the number of ways
to fill up r-th place as [n – (r–1)] = n–r+1
So, the total no. of ways to fill up from first place up to r-th-place −
nPr=n(n−1)(n−2).....(n−r+1)nPr=n(n−1)(n−2).....(n−r+1)
=[n(n−1)(n−2)...(n−r+1)][(n−r)(n−r−1)…3.2.1]/[(n−r)(n−r−1)…
3.2.1]=[n(n−1)(n−2)...(n−r+1)][(n−r)(n−r−1)…3.2.1]/[(n−r)(n−r−1)…3.2.1]
Hence,
nPr=n!/(n−r)!nPr=n!/(n−r)!
Some Problems
Problem 1 − From a bunch of 6 different cards, how many ways we can permute it?
Solution − As we are taking 6 cards at a time from a deck of 6 cards, the
permutation will be 6P6=6!=7206P6=6!=720
Problem 2 − In how many ways can the letters of the word 'READER' be arranged?
Solution − There are 6 letters word (2 E, 1 A, 1D and 2R.) in the word 'READER'.
The permutation will be =6!/[(2!)(1!)(1!)(2!)]=180.=6!/[(2!)(1!)(1!)(2!)]=180.
Problem 3 − In how ways can the letters of the word 'ORANGE' be arranged so that
the consonants occupy only the even positions?
Solution − There are 3 vowels and 3 consonants in the word 'ORANGE'. Number of
ways of arranging the consonants among themselves =3P3=3!=6=3P3=3!=6. The
remaining 3 vacant places will be filled up by 3 vowels in 3P3=3!=63P3=3!=6 ways.
Hence, the total number of permutation is 6×6=366×6=36
Combinations
A combination is selection of some given elements in which order does not matter.
The number of all combinations of n things, taken r at a time is −
nCr=n!r!(n−r)!nCr=n!r!(n−r)!
Problem 1
Find the number of subsets of the set {1,2,3,4,5,6}{1,2,3,4,5,6} having 3 elements.
Solution
The cardinality of the set is 6 and we have to choose 3 elements from the set. Here,
the ordering does not matter. Hence, the number of subsets will be 6C3=206C3=20.
Problem 2
There are 6 men and 5 women in a room. In how many ways we can choose 3 men
and 2 women from the room?
Solution
The number of ways to choose 3 men from 6 men is 6C36C3 and the number of
ways to choose 2 women from 5 women is 5C25C2
Hence, the total number of ways is − 6C3×5C2=20×10=2006C3×5C2=20×10=200
Problem 3
How many ways can you choose 3 distinct groups of 3 students from total 9
students?
Solution
Let us number the groups as 1, 2 and 3
For choosing 3 students for 1st group, the number of ways − 9C39C3
The number of ways for choosing 3 students for 2 nd group after choosing 1st group
− 6C36C3
The number of ways for choosing 3 students for 3 rd group after choosing 1st and
2nd group − 3C33C3
Hence, the total number of
ways =9C3×6C3×3C3=84×20×1=1680=9C3×6C3×3C3=84×20×1=1680
Pascal's Identity
Pascal's identity, first derived by Blaise Pascal in 17 th century, states that the
number of ways to choose k elements from n elements is equal to the summation of
number of ways to choose (k-1) elements from (n-1) elements and the number of
ways to choose elements from n-1 elements.
Mathematically, for any positive integers k and
n: nCk=n−1Ck−1+n−1CknCk=n−1Ck−1+n−1Ck
Proof −
n−1Ck−1+n−1Ckn−1Ck−1+n−1Ck
=(n−1)!(k−1)!(n−k)!+(n−1)!k!(n−k−1)!=(n−1)!(k−1)!(n−k)!+(n−1)!k!(n−k−1)!
=(n−1)!(kk!(n−k)!+n−kk!(n−k)!)=(n−1)!(kk!(n−k)!+n−kk!(n−k)!)
=(n−1)!nk!(n−k)!=(n−1)!nk!(n−k)!
=n!k!(n−k)!=n!k!(n−k)!
=nCk=nCk
Pigeonhole Principle
In 1834, German mathematician, Peter Gustav Lejeune Dirichlet, stated a principle
which he called the drawer principle. Now, it is known as the pigeonhole principle.
Pigeonhole Principle states that if there are fewer pigeon holes than total number
of pigeons and each pigeon is put in a pigeon hole, then there must be at least one
pigeon hole with more than one pigeon. If n pigeons are put into m pigeonholes
where n > m, there's a hole with more than one pigeon.
Examples
Ten men are in a room and they are taking part in handshakes. If each person shakes
hands at least once and no man shakes the same man’s hand more than once then two
men took part in the same number of handshakes.
There must be at least two people in a class of 30 whose names start with the same
alphabet.
Basic Concepts
Probability theory was invented in the 17th century by two French mathematicians,
Blaise Pascal and Pierre de Fermat, who were dealing with mathematical problems
regarding of chance.
Before proceeding to details of probability, let us get the concept of some
definitions.
Random Experiment − An experiment in which all possible outcomes are known
and the exact output cannot be predicted in advance is called a random experiment.
Tossing a fair coin is an example of random experiment.
Sample Space − When we perform an experiment, then the set S of all possible
outcomes is called the sample space. If we toss a coin, the sample
space S={H,T}S={H,T}
Event − Any subset of a sample space is called an event. After tossing a coin,
getting Head on the top is an event.
The word "probability" means the chance of occurrence of a particular event. The
best we can say is how likely they are to happen, using the idea of probability.
Probabilityofoccurenceofanevent=TotalnumberoffavourableoutcomeTotalnumberofOutcomesProba
bilityofoccurenceofanevent=TotalnumberoffavourableoutcomeTotalnumberofOutcomes
As the occurrence of any event varies between 0% and 100%, the probability varies
between 0 and 1.
Tossing a Coin
Throwing a Dice
From a deck of 52 cards, if one card is picked find the probability of an ace being
drawn and also find the probability of a diamond being drawn.
Total number of possible outcomes − 52
Outcomes of being an ace − 4
Probability of being an ace = 4/52 = 1/13
Probability of being a diamond = 13/52 = 1/4
Probability Axioms
The probability of an event always varies from 0 to 1. [0≤P(x)≤1][0≤P(x)≤1]
For an impossible event the probability is 0 and for a certain event the probability is 1.
If the occurrence of one event is not influenced by another event, they are called
mutually exclusive or disjoint.
Properties of Probability
If there are two events xx and x¯¯¯x¯which are complementary, then the probability of
the complementary event is −
p(x¯¯¯)=1−p(x)p(x¯)=1−p(x)
For two non-disjoint events A and B, the probability of the union of two events −
P(A∪B)=P(A)+P(B)P(A∪B)=P(A)+P(B)
If an event A is a subset of another event B (i.e. A⊂BA⊂B), then the probability of A is
less than or equal to the probability of B.
Hence, A⊂BA⊂B implies P(A)≤p(B)P(A)≤p(B)
Conditional Probability
The conditional probability of an event B is the probability that the event will occur
given an event A has already occurred. This is written as P(B|A)P(B|A).
Mathematically − P(B|A)=P(A∩B)/P(A)P(B|A)=P(A∩B)/P(A)
If event A and B are mutually exclusive, then the conditional probability of event B
after the event A will be the probability of event B that is P(B)P(B).
Problem 1
In a country 50% of all teenagers own a cycle and 30% of all teenagers own a bike
and cycle. What is the probability that a teenager owns bike given that the teenager
owns a cycle?
Solution
Let us assume A is the event of teenagers owning only a cycle and B is the event of
teenagers owning only a bike.
So, P(A)=50/100=0.5P(A)=50/100=0.5 and P(A∩B)=30/100=0.3P(A∩B)=30/10
0=0.3 from the given problem.
P(B|A)=P(A∩B)/P(A)=0.3/0.5=0.6P(B|A)=P(A∩B)/P(A)=0.3/0.5=0.6
Hence, the probability that a teenager owns bike given that the teenager owns a
cycle is 60%.
Problem 2
In a class, 50% of all students play cricket and 25% of all students play cricket and
volleyball. What is the probability that a student plays volleyball given that the
student plays cricket?
Solution
Let us assume A is the event of students playing only cricket and B is the event of
students playing only volleyball.
So, P(A)=50/100=0.5P(A)=50/100=0.5 and P(A∩B)=25/100=0.25P(A∩B)=25/1
00=0.25 from the given problem.
P⟮B|A⟯=P⟮A∩B⟯/P⟮A⟯=0.25/0.5=0.5P⟮B|
A⟯=P⟮A∩B⟯/P⟮A⟯=0.25/0.5=0.5
Hence, the probability that a student plays volleyball given that the student plays
cricket is 50%.
Problem 3
Six good laptops and three defective laptops are mixed up. To find the defective
laptops all of them are tested one-by-one at random. What is the probability to find
both of the defective laptops in the first two pick?
Solution
Let A be the event that we find a defective laptop in the first test and B be the event
that we find a defective laptop in the second test.
Hence, P(A∩B)=P(A)P(B|A)=3/9×2/8=1/12P(A∩B)=P(A)P(B|A)=3/9×2/8=1/12
Bayes' Theorem
Theorem − If A and B are two mutually exclusive events, where P(A)P(A) is the
probability of A and P(B)P(B) is the probability of B, P(A|B)P(A|B) is the probability
of A given that B is true. P(B|A)P(B|A) is the probability of B given that A is true,
then Bayes’ Theorem states −
P(A|B)=P(B|A)P(A)∑ni=1P(B|Ai)P(Ai)P(A|B)=P(B|A)P(A)∑i=1nP(B|Ai)P(Ai)
In situations where all the events of sample space are mutually exclusive events.
Simple Graph
A graph with no loops and no parallel edges is called a simple graph.
The maximum number of edges possible in a single graph with ‘n’ vertices
is nC2 where nC2 = n(n – 1)/2.
The number of simple graphs possible with ‘n’ vertices = 2 c = 2n(n-1)/2.
n
2
Example
In the following graph, there are 3 vertices with 3 edges which is maximum
excluding the parallel edges and loops. This can be proved by using the above
formulae.
= 23(3-1)/2
= 23
= 8
These 8 graphs are as shown below −
Multi-Graph
If in a graph multiple edges between the same set of vertices are allowed, it is
called Multigraph. In other words, it is a graph having at least one loop or multiple
edges.
Weighted graph :
Sometimes want to associate some value with the edges in graph. 20 1 -------> 2 / \ / 50/ \50
/20 / \ / v 10 v v 20 5 ------> 3 -----> 4 So.. label all the edges with a number. That number (called the
weight) could represent: • Distances between two locations (cities; computers on network) • Time
taken to get from one node to another (stations; states in schedule or plan). • Cost of traversing the
edge (train fares; cost of wires.
A graph is traversable if you can draw a path between all the vertices without
retracing the same path. Based on this path, there are some categories like Euler’s
path and Euler’s circuit which are described in this chapter.
Euler’s Path
An Euler’s path contains each edge of ‘G’ exactly once and each vertex of ‘G’ at
least once. A connected graph G is said to be traversable if it contains an Euler’s
path.
Example
Euler’s Circuit
In an Euler’s path, if the starting vertex is same as its ending vertex, then it is called
an Euler’s circuit.
Example
Euler’s Path = a-b-c-d-a-g-f-e-c-a.
Example
Euler’s Path − b-e-a-b-d-c-a is not an Euler’s circuit, but it is an Euler’s path.
Clearly it has exactly 2 odd degree vertices.
Note − In a connected graph G, if the number of vertices with odd degree = 0, then
Euler’s circuit exists.
Hamiltonian Graph
A connected graph G is said to be a Hamiltonian graph, if there exists a cycle which
contains all the vertices of G.
Every cycle is a circuit but a circuit may contain multiple cycles. Such a cycle is
called a Hamiltonian cycle of G.
Hamiltonian Path
A connected graph is said to be Hamiltonian if it contains each vertex of G exactly
once. Such a path is called a Hamiltonian path.
Example
Hamiltonian Path − e-d-b-a-c.
Note −
Example
Example
Regions
Every planar graph divides the plane into connected areas called regions.
Example
deg(1) = 3
deg(2) = 4
deg(3) = 4
deg(4) = 3
deg(5) = 8
Degree of an unbounded region r = deg(r) = Number of edges enclosing the
regions r.
deg(R ) = 4
1
deg(R ) = 6
2
|E| ≤ 3|V| − 6
|R| ≤ 2|V| − 4
|E| ≤ {2|V| – 4}
7. Kuratowski's Theorem
A graph 'G' is non-planar if and only if 'G' has a subgraph which is homeomorphic to
K5 or K3,3.
Graph coloring is nothing but a simple way of labelling graph components such as
vertices, edges, and regions under some constraints. In a graph, no two adjacent
vertices, adjacent edges, or adjacent regions are colored with minimum number of
colors. This number is called the chromatic number and the graph is called
a properly colored graph.
While graph coloring, the constraints that are set on the graph are colors, order of
coloring, the way of assigning color, etc. A coloring is given to a vertex or a
particular region. Thus, the vertices or regions having same colors form
independent sets.
Vertex Coloring
Vertex coloring is an assignment of colors to the vertices of a graph ‘G’ such that no
two adjacent vertices have the same color. Simply put, no two vertices of an edge
should be of the same color.
Chromatic Number
The minimum number of colors required for vertex coloring of graph ‘G’ is called as
the chromatic number of G, denoted by X(G).
χ(G) = 1 if and only if 'G' is a null graph. If 'G' is not a null graph, then χ(G) ≥ 2
Example
Note − A graph ‘G’ is said to be n-coverable if there is a vertex coloring that uses at
most n colors, i.e., X(G) ≤ n.
Region Coloring
Region coloring is an assignment of colors to the regions of a planar graph such
that no two adjacent regions have the same color. Two regions are said to be
adjacent if they have a common edge.
Example
Take a look at the following graph. The regions ‘aeb’ and ‘befc’ are adjacent, as
there is a common edge ‘be’ between those two regions.
Similarly the other regions are also coloured based on the adjacency. This graph is
coloured as follows −
Example
Clustering
Data mining
Image capturing
Image segmentation
Networking
Resource allocation
Processes scheduling
Bipartite Graph - If the vertex-set of a graph G can be split into two disjoint
sets, V1 and V2 , in such a way that each edge in the graph joins a vertex in
V1 to a vertex in V2 , and there are no edges in G that connect two vertices in
V1 or two vertices in V2 , then the graph G is called a bipartite graph.
Complete Bipartite Graph - A complete bipartite graph is a bipartite graph in
which each vertex in the first set is joined to every single vertex in the second
set. The complete bipartite graph is denoted by K x,y where the graph G
contains x vertices in the first set and y vertices in the second set.
Tree
A connected acyclic graph is called a tree. In other words, a connected graph with
no cycles is called a tree.
The edges of a tree are known as branches. Elements of trees are called
their nodes. The nodes without child nodes are called leaf nodes.
A tree with ‘n’ vertices has ‘n-1’ edges. If it has one more edge extra than ‘n-1’, then
the extra edge should obviously has to pair up with two vertices which leads to form
a cycle. Then, it becomes a cyclic graph which is a violation for the tree graph.
Example 1
The graph shown here is a tree because it has no cycles and it is connected. It has
four vertices and three edges, i.e., for ‘n’ vertices ‘n-1’ edges as mentioned in the
definition.
Example 2
In the above example, the vertices ‘a’ and ‘d’ has degree one. And the other two
vertices ‘b’ and ‘c’ has degree two. This is possible because for not forming a cycle,
there should be at least two single edges anywhere in the graph. It is nothing but
two edges with a degree of one.
Forest
A disconnected acyclic graph is called a forest. In other words, a disjoint
collection of trees is called a forest.
Example
The following graph looks like two sub-graphs; but it is a single disconnected graph.
There are no cycles in this graph. Hence, clearly it is a forest.
Spanning Trees
Let G be a connected graph, then the sub-graph H of G is called a spanning tree of
G if −
H is a tree
H contains all vertices of G.
A spanning tree T of an undirected graph G is a subgraph that includes all of the
vertices of G.
Example
In the above example, G is a connected graph and H is a sub-graph of G.
Clearly, the graph H has no cycles, it is a tree with six edges which is one less than
the total number of vertices. Hence H is the Spanning tree of G.
Circuit Rank
Let ‘G’ be a connected graph with ‘n’ vertices and ‘m’ edges. A spanning tree ‘T’ of
G contains (n-1) edges.
Therefore, the number of edges you need to delete from ‘G’ in order to get a
spanning tree = m-(n-1), which is called the circuit rank of G.
This formula is true, because in a spanning tree you need to have ‘n-1’ edges. Out
of ‘m’ edges, you need to keep ‘n–1’ edges in the graph.
Hence, deleting ‘n–1’ edges from ‘m’ gives the edges to be removed from the graph
in order to get a spanning tree, which should not form a cycle.
Example
For the graph given in the above example, you have m=7 edges and n=5 vertices.
Then the circuit rank is
G = m – (n – 1)
= 7 – (5 – 1)
= 3
Example
Let ‘G’ be a connected graph with six vertices and the degree of each vertex is
three. Find the circuit rank of ‘G’.
By the sum of degree of vertices theorem,
n ∑ i=1 deg(Vi) = 2|E|
6 × 3 = 2|E|
|E| = 9
Circuit rank = |E| – (|V| – 1)
= 9 – (6 – 1) = 4
Kirchoff’s Theorem
Kirchoff’s theorem is useful in finding the number of spanning trees that can be
formed from a connected graph.
Example
The matrix ‘A’ be filled as, if there is an edge between two vertices, then it should be
given as ‘1’, else ‘0’.
Cut Set of a Graph
Let ‘G’= (V, E) be a connected graph. A subset E’ of E is called a cut set of G if
deletion of all the edges of E’ from G makes G disconnect.
If deleting a certain number of edges from a graph makes it disconnected, then
those deleted edges are called the cut set of the graph.
Example
Take a look at the following graph. Its cut set is E1 = {e1, e3, e5, e8}.
After removing the cut set E1 from the graph, it would appear as follows −
Similarly there are other cut sets that can disconnect the graph −
Edge Connectivity
Let ‘G’ be a connected graph. The minimum number of edges whose removal
makes ‘G’ disconnected is called edge connectivity of G.
Notation − λ(G)
In other words, the number of edges in a smallest cut set of G is called the edge
connectivity of G.
If ‘G’ has a cut edge, then λ(G) is 1. (edge connectivity of G.)
Example
Take a look at the following graph. By removing two minimum edges, the connected
graph becomes disconnected. Hence, its edge connectivity (λ(G)) is 2.
Here are the four ways to disconnect the graph by removing two edges −
Vertex Connectivity
Let ‘G’ be a connected graph. The minimum number of vertices whose removal
makes ‘G’ either disconnected or reduces ‘G’ in to a trivial graph is called its vertex
connectivity.
Notation − K(G)
Example
In the above graph, removing the vertices ‘e’ and ‘i’ makes the graph disconnected.
If G has a cut vertex, then K(G) = 1.
Notation − For any connected graph G,
K(G) ≤ λ(G) ≤ δ(G)
Vertex connectivity (K(G)), edge connectivity (λ(G)), minimum number of degrees of
G(δ(G)).
Example
Solution
From the graph,
δ(G) = 3
K(G) ≤ λ(G) ≤ δ(G) = 3 (1)
K(G) ≥ 2 (2)
Deleting the edges {d, e} and {b, h}, we can disconnect G.
Therefore,
λ(G) = 2
2 ≤ λ(G) ≤ δ(G) = 2 (3)
From (2) and (3), vertex connectivity K(G) = 2
Traversal is a process to visit all the nodes of a tree and may print their values too.
Because, all nodes are connected via edges (links) we always start from the root
(head) node. That is, we cannot randomly access a node in a tree. There are three
ways which we use to traverse a tree −
In-order Traversal
Pre-order Traversal
Post-order Traversal
Generally, we traverse a tree to search or locate a given item or key in the tree or to
print all the values it contains.
In-order Traversal
In this traversal method, the left subtree is visited first, then the root and later the
right sub-tree. We should always remember that every node may represent a
subtree itself.
If a binary tree is traversed in-order, the output will produce sorted key values in an
ascending order.
We start from A, and following in-order traversal, we move to its left subtree B. B is
also traversed in-order. The process goes on until all the nodes are visited. The
output of inorder traversal of this tree will be −
D→B→E→A→F→C→G
Algorithm
Until all nodes are traversed −
Step 1 − Recursively traverse left subtree.
Step 2 − Visit root node.
Step 3 − Recursively traverse right subtree.
Pre-order Traversal
In this traversal method, the root node is visited first, then the left subtree and finally
the right subtree.
We start from A, and following pre-order traversal, we first visit A itself and then
move to its left subtree B. B is also traversed pre-order. The process goes on until
all the nodes are visited. The output of pre-order traversal of this tree will be −
A→B→D→E→C→F→G
Algorithm
Until all nodes are traversed −
Step 1 − Visit root node.
Step 2 − Recursively traverse left subtree.
Step 3 − Recursively traverse right subtree.
Post-order Traversal
In this traversal method, the root node is visited last, hence the name. First we
traverse the left subtree, then the right subtree and finally the root node.
We start from A, and following Post-order traversal, we first visit the left
subtree B. B is also traversed post-order. The process goes on until all the nodes
are visited. The output of post-order traversal of this tree will be −
D→E→B→F→G→C→A
Algorithm
Until all nodes are traversed −
Step 1 − Recursively traverse left subtree.
Step 2 − Recursively traverse right subtree.
Step 3 − Visit root node.
Boolean algebra deals with binary variables and logic operation. A Boolean
Function is described by an algebraic expression called Boolean
expression which consists of binary variables, the constants 0 and 1, and the logic
operation symbols. Consider the following example.
Here the left side of the equation represents the output Y. So we can state equation
no. 1
Karnaugh-map or K-map
The Boolean theorems and the De-Morgan's theorems are useful in manipulating
the logic expression. We can realize the logical expression using gates. The
number of logic gates required for the realization of a logical expression should be
reduced to a minimum possible value by K-map method. This method can be done
in two different ways, as discussed below.
It is in the form of sum of three terms AB, AC, BC with each individual term is a
product of two variables. Say A.B or A.C etc. Therefore such expressions are
known as expression in SOP form. The sum and products in SOP form are not the
actual additions or multiplications. In fact they are the OR and AND functions. In
SOP form, 0 represents a bar and 1 represents an unbar. SOP form is represented
by .
Given below is an example of SOP.
Product of Sums (POS) Form
It is in the form of product of three terms (A+B), (B+C), or (A+C) with each term is in
the form of a sum of two variables. Such expressions are said to be in the product
of sums (POS) form. In POS form, 0 represents an unbar and 1 represents a bar.
POS form is represented by .
Given below is an example of POS.
Problem 1
Solution
Given,F(A,B,C)=A′B+BC′+BC+AB′C′F(A,B,C)=A′B+BC′+BC+AB′C′
Or,F(A,B,C)=A′B+(BC′+BC′)+BC+AB′C′F(A,B,C)=A′B+(BC′+BC′)+BC+AB′C′
[By idempotent law, BC’ = BC’ + BC’]
Or,F(A,B,C)=A′B+(BC′+BC)+(BC′+AB′C′)F(A,B,C)=A′B+(BC′+BC)+(BC′+AB′C
′)
Or,F(A,B,C)=A′B+B(C′+C)+C′(B+AB′)F(A,B,C)=A′B+B(C′+C)+C′(B+AB′)
[By distributive laws]
Or,F(A,B,C)=A′B+B.1+C′(B+A)F(A,B,C)=A′B+B.1+C′(B+A)
[ (C' + C) = 1 and absorption law (B + AB')= (B + A)]
Or,F(A,B,C)=A′B+B+C′(B+A)F(A,B,C)=A′B+B+C′(B+A)
[ B.1 = B ]
Or,F(A,B,C)=B(A′+1)+C′(B+A)F(A,B,C)=B(A′+1)+C′(B+A)
Or,F(A,B,C)=B.1+C′(B+A)F(A,B,C)=B.1+C′(B+A)
[ (A' + 1) = 1 ]
Or,F(A,B,C)=B+C′(B+A)F(A,B,C)=B+C′(B+A)
[ As, B.1 = B ]
Or,F(A,B,C)=B+BC′+AC′F(A,B,C)=B+BC′+AC′
Or,F(A,B,C)=B(1+C′)+AC′F(A,B,C)=B(1+C′)+AC′
Or,F(A,B,C)=B.1+AC′F(A,B,C)=B.1+AC′
[As, (1 + C') = 1]
Or,F(A,B,C)=B+AC′F(A,B,C)=B+AC′
[As, B.1 = B]
So,F(A,B,C)=B+AC′F(A,B,C)=B+AC′is the minimized form.
Problem 2
Solution
Given, F(A,B,C)=(A+B)(A+C)F(A,B,C)=(A+B)(A+C)
Or, F(A,B,C)=A.A+A.C+B.A+B.CF(A,B,C)=A.A+A.C+B.A+B.C [Applying
distributive Rule]
Or, F(A,B,C)=A+A.C+B.A+B.CF(A,B,C)=A+A.C+B.A+B.C [Applying Idempotent
Law]
Or, F(A,B,C)=A(1+C)+B.A+B.CF(A,B,C)=A(1+C)+B.A+B.C [Applying
distributive Law]
Or, F(A,B,C)=A+B.A+B.CF(A,B,C)=A+B.A+B.C [Applying dominance Law]
Or, F(A,B,C)=(A+1).A+B.CF(A,B,C)=(A+1).A+B.C [Applying distributive Law]
Or, F(A,B,C)=1.A+B.CF(A,B,C)=1.A+B.C [Applying dominance Law]
Or, F(A,B,C)=A+B.CF(A,B,C)=A+B.C [Applying dominance Law]
So, F(A,B,C)=A+BCF(A,B,C)=A+BC is the minimized form.
Karnaugh Maps
The Karnaugh map (K–map), introduced by Maurice Karnaughin in 1953, is a grid-
like representation of a truth table which is used to simplify boolean algebra
expressions. A Karnaugh map has zero and one entries at different positions. It
provides grouping together Boolean expressions with common factors and
eliminates unwanted variables from the expression. In a K-map, crossing a vertical
or horizontal cell boundary is always a change of only one variable.
Example 1
A B A operation B
0 0 w
0 1 x
1 0 y
1 1 z
Example 2
Wrong grouping
Rule 2 − Groups must contain 2n cells (n starting from 1).
Wrong grouping
Rule 3 − Grouping must be horizontal or vertical, but must not be diagonal.
Insufficient grouping
Proper grouping
Rule 5 − If 1 of any cell cannot be grouped with any other cell, it will act as a group
itself.
Proper grouping
Rule 6 − Groups may overlap but there should be as few groups as possible.
Proper grouping
Rule 7 − The leftmost cell/cells can be grouped with the rightmost cell/cells and the
topmost cell/cells can be grouped with the bottommost cell/cells.
Proper grouping
Problem
Solution
Each term is put into k-map and we get the following −