Insights On Discrete Structure
Insights On Discrete Structure
iI
-
l ~
,.
l ~
-
-, f
',. __~-
,; ~:
J -.
·:''
i.
CONTENTS
3.3 Solution of Nonlinear Recurrence Relations .............. .. .............. J2 I
Ch,1ptt1r - 1 3.4 Application to Algorithm Analysis ....... ................................ ...... 127
LOGIC, INDUCTION AND REASONING
SOLVED NUMERICALS ....................................................... 130
1.1 . . ...............•·· ••· •··· ·· .. · · ·· ··· ································· I
Discrete Mathemaucs
Ch,1ph•r - 4
1.2 Logic, Induction and Reasoning •··••·•············ .. ··········· .... ··············· .. 3
GRAPH THEORY
1.3 Proposition and Truth Function ...... •.. ••··••········· .. ···· ... ·· ... · .... ·· .. · .. · .. · 6
4.1 Graph .............................................. ............................................ 136
1.4 Propositional Logic ............................... ."................ .... :........ ........... 7
4.2 Undirected and Directed Graphs .... ............................................ 138
1.5 Expressing Statements in Propositional logic ..... ........................ 16
4.3 Graphical Tenns and Terminologies .......................................... 139
1.6 The Predicate Logic ........................................... :.................... :..... 17
4.4 Bipartite Graphs, Planar Graphs, Regular Graphs ...................... 153
1.7 Arguments, Argument Forms and V~lidity .................. ::.............. 24
4.5 Walk Paths, Circuits, Components ............................................. 160
1.8 Rules of Inference ....... _...........................: .................: .... : ............. 25
4.6 Connectedness Algorithm........................................................... 162
1.9 ronnal and lnfonnal Proof.................................... , ...................... 28
4.7 Cut Sets and Cut Vertices ........................................................... 163
1.10 Informal Deduction in Predicate Logic .............. •·: •···· ·· .......... •····· 33
4.8 Eulerian Graph ............................................................................ 165
1.1 l lnfonnal Proofs and Fonnal Proofs .....................................,........ 36
4.9 Hamiltonian Graph ..................................................................... 167
1.12 Elementary Induction and Complete Induction ................ ............ 4 7
4.10 A shortest Path Algorithm .......................................................... 168
1.13 Consistency and Completeness of the System .............................. 55
4.11 Tree as a Directed Graph ............................................................ 175
1.14 Method of Tableaux. ........ - ........................................................... 55
4.12 Binary Search Tree .............................................................. ....... 181
SOLVED NUMERICALS - · - - · - - · · -..........- ........ 63
4.13 Prefix Codes ............................................................................... 183
<haplN- 2 4.14 Spanning Tree............................................................................. 186
FINITE STATE AUTOMATA 4.15 Graph Coloring ........................................................................... 198
2.1 Sequential Circuits and Finite state Machine ............................... 73 4.16 Max Flow and Min Cut .............................................................. 200
2.2 Finite state AutoDJata......- ............................................................ 76 SOLVED NUMERICALS ----·-··--······--··--····--···-·············· 204
2.3 Language and Grauunar ······················································:·....... 80
2.4 Language and Automata ............................................................... 86
2.5 Non-deterministic Finite State Automata ..................................... 89
2.6 Regular Expression and its Characteristics ................................... 93
SOLVED NUMERICALS - ··-··-·········.......................... 101
<haptN - ·3
RECURRENCE RELATION
3. 1 · Defi
Recursive . · · o f ---t'"-Dces
mt1on ~.. .. .......................................... . 110
Jr
. -]'
.
.
computer science as information is stored and manipulated in a
discrete form by computing machines. It is mathematics of integers
and collection of objects that triggers the operation of digital
computer. Discrete mathematics is widely used in all fields of
computer science for programming and reasoning about data
structures, algorithms and comple, ity. It enables to formulate
problems. precisely. solve the problems. apply formal proof
techniques, and explain their reasoning clearly. Discrete
mathematics deals with the questions like:
• In how many , ays the valid password can be chosen?
• What is the probability of winning a lottery?
• How can a list of integers be sorted in increasing order?
• How the shortt!st path between two cities can be
determined?
lnsl1hts on Discrete·Structure I1
r \
Uses of Discrete Math in Computer Science
2. Relational thinking (graph theory sets fu .
Discrete mathematics is widely used in various field of . ) , , nctions, database
re lahons
computer science like in Networking, Database, Image Processing,
Programming Languages, Compilers & Interpreters, Software 3. Recursive thinking (recurrence relati·ons, recursive
.
. data
Engineering, Artificial Intelligence, Computer Architecture, structures (bmary search trees))
4. Quantitative thinki~g
Operating Systems, Security & Cryptography, Advanced . h . . (counting, combinations, p'e. rmutat·10ns,
Algorithms & Data Structures, and Graphics & Animation. pigeon ole, big-Oh notation) ,.
5. Analytic~I thinki~g (apply previous tools, algorithm
Reason Behind Studying Discrete Mathematics:
complexity, analysis of algorithms)
There are two reasons behind studying discrete mathematics: 6. Applied thinking (problem solving skills, modeling)
i. To develop mathematical maturity
_ piscrete Mathematics is essential to Computer Science. The
ii. To enter to more advanced mathematical sciences
vanou~ aspects of discrete mathematics form the foundation for
i. To develop mathematical maturity: mod~lmg comp~ting structures, designing programs and
The study of discrete mathematics is necessary to upgrade algonthms, reasoning
. about programs and algorithms, solvmg· rea-l
the ability to understand and create mathematical arguments. ~o~ld probl~ms usmg the computer in particular, solving problems
This skill is important to get very far in the studies m m mfo~at~on ~echnology i.e., problems involving computers,
mathematical sciences. commumcatton, mformation.
~
ii. To enter to more advanced mathematical sciences 1.2 . Logic, Induction and Reasoning
Discrete mathematics is the gateway to more advanced 1.21 Logic
courses in all parts of mathematical sciences. Discrete
!~
j.
mathematics provides mathematical foundations for many
computer science courses incl~ding data structure
algorithms, database theory, automata theory, formal
Logic is a particular -.,,ay of thinking, especially one that is
reasonable and bas_ed on good judgment. More precisely, logic is
the study ~f reaso~mg or method of reasoning. Logic is a language
:;r r~omng. _It 1~ ~ co!lection of rules that is used in logical
r
i
language, compiler theory,. computer security, operating,
systems, math courses based on the material studied in . asomng. Logic d1stmgwshes valid and invalid arguments. Logic
IS
discrete ~thematics including logic, set theory, number
theory, liner algebra, abstract algebra, combinatorics, graph · • Crucial for Itlathematical reasoning
theory, probability theory. Discrete math contains necessary • Important for program d~sign
mathematical background for solving problems in operations • Used for designing electronic circuitry
research, chemistry, engineering, biology. Discrete
l.2.1:1 Types of logic
mathematics develops mathematical reasoning and problem
solving. ' 1. Propositional logic (logic of sentences)
Propositional logic is the study of propositions where ·a
Aspects of Discrete Mathematics:
proposition is a statement that is either true' or false.
I. Logical thinking (propositional, predicate logic, proof
Propositional logic may be used to encode simple arguments
method, prolog) that are.expr~ssed in natural language, and to determine their
1.
7_ NOR'( not OR) denoted byJ..
8 _ NAND ( not AND) denoted by :t
CooJ·uoctioo (A)
· · '
Let P and q be two propositions. The proposttton p an
denoted by pAq and is true only when p and q are true.
d q'
.
ts
_I-;~I_TI
p : Today is Monday.
,p : Today is not Monday.
Truth table of pAq ,p : It is not the case that today is Monday.
p q pAq 4. Implication ( - ) (conditional implication)
T T T
Let P and q be two propositions. The conditional statement
T F F
P- q is the proposition ' ifp then q'.
F T F
The proposition p - q is false only when p is true and q is
F F F false otherwise true.
..
Let p is proposition 'I am in college'. q is propos1tton 'It is : p q p ➔ q
cold'. T .
T T
pAq is I am in college and it is cold. T F F
Sometime but is used instead of and. F
E.g., The sun is shining but it is raining.
- F
T T
F T
lfl b
----
ecome HOD, I will give laptop to every student.
the converse is q - . p F T F
Inverse F F T
The inverse of conditional statement is the negation of botb.
the hypothesis and the conclusion. If we have condinon
· al Example, you can take the flight if and only if you buy a
ticket.
statement p _. q then the inverse is -,p - -,q 6. Exclusive OR (EB)
Contrapositive
· the Let p and q be propositions, p EB q is true when p is true and
Toe contrapositive is · computed by interchangm~. i
q is false or q is true and p is false. It is false when both p
hypothesis-an4 conclusion of inverse. If we have condition ·
and q are false or both are true.
statement p - q then the inverse is -,q -+ -,p
Insights cm Discrete Structure I 11
10 I Insights on DISQ"ete Structure
------------------., J
Example, Student who have take~ calculus or computer Lo21c andb.1t operation
science b ut not both can enroll in th1 s class. · X y xvy x-y .-,:
XAY x+-+y
p q p<Bq
0 0 0 0 I l
T F 0 I 0 l l 0
T
F T l 0 0 l 0 0
T
T T I l J J I J
F
F F Q. Find bitwise OR, bitwise XOR of bit strings 0110110110
F
and 1100011101. · [Do it yourselj]
7. NOR ( not OR) (J..)
NOR is negation of OR. For two propositions p and q,
1.4.2 Tautology, Contradiction and Contingency
Tautology
p-l.q = -, (pvq)
A compound proposition that is alway~ true no matter what
8. NAND ( not AND)(i)
the truth values of the proposition occur in it, is called tautology.
NANO is negation of AND. For two propositions p and q,
e.g., pv -,,, -,>A(pvq) - q, [(p-q)l\p]-q
piq = -,(pAq)
Contradiction
Precedence of operator
I. -, A compound proposition that is always false no matter what
the truth values of the proposition occur in it, is called
2. /\ contradiction.
3. V
e.g., PA-,>, (pvq)A[( -,>)/\( ~]
4. -
5. H
Contingency
-,>Aq means (-,,)Aq A compound proposition that is neither tautology nor
contradiction is called contingency. ·
pAq-+r means (pAq)-r
Q) Construct the truth table of compound proposition (-pN/) e. g., (pA~ - (pAq), (pvq) I\ ( -,,)
Q.
h
It sniws w enever +
the wind blows from the northeast A predicate is a declarative sentence whose truthiness or
falsehood depends on one or more variables. Predicate is
Hypothesis propositional function
Conclusion
"x is greater than 4"
Iftbe wind blows from the north-east then it snows
Subject: x
p : The wind blows from the northeast
Predicate: "is greater than 4" (property of statement)
q : It snows
P(x) :"x greater than 4"
p-+ q
where x is the variable and p is the predicate "is greater than
Q. To ,ei tenure as a professor, it is sufficient to be world
4"
ftunOUS.
Assign a value to x and P(x) becomes a proposition.
If you are world famous then you can get tenure as a
professor. P(x) is also called the value of propositional function at x.
p: You are world famous P(x) denotes x>3, what are truth value of p(x) and p(l)
q : You can get tenure as a professor P(4), setting x = 4, 4>3 is True.
p-+q P(l), setting x = 1, 1>3 is False.
Q. Tl,e tlutomated reply cannot be sent when the file system is • Propositional logic is not sufficient to express the meaning of
. j,,IL [conclusion is statement before when] statements in mathematics.
p : The automated reply can be s_ent. • Predicate logic is more powerful type of logic .
q : The file system is full. • Predicates are also used in verification that computer
q-+.,, programs always produces the desired output when given
Q. JlJIM is either smart or honest but Ram is not honest if he is valid input. The statements that describe valid inputs are
JMart. preconditions and the conditions that output should satisfy
P: Ram is smart when the program has run are called post condition.
q: Ram is honest temp= x
x=y
(pvq) A (p-,0
Q. is muut is necessary and suflkient for Ram to be
JlJUI,
y = temp
lwnot. For precondition, we need to express that x and y have
P: Ram is smart particular values before we run the program. For precondition we
q: Ram is honest use the predicate P(x, y) is statement where x = a and y =b . As we
' want to verify that program swaps the values of x and y, fOT post
!
i· . -_ _ J>H<l
_ _ _ _ _ _ _ __
Insights on Discrete Structure I 17
J 1' I lt.Jipa on Discrete Structure
r .
condinon we use
Q(x y) where Q(x y) is statement x =bandy==
, ,
a. To verify, suppose that the precondition we use ~(x, y) statement
· true In 1st ·step temp= x, after this step we know
Examples
Q. Let p(x) be "x2>10", what is the truth value of l:fx P(x)
x=aand y= b 1s . ,
nd
x = a, temp = a and y =b. after 2 step, x = y we know x = b, temp i. The set ofreal number (Ans. F)
\
= a, y = b. Finally after 3rd step, ,ve know th~t-x = b, temp = a and y ii. The set of positive number not exceeding {1, 2, 3, 4}
=a.After this program is run the post cond1t1on Q(x, y) holds, that (Ans. F)
is, the statement "x =bandy= a" is true. = p(l) A p(2) A p(J) A p(4)
=FAFAFAFAT
Quantifiers
=F
Quantifier defines the quant~~ or quantifi~~tion.
Quantification is a way to create a propos1tton from a propos1ttonal iii. Let set of real number in the interval /10,50} (Ans. T)
function. It expresses the extent to which a predicate is true over a Q. Let Q(x) be the statement 'x<2 ', what is the truth value of
range of elements. the quantification l:fx Q(x) where domain consists of all
real numbers.
Two types of quantification
l . Universal quantification Q(x) is not true for every real number x. Q(3) is false, that is
2. Existential qualification Q(3) is a counter example of statement Vx Q(x). Thus Vx
Q(x) is false.
Universal quantification
Existential Qualification
Universal quantification tells us that a predicate is true for
every element under consideration. The universal quantification of Existential quantification tells, us that. there is one or ~ore
P(x) for a particular domain is the proposition that asserts that P(x) element under consideration for which predicate is true.
is true for all values of x in this domain. · Ddmain specifies the _The existential quantification of P(x) is the statement "There
possible values of the variable x. is an element x in the domain such that P(x) is true." It is denoted
The universal quantification of P(x) for all values of x in the by 3xP(x).
domain is denoted by Vx P(x). 3xP(x) is true when P(x) is true for one or more x in the
domain.
VxP(x) is true when P(x) is true for every x.
VxP(x) is false when there is ax for P(x) is false. An element 3xP(x) is false when P(~) is false for all values of x in the
domain.
for which P(x) is false is called a counter example of Vx P(x). If the
domain is empty VxP(x) is true for any propositional function P(x), The element for which P(x) is true is called a witness -0f
since there are no counter example in the domain. 3xP(~). If the ~omain is ~mpty 3xP(x) is false for any propositional
function P(x) smce there 1s not witness in the domain.
When all elements in domain can be listed as xi, X2, X3, . · · '
Xo, the universal quantification VxP(x) is same the conjunction. 3 is called existential quantifier
Negation of 3x(x == 2)
2 4. Every mail message larger than •one megabyte ,will be
compressed.
== ~x(x2== 2) ·
Let x be mail message.
==3x--(x2 == 2)
Let y be megabyte.
== Vx(x2 :f; 2)
Mail message x is larger than one megabyte. i. e.
Resbicting the domain of a quantifier S(x, y)
1. Vx>O (x2>2) ¢:>Vx (x>O - x2>o) Message will be compressed. i. e. C(x)
2. Vy:#) (y3 = 0) is same as Vy (y = O - y 3=,:0) \ix (S(x, y) - C(x))
3. 3z>O (r= 2) is same as3x(z = 0Az2= 2) 5. Consider the statement
Tr~slate into logical equivalence · "alt lions are fierce."
1. Every student in this cla~s has studied calculus. "Some lions do not drink coffee."
Here, P(x) : x is lion.
Domain = aU student. Q(x) : x is fierce
For every student in this class, that student has studied Vx (P(x) - Q(x))
calculus.
3~(P(x)A-. R(x))
Let x be the variable, so that for every student x in this class,
3x(Q(x)A-. R(x))
x has studied calculus.
~§Ilk.Ji
Nested quantifiers valid if the truth of all its premises implies that the conclusion is
1) 'v'x'v'y (x + y = y + x) . true.
+y- y+x An argument form in propositional logic is a sequence of
For every x and for every Y, x -
compound propositions involving propositional variables. An
2) Vx3y(x + y = 0)
argument form is valid if no matter which propositions are
For all real no. x, there is a real no. y such that x + y = 0
substituted for th~ propositional variables in its premises, if the .
Let Q(x, y) denote (x + y = O). What is truth values of premises are all true, then the conclusion is true.
3)
- t· n3y\/xQ(x y) and \/x3yQ(x, y). where domain
quant1 61ca 10 ,
In other words, an argument form with premises p 1, p 2 , • •• ,
consist of all real number.
Pn and conclusion q is valid if and only if (p 1A p2A · · · A p 0 ) - q
3y\/x Q(x, y) is False is a tautology.
\/x3yQ(x, y) is True Validity is the quality of being logically or factually sound;
why? soundness or cogency. It is the state of being acceptable.
3 \/xQ{x, y) means that "There is a number y such that for
1.8 Rules of Inference
y
every real number x, Q(x + y = 0). II w h'
.1ch 1s
. 1a
"'Ise.
Rules of Inference
\/x3yQ(x, y) means that_"For all rea~ no. _x, ~ere is a real no.
y such that Q(x y) that 1s x + y = 0. which 1s true.
1
An argument is a sequence of statement that ends with a
' ' conclusion. The argument is valid if the conclusion (final
Statement When True? When False?
statement) follows from the truth of the preceding statement
For every pair (x, y), There exists a pair. x, y (premises). Rules of inferences are templates for buil~ng valid
\/x\/yP(x, y) ,
P(x; y) is true. such that p(x, y) is false. arguments. These will be the main ingredient needed in formal
\/y'v'xP(x, y)
proofs.
'v'x3yP(x, y) For every values of x, There exists a x sub that
Example:
there ·is a y such that for for every y, P(x, y) is
P(x, y) is true. false 'If you have a current password, then you can log onto the
network. '
8
.3xv'yP(x, y) There exists a x such For every x there exists
Let p represents "you have a current password."
that P(x, y) for every y, y such that P(x, y) is false.
q represents "you can log onto the network."
3x3yP(x, y) For some pair (x, y), For all pairs {x, y), P(x, y) - p ➔ q
P(x, y) is true. is false. p
3y3xP(J.C, y) ~
q
1.7 · Arguments, Argument Forms and Validity ___.. ((p- q)Ap) - q is tautology.
Definition:
An argument in ·propositional logic is sequence . of
propositions. All but not the final proposition are called premlS~
and the final .proposition is called the conclusicm. An a r ~
Insights on Discrete Structure I 25
24 I Insights o~ Discrete Stru(ture
Premises
S.N. Rules of Tautology Name
Arguments
inference
' 4. pvq
~
q
[(pvq)A -.,] ...:.+ q Disjunctive
syJlogism
p-+ r r
-- p-+
Insights on l!>iscrete-Sttucture I 35
34 f Insights on Discrete Structure
Q. Lions are dangerous animals. There are lions. Therefore
there are dangerous animals. formal proof is rigorous but so can be a proof that does not rely 0 0
L(x) : x is lion. symbols! Formal proof example (rules of inference to build
arguments)
D(x) : x is dangerous animals.
Hypothesis : 1.11.1 Proof Methods
Vx (L(x) -+ D(x)), 3xL(x) A proof is a valid argument that establishes the truth of a
mathematical statement, using the hypotheses of the theorem, if
Conclusion:
any, axioms assumed to be true, and previously proven theorems.
3x.D(x)
Using these ingredients and rules of inference, the proof
S. N. Steps Reasons establishes the truth of the statement being proved.
I. Vx(L(x) -+ D(x)) Hypothesis We move from formal proofs, as seen in the previous
2. L(a)-+ D(a) Universal instantiation on (1) section, to informal proofs, where more than one inference rule
may be used at each step, where steps may be skipped, and where
3. 3x(L(x)) Hypothesis axioms and rules of inference used are-not explicitly stated.
4. L(a) Existential inst~ntiation on (3) Some Terminology
5. D(a) Modus ponens on (3) and (4)
• Definition : A precise and unambiguous description of the
6. 3xD(x) Existential generalization on (5) meaning of mathematical term.
• Theorem: A statement that can be shown to be true using
1.11 Informal Proofs and Formal Proofs vigorous (strong) mathematical reasoning.
I The steps _of the informal proofs are not expressed in any
formal language as e.g. propositional logic. Steps are argued less
formally using English, mathematical formulas and so on. One
A statement that can be shown to be true (sometimes referred
to as facts or results).
Less important theorems are often called propositions.
must always watch the consistency of the argument made; logic • Lemma : A lemma is a less important theorem, used as an
and its rules can often help us to decide the soundness of the. auxiliary result to prove a more important theorem.
argument if it is in question. We use informal proofs to illustrate It is used as an auxiliary result to prove a theorem. It is
different methods ofproving theorems. stepping stone to prove theorem.
A formal proof of a conclusion q with given hypotheses pi, • Corollary: It is a theorem proven as. an easy consequence of
a theorem.
P2, p3 . . . ; Pn is a sequence of steps, each of which applies some
inference rule to hypotheses or previously proven statements • Conjecture : A conjectw:e is a statement that has been
(antecedents) to yield a new true statement (the consequent). proposed a true statement. If proved later then it can be used
as a theorem but it may be false
A formal proof. demonstrates that if the premises are tr11e,
then the conclusio~ is true. A formal proof is based simply on
symbol manipulation (no need of thinking, just apply rules). A
,.hypotheses (or premises), previously proven theorems and Theorem (use direct proof)
definitions. Rules of inferences, together with definition of l. If n is an odd integer, then 0 2 Is odd.
t~rms are used to draw conclusions from other assertions Let p(n) : 'n is an odd integer • is true
'
tying together the steps of a proof.
'
then,
Three methods of showing statements of the type p -. q are n = 2k + I (from definition)
true: then,
1. Direct proofs: Assume p is true; the last step establishes q is n2 = (2k + 1)2
true. If n2 = 4k2+ 4k ~ I
2. Proof by Contraposition: Uses a direct proof of the 2
n ~ 2(2k2 + 2k) + J
contrapositive of p - q, which is -iq - . -,,. That is, assume 2
here, (2k + 2k) is an integer, so,
-iq is true; the last step established -,, is true.
2(-2k2 + 2k) is even
3. Proof by Contradiction: To prove that P is true, we assume .
n2 is odd.
-,p is true and reach a contradiction, that is (r A ,-) is true for
some proposition r. In particular, to prove (p -. q), we Definition
assume (p -. q) is false, and get as a consequence a Anb2integer is a perfect square I·f the is
= . an integer
· b such that a
contradiction. Assuming that (p -. q) is false = (-,, v q) is
false= (p.A'""'<l) is true. Theorem
4. Formal and Informal Proof 2. If m and n are both erfect
perfect square. p square the mn is also a
A fonnal direct proof of a conditional statement p ~ q
works as follows: Let m and n be perfect s u h
t such that, q are, t en there exist integers s and
Assume p is true, build steps using inference niles, with the
final step showing that q is true. m= s2and
In infonnal direct proof, we assume that p is true, and use n = t2
axioms, . definitions and previous theorems, together witb mn = s2t2 = (st)2
rules of mference to show that q must be true. . Hence, R.H.S, is
p f by contrapos1t1on. ' . qi O such that r = p/s . A real number that is not rational is called
1.11.2.1 roo : d + 2 is odd, then n is odd. irrational.
l. If n is an mteger an 3n .
~ ) is odd then n is odd) 1. Prove that the sum of two rational numbers rational.
p-+q (if 3n , 2
.f . not odd then (3n + 2) is even) If r and s are rational numbers then to prove is r + s is also
-.q -+ ....,, (l D l S rational
let n is even, Let r = p/q and s = t/u where p, q, t, u are integers such that q
n=2k to and u i 0
now, 3n + 2 == 3*2k + 2 r + s = p/q + t/u = (pu + qt)/qu
=6k + 2 qutO
==2(3k + 1) Hence, r + s is rational (proof succeeded by direct proof)
Thus (3n + 2) is even . r 2. Prove that if n is an integer and n 2 is odd,
The negation of conclusion of conditional statement d1~~ I~ Then n is odd.
·mnal con 1non
that the hypothesis is false, so, the one.- Here, we first attempt by a direct proof. Suppose n 1s an
statement is true. rs integer and n2 is odd.
Prove that if n = ab where a and b are positive lntege n
2
= 2k + I
2.
then ~ ✓
nor~ ✓n n = ±v'2k + 1
Here, The above equation is not useful to show n is odd. Because
lf (n = ab) then (a~ ✓nor ~✓n) this attempt to use a direct proof did not bear fruit, we next
The contrapositive of p-+ q is~-+ --P have a proof by contraposition.
-,q - ,,
So,
~ means (a >✓n V b >✓
n)
Insights on- Discrete Structure I 41
40 I Insights on Discrete Structure
=6k + 2
if n is not odd then n2 is not odd
2· n = 2(3k + l)
if n is even then n is eve
Its even
~ n= 2k
2 Hence, our assumption came to wrong.
n2 = (2k)2 = 2k(2k) even
So, if 3n + 2 is odd then n is odd.
d. tion
111 2 2 Proof by contra ic . Q. Prove if ti is even then a is even (by contraposiave)
· • • ove that a statement p 1s true. SqppOSe
Suppose we want tod~\ion q such that""" p -+ q is true, only For p _. q the contrapositive is """q _. 7'
that we can find a contra ic So, the contrapositive g the given question is
when p is false that is p is trUe. .
If a is odd then a 2 is odd
For (p --+ q) we use (pA"""q) -+ F
a= 2k + l
r,; ti (prove by proof by contradiction)
1. v "' is irra ona1 a 2 = 4k2 + 4k + l = 2(2k2 + 2k) + 1 which is odd' (see the
difference in proof by contrapositive are proof contradiction)
Let ./2 is rational.
ented as a ratio of integer a and b such Hence proved.
Then 2 can b e rePres
d b have no common factor. If a2 is even then a is even.
that b i o. Where a an
a = 2c where. c is any integer
./2 = alb
2b2 = (2c)2
.,/zb=a
b 2 = 2c2
Squaring both side,
2b~=a
2 1.11.3 Vacuous proof
a2 is even number, so a is also even p _. q is true when p is false . If we can show that p is false
then we have a proof , called vacuous proof.
a=2c
We can quickly prove that a conditional statement p -+ q is
= :4c
2 2
Again, 2b true when we know that p is false, because p -+ q must be true
2
b2 = 2c when p is false. Consequently, if we can show that p -is false, then
b2 is even, b is even we have a prnof, called a vacuous proof, of the conditional
statement p _. q.
"'.b~
Both a an b are even, 2 divides both a and b . ..fi. = a/b.
a and b have no common factor it means 2 does not ~~de Q. Show that the proposition P(O) is true where the domain
both a and b. Because""" p leads to contradiction that 2 diVl c~nsists of the integer numbers and P(n) is "If n ~ 1 then
,. > n." Note: vacuous proof: when p is false p -+ q is
both a and b. so, """P is false. 2 is irrational. true, regardless of the yalue of q.
2. H 3n + 2 is odd, then n is odd. Solution:
Let us assume that n is even and,3n + 2 is odd. Note that P(O) is "If O > 1, then 02 > O." We can show P(O)
Then, n = 2k using a vacuous proof, because the hypothesis O > I is false.
Hence P(O) is automatically true.
3n + 2 = 3(2k) + 2
Insights on Discrete Structu,e I '3
42 I Insights. on Discrete Structure
1
1.11.4 Trivial proof . . 2
n = 41<2 + 4k + I
A proof of P - q that uses the fact that q 1s true
, .
1s called
2
n = 2(2k2 + 2k) + I
trivial proof.
q- p
By showing that q is true, it quickly follows that p ~ q rnus1
• of p _ q that uses the fact that q ts true is n = 2k
also be true. A proo f
n 2 = (2k)2 = 4k2
called a trivial proof.
n 2 = 2(2k2)
Q. Let P(n) is 'If a and b are positive ~ntegers with a ~ then
a• ~b• where domain consists of all integers. Show that p(O) if n is even, then n2 is even
is true. (proof by contraposition)
The proposition P(O) is ··If a~~ then a ~
0
?o"
Because "' a0
Q. Show that these statement about integer n are equivalent
bo = 1, the conclusion of the given cond1t10nal statement is pl : n is even
true. p2: n-1 is odd
Thus p(O) is true. p 3: n2·1s even
1.11.5 Proof by equivalence pl --+ p2, p2 - p3 and p3 - pl
To prove p - q show that p--+ q is true and q--+ pis true. · F~r pl--+ p2
The validity of this approach is based on the tautology Let n= 2k
(pH q) H [(p--+ q)A(q--+ p)] then n-1= 2k-1=2k-1+1-1=2(k-l}+ l=even+ l=odd
Example: Prove that if n is a positive integer, then n is odd il Forp2- p3
and only if n2 is odd. . Let n-1=2k + 1
Sometimes, a theorem states that several propositions are Then n= 2k+2
equivalent. Such a theorem states that propositions pl, p2, 02
= (2k+2)2 = 2(2k2 + 4k + 2)=e;ven
p3 ........ po are equivalent. This can
be written as 'pl+-+ p2+-+........+-1 2
po p3 --+ Pl i.e. if n is even n is even is proved earlier.
which states that all propositions have the same truth values Hence these propositions are equivalent
and consequently for all i and j with . l ~ i ~ n and 1 ~ j ~ n, pi and pl .H p2 H p3 - --- +-+ pn)H{pl - p2)A{p2-+ p3)A /\
pj are equivalent. (pn--+ pl) . ...
This can ® proved as following v (pl+-+ p2+-+ ........+-1 l.11.6 Proof by cases
pn)+-+{p 1 -+ p2}A{p2 --+ p3)A ..: .......... A(pn --+ p 1)
&, 11 Sometimes it is difficult to use a single argument that holds
Q. Prove that ''If n is an integer, then n is odd iff n2 is odd''. 1 or a cases. ·
p: n is odd
Proof by cases uses the following equivalence:
q: n2 is odd
[(pl Vp2 V· ··Vpn) --+ q]
q)]
= [{pl - q)A(p2 - q)A· ··A(pn -
p --+- q [T]
n = 2k + I Example: Prove that if n is integer then ni 2: n.
Case (a): Suppose k + 1 is a prime. Then we are done. e or an arbitrary positive integer k, 1· e
I + 2 + 3+ .....+ k = k(k + 1)/2 . · ·
Case (b): Suppose k + 1 is a not prime. Then by the fact
Now, we have to show p(k + l) is tru .
stated above, there e~ist integers a and b with 2 :5 a, b ::; i I 2 e, t.e.
such that + + 3 + ....k _+ (k+ l )=(k+·I)(k + 2)/2
L.H.S. =I+ 2 + 3+....k+(k + I)
k+ I =,a· b.
= k (k + J)/ 2 .
+ (k + l) (inductive hypothesis)
By the strong inductive hypothesis, since 2 :5 a, b :5 k, both 1
and b are the product of primes. Thus k + 1 = a · b is tlx = k (k + l) + 2k + 2/2
product of primes. = k (k + I) + 2(k + l )/2
Mathematical Induction =(k+ l)(k +2)/2
From the · · I ·
Mathematical induction is a means of proving a theorem ~- . . pnnc1p e of mathematical induc . .
all positive integers n. tion, p(n) 1s true for
showing that if it is true of any particular case it is true of the nex:
case in a series, and th<,m showing that it is indeed true in ol'.i 2. Conjecture a formula for the su
particular case integers. Then pr.,. m of the .first n positive odd
, vVe your COnlj"ectu •
induction. re US,ng mathematical
Suppose we have some statement P(n) and we want u
demonstrate that P(n) is true for all n. The sum of the fi t ··
are rs positive odd integers for n == l 2 3 4 5
To prove that p(n) is true for all positive integer n where p(o , , ' ,
is a propositional function then we do two steps l == l
1+3=4
Basic step: we verify that p(O) or p(l) is true
1+3+5 = 9
Inductive hypothesis: we assume that p(k) is true I + 3 + 5 + 7 = 1.6
Inductive step: we prove p(k + I) is true I + 3 + 5 + 7 + 9 = 25
We show p(k) -+ p(k + I) is true for all positive integer! Hence the su f h
assuming p(k) is true (Inductive hypothesis) I + 3 + 5 + m o t e fir!t n positive odd integers is n2 i.e.
.. . (2n-l) = n
As rule of inference, this can be stated as, Let p(n) denote the proposition th ..
[p(l) A Vk(p(k)-+ p(k + I)]-+ Vnp(n) . positive odd integers is n2 at the sum of the .first n
. ua/ity fior harmonic numbers. The harmonic 9. If S is a finite set with n element where n is a non-negative
7. An ,neq . med b H · = 1 + 112 + integer, then S has 2" subsets.
numbers H), J = 1, 2, 3, ...•.. are deft 1 1
Let p(n) be the proposition that a set with n elements has zn
1/3+..•... + 1/j
subsets.
Show that H/ ~ 1 + n/2 where n is a non-negative integer.
Basis steps : p(O) is true, because 2° = l subsets which agrees
Solution: with the fact that a set with zero element i.e. empty set has
Let p(n) be the proposition that H/2:1 + 0/2 only one subset namely itself.
Basis step, Inductive step : we assume for non-negative integer k that
every set with k element has 2k subsets. p(k + l) is the
H12: l
statement that every set with k + l elements has 2" + 1 subsets.
l 2: 1
Inductive step : assume p(k) is true H/ 2:1 +k/2 for a non· Let T be a set with k + 1 elements, then we can write T =S u
, I
negative integer k. . {a} where a is one of the element ofT and S = T-{a}
1
Then p(k + 1) is the statement H 2k+ 2: l +(k + l )/2 (ISi = k) subsets ofT ean be obtained in the following way
Now from definition of harmonic number For each subsets of there are exactly two subsets of T,
' ~
H/+ 1= 1 + l/2 + 1/3+ + (1/2")+(11:!"+l)+(l/2"+2)+ ... +l/2 namely, X and XU {a}, these constitute all the subsets of T
= H/+ (112"+1) + (112"+ 2) + ... + 1/2k+I and are all distinct.
?_ (l+k/2) ·+ (1/2"+ 1) + (li2"+2) + .. .+1/zk+I · But there are 2k subsets of S, so there are 2.2k = 2k + 1 subsets
ofT.
2: (1 +k/2) + 2"*(112"+!)
Insights on Discrete Structure I 53
52 I Insights on Discrete Structure..
S -{
- a, b} T=={a,b,c} 1.13 Consistency and Completeness of the.System
X == [ {} ' {a} ' {b}, {a, b}] valid Formula ,
T == {a, b, c}
Valid formulae are those formulae which are valid under all
valuations (pv-.p) is valid formula. Valid propositional formulae
SubsetofT U{c} {b}U{c},{a, b}U{c}) are caUed tautologies.
== [ {} ' {a}, {b} , {a, b} ' {} U {a} , {a} '
Satisfiable Formula
.zation of proof techniques
Eumm
S Proof Approach to Remarks These can be made true under at least ~ne valuation, thou~
not necessarily all valuations. An example of satisfible formula ~s
N.· Technique prove p-+ q
pvq which is true at p = T and q = F. Every valid formula 1s
satisfiable.
1. Exhaustive Demonstrate p May only be used for
Unsatisfiable Formula
proof -+ q for all finite number of cases
possibilities The unsatisfiable fonnulas come out false under all valuations.
2. Direct proof Assume The standard approach S~undless and Completeness of the system
p, . t try
deduce q usually the thmg o •
The axioms are all valid and each inference rule has the
following properties: If both premises are valid then the conclusion
3. Proof by Assume ~q, Use this q i(. as . a is also valid. It follows this, that, only valid formulae can be proved
contraposition derive-,> hypothesis seems to give in a sound logical system.
more ammunition then q
would. If (j) can be proved in a sound logical system then <I> is valid.
If there is a proof of (j) then <I> is called a theorem.
4. Proof by Assume P-"~q, Use this when q says
contradiction deduce a something is not true The soundless of a logical system is expressed as
contradiction If (j) is a theorem (if (j) can be proved), then cj> is valid.
5. Vacuous proof Show p is false Give an example to inake The completeness of the system is expressed as
pis false, in p-+ q.
If cj> is valid then (j) is a theorem ((j) can be proved)
6: Trivial proof Show q is true Give an example to make 1.14 Method of Tableaux
q is true.
The main problem with the axiomatic system. we have
described is that although it is relatively easy to check that a proof
7. Proo_f by cases Demonstrate p May only be used ~for of a fonnuJa is correct, it is much harder to can:;,truct a proof. We
- q for all cases known cases. need intuition to know which axioms to pick and when to apply
LL----:-+-__:_--+-~-:-------:HPJ
8. Proof by To prove pHq (p1HP2Hp3. .... )
- modus ponens. It is even . worst, if you do no_t know whether a ·
fonnula can be proved or not.
equivalence show (p -+ H(p1 -+ P2)A(P2 -+ P3 .. ...
It is the method to prove the satisfiabilty of a s'e t of fo~ula.
q)A(q-+ P) · A(pn-+ Pt)
B
/\-.s
l. First of al\, list the formulas
C -C
'1>1 -,c -,c
~ D D
q,3 4. After each step, we check for satisfiability along branches.
Thus, the left- most branch contains a formula and its
· negation, namely, C and -C.
There are, the left-most branch is not ·satisfiable. So, we can
'Pm . . l close-off this b~ch and we will not analyze this
Starting from any formula oi, apply the denvat1on ru e, say further.(indicated by bar)
2.
q,;= ca--c) Note that we will not apply further derivations rules to it.
We apply the previous steps along each branch that is not yet
q, l
closed off until either
q,i i. Every branch is closed or
ii. All non-literals along each unclosed branch is checked.
Then in case (i), the initial set q, 1, q, 2 , ..... q, m is not
satisfiable. On the other hand, if (i) fails that is some
branch is not closed off but (ii) holds, then the set of
formulas q, l, q, 2, . .... q, m is satisfiable.
B
A -.a
5. From open branch we can check for validity by valuation.
For all literals p we define valuation Vas
V(p) = T ifp appears along the branch
C -C rt 1 = F if p appears along the branch
Now' along each branch of the tree constructed hithe o,
3.
repeat the previous steps, say cl>;= (-CAD) =Tor F if both p and 7> not appears in branch
Q. Consider the set ; ={(PA-.Q) -+ S, -.Q v-,R; PAT}
4>1 I •
A tableaux for q,
A tableau for --. cl>- This means ~hat any valid formula can be pr~ved
;<:)A using the tableau method showing completeness is usually the hard
part to check for most inference systems.
Corollary:
A71-i
-,iQ pp
If a completed tableau for a formula cl> is open, then cl> is
satisfiable. If a completed tableau for cl> is closed, then cl> is
1 P
A T (5)T (6)
p --.Q --.R
unsatisfiable.
By following corollary and the two theorems we know that
the tableau method is both sound and complete.
·
I T (3) (4) .
Definition:
<•) c2) r An argument
\ Al
For open branch (4) A2
V(T)=T
V(P)=T An
V(R)=F B
V(S)=TorF is said to be valid if the conclusion B is a tautological
V(Q)=T consequence of the premises Al , A2, .. .. ...An
Then Now, {Al, A2, . ...... An}=B
~B
C(x): x is student in this class
R(x): x has read the book
~P P(x): x has passed the first exam
\ Hypothesis:
p
3x(C(x) "--.R(x))
/
~
--.p (QAR)
Vx(C(x) --+ P(x))
Conclusion:
\ 3x(P(x) /\--.R(x))
Q S.N. Statement Reason
R l. 3x(C(x) A ---R(x)) Hypothesis
~ 2. C(a) /\ --.R(a) Using Existential Instantiation in 1.
-Q s
3. \fx(C(x)--+ P(x)) Hypothesis
~ 4. C(a)--+ P(a) Using Universal Instantiation in 3.
--.g -.A
~A
--.R
5.
6.
C(a)
P(a)
Using Simplification in 2.
Using Modus Ponens in 4 and 5.
Every branch closes hence the argument is ivalid. 7. --.R(a) Using Simplification in 2.
8. P(a) /\ --.R(a) Using Conjunction in 6 and 7.
9. 3x(P(x) "--.R(x)) Using Existential generalization in 8 .
3. Using resolution prin~iple, prove that the hypotheses "t .get wet" imply that "Sita does not wet." (071 Bhadra]
today is Tuesday then I will have a test in. Discrd Solution:
Structure or Microprocessor". "If my Microprocess#_ r: It is raining
teacher is sick then I will not have a test P u: Sita has her umbrella
Microprocessor." and "Today is Tuesday and ,: w: Sita gets wet
Microprocessor teacher is sick. " lead to the conclusion lkl
hypothesis:
"I will have a test in Discrete Structure". {072 Ash~
--rvu, """'l.lV-w, rV-w
Solution:
Conclusion:
Propositions:
-w
p: Today is Tuesday
64 I Insights on Discrete Structure Insights on Discrete Structure I 65
Putting in clause fonn 5. J(a) Using simplification on 3.
hypothesis
cl:-,vu 6. W(a) Using modus ponens on 4 and 5.
hypothesis
c2:---uv-'W 7. C(a) Using simplification on 3.
hypothesis
c3:rv-'W 8. W(a)/\C(a) Using conjunction on 6 and 7.
negating conclusion
c4:w
from c \ and c2 9. 3x (W(x)/\C(x)) Using existential generalization on
c5: -,rv-.w 8.
from c3 and c6
c6:-""'W
from c4 and c6 6. Let Q(x, y) denote (x + y = 0). What is truth values of
c7: Y quantification ~ lfxQ(x, y) and lfx~Q(x, y). /2076
hence the argument is true. Baisakh, Back/
' . rules 0 r inference to show
rgu1ttent using 'J • Solution:
5. Construct an a esis "all 1ttovies produced a movie art
that the hypoth duced a ,,.0 vie about coal Here,
..1-J.,1 John Sayles pro .
wonue•J-· . "There is a wonderful mo\llt Q(x, y) denotes x + y = 0
. ,, • ply the cone1uswn,
miners ilft . " You are required to show each step 3yv'xQ(x, y) means that " There is a number y such that for
about coal miners. h steps be/ore you come to tht every real number x, for Q(x, y) i.e. x + y = 0.
and give reasons for t ose th . /071 Maghj
desired conclusion from the hypo esrs. It is false when for all value of y, there exists a x such that
Q(x, y) is false.
Solutwn:
J(x): x is movies produced by Jolin Sayles It is true when there exists a y such that Q(x, y) is true for
every x.
C(x): x is movie about coal miners.
v'x3yQ(x, y) means that "For all real number x, there is a
W(x): x is wonderful movie. real number y, such that Q(x, y) i.e. x + y = 0 .
Hypothesis: It is true when for every value of x there exists a y such that
v'x(J(x) .- W(x)), 3x(J(x)/\C(x)) Q(x, y) is true.
Conclusion: It is false when there exists ax such that for every y Q(x, y)
3x(W(x)/\C(x)) - is false.
S.N. Statement Reason ~ 7. Using mathematical induction technique, prove· that the
following statement is true: 3 + 3*5 + 3*51+3*5" = 3(5"+_
1. v'x(J(x) .- W(x)) Hypothesis - 1)/4 whenever n is nonnegative integer. {072 Ashwin]
2. 3x(J(x)/\C(x)) Hypothesis
---
Using existential instantiation on
Hints:
p(k+ 1) =3*(5k+l_l)/4+3*5k +I
3. J(a)/\C(a)
4. J(a)- W(a)
2.
· ---
· ftonon 1.
Using universal mstantla
= (3*(5k +1-1) + 12*5k +1)/4
= (l 5*(5k + 1)-3)/4
8.
if
Show that {A /\ C, (·.,A v B~ tableaus. Prove that " If nii 9. Use mathematical induction to prove that 1' + +If" + is
divisible by 57 for every non negative integer n. [2076
2 1
b/0
10/ 1 00/1 11/1
The SR trID fl 00
Let M = {I, 0, S, f, g, cr } be a FSM. The transition dia~
s R Q
of M is a diagraph G whose vertices are the members S. an aJtl1
l 1 Not allowed
designates the initial state. A directed edge (crl, cr2) exist in G.1
there exists an input I with f(a 1, i)= cr2. In this case, if g( o 1, i) " 1 0 l
The edge (cr 1, a2) is labeled i/o. 0 1 0
0 0 l ifs was last equal to I
Definition 0 ifR was last equal to I
Let M = (I, 0, S, f, g, a) be a FSM. An 1/P string for M~
string over I. lnslahts on Discrete Structure I 75
<Jo 01 <Jo 1 0
01 02 CJo I 0
I 02 <Ji <Jo I 0 a/I
b/0
a/1
5. An initial state aE S
A = (I, S, f, A, a) a
Exm,,ple
b
Transition diagram of FSA Yes
A = (I, s, f, A, a ) where Is the string ahhahha accepted by Fjn. b
I= {a, b}, s = { Oo,Ot,OJJ . A= { <J2}
a Go and f is given by table below a b
F
s/1 a b b
<Jo <Jo a,
<J1 <Jo <J2 a
V = {0, 1} is a binary alphabet Language is set of strings all of which are taken from v•
v= {a, b, ....z} is a set oflower case letter.
------=----=----==-==-=--------___,,,
l tnsilhtS
80 on Discrete Structure
Insights on Discrete Structure I 81
• bset of
A fonnal language over v is su
v•
A must include at least one non terminal symbol whereas
L~V• B can consists of any combination of non terminal and
V = {0, 1} terminal symbols.
Let,
V°= {}
V 1 ={0,l} N= { a, S)
V2=VUV T = {a, b}
= {0,l}U{0,l} P = {a - ba, a - as, s - bs, s - b}
= {00,01, 10,11} Then G = (N, T, P, CJ) is a grammar.
I
the language. Types _of grammar (Chomsky hierarchy of grammar)
A grammar defining formal language I is a quadtruple 1. Unrestricted grammar (Type O)
G = (N, T, ~ S) If there is no restriction in the every production of the
grammar, it is called unrestricted grammar.
N = set of non terminal
Production rule
T = set of terminals
a-JJ
R = set of production Where,
S = start symbol ae(NuT)*
T is alphabet J}E(N UT)*
A grammar is a way to specify the set of all legal senten¢ It is recognized by Turing machine
of a language. 2.
Context Sensitive Grammar (Type t)
We _write G = (N, T, P, cr ). A production (A, BEP) ~ If every production is of the form
usually wntten A - B aA J} -. ayJ}
-
12~;;.;::-;;:::=:::=--:--------__,
82 I lnsllhts on Discrete Structure
Insights on Discrete Structure I 83
. the context of a and~ ) Starting symbol S
(we may rep lace A with rm
Grammar
a, ~E (NUT)* Mathematical model
AEN this grammar is recognized by Unrestricted type o ~ Turing machine
The language generated by
Context sensitive Linearly bounded
Linearly Bounded Automata.
grammar type 1
,~
. automata
3. Context Free Grammar (fype 2)
Push down
If the production is of the fonn Context free
1rrammar tvoe 2
~
- -- automata
A-+ y Regular . Finite
WbereAEN gra~r type 3
- Automata
yE(Nun•
The string a1,3c3 is in L(G) If there is an edge labeled x from S to S' and
It can be show that s-s·
L(G) = {a°b c In= 1,2, .. ..... }
0 0
If S is an accepting state let G be the regular grammar.
Q. Write the regular grammar given by FSA !liven below G= (N,T,P,cr)
b Then set of strings accepted by A is equal to L(G) .
b
Reverse case
a Given a regular grammar G, we want to construct a FSA to
that L(G) is precisely the set of string accepted by A.
b
b
I.
-s----.1 A B
{ cr} {c} { cr}
{C} { ~} {C, F}
{C, F} { ~} {C,F}
b
b
Q
a
I?
Equivalent OFA
90 I Insights on Discrete Structure
lnslpts on Discrete structure I 91
>
....
,f trings acCepted b11
.., the FSA show11
Q. Let L be the set ;S; that accepts the strings b b
below construct a
LR= {Xn •• •• xdx, ......Xn EL}
b
a
a
. above FSA and make
all arrows ID . 03 the starting
Reserve . tale The result 1s a NDFSA that g( {If,}, b)={lf,}
state and OJ the afceptmg s .
accepts L
R
Non Deterministic Finite State Automata
b A non-deterministic finite automaton is a generalization of a
a finite state automaton so that at each state there might be several
possible choices for the ..next state' instead ofjust one.
Convert NDFSA to DFSA
b
a
a
b
Change into DFSA .
E(o3).={o3}, E(o2) = {oi}, E(o,) = {01}
Transitions
(03, b, 03). (cr1, a, 01)
(03, b, 02) ( 01, ~ 02)
(o 1, b, cr3)
g( {(cr3}, a)= cl>
b
g( {(cr3}, b) = E(cr3)UE(o2) ={03, 02}
g( {(03, 02}, a)= cl>
g( {(o3, o2}, b)::;: E(o3)UE(o2)UE((o1) = {03, 02, oi} ~ Regular Expression and its Characteri~tics
g({(o3, 02; 01}, a)= E(o1)UE(o2)UE((o3) = {03, 02, 01}
. Regular expressions are useful for representing certain set of
g( {(03., 02,.01}, b) = E(o1)UE(o2)UE((o3) = {03, 02. oi} stri
ngs in an algebraic manner. Actually this describes the language
g({t}, a)={t} · accepted by finite state automata.
----------------------:-:=----:
92 I ln#ts,on ~ e .St~cture Insights on Discrete St~ctute I 93
al habet L are the strings ( 1O)* = Any number of copies of IO (including the null
2.
The regular expressions over anh Jat the following hold (}:
{) c u }sue string)
over the alphabet 2, U _' ' b..'... }
1/p symbols)
3. OUO l = The string O or the string OI.
consists of alphabet L - {a, ' mber of L is a regular
t IP and each me . 4. O(OU l )* = Any string not beginning with 0.
1. The empty se
5. (O* 1)* = Any string not ending with 0' .
·expression. . then their concatenation
If a and p are re gu
lar expressions
. 6. L* = {O. l }*= (0 + 1)*= { E,0,1,00,0I,10, l I..}
2. lar expression. O* + 1* = {E,0,00,000, ..... }
aP is also a regu . then their union ( a U P) is 1.
If a and p are regular .expressions = {e, 1, 11,111, . ..... } (can it give combination oniy either O or
3
· gular expressions. . . 1.)
also a re . th is the closure (iteration)
If a is a regular expressions en s O 8. O*l • = {E, 0, I, 01 , 001 , 0011, .}(zero never come after 1)
4.
• RE (a) is also RE.
a.• . If a is . . unless it follows from (I) 9. (01)* = {E, 01, 0101, 010101, ... .. . }
Nothing is a regular expression .
5. 1o. 0 1• + l O* =either single 0 followed by any number of l or
through(4). d ti vice versa.
haracterized as languages e med
Regular languages can be c 11. (O+l)*.00
b regular expressions. . . .
Y ed b . gular expression 1s given a A language is regular iff it is accepted by FSA.
Th l guage represent y re ).
e an .f ·s any regular expressions then Ll\l. is . There are three operations on language that the operators of ·
function .L, such that 1 a t regular expression represent.
the language represented by a.
L (IP)= IP, L(a) = {a}, for each a EL These operations are;
1. If a and p are regular expressions then L( ap) = _L (a). L(P) 1. Union:
2.
If O and p are regular expressions The union of two languages L and M de~oted by L + M is
3.
the set of strings that are in either L or M or both
Then
E.g.L= {001,10,111} andM= {E,001}
L(aUP) = L(a)UL (P)
Then,
4. If a is a regular expression
L + M = {E, l 0, 001 , 111 }
Then 2. Concatenation:
L (a*)= L(ci)*
The concatenation of language L and M is the set of strings
What are the strings specified by the regular expression?
that can be formed by taking any string in L and
,
Regular expression is language 1
generatyr •t
1 ge
nerates
. the
co~catenation it with any string i~ M and is denoted by L.M
set of all strings for finite automata. E.g. L= {001,.10,111},M= {E, 001}
(FSA, pumping lemma are langaage.recognizer.) 'Then,
l. 10* = A 'l' followed by any no. of O's including non zero. L.M = {001,10,111,001001,loP()l,) 11001}
The class of languages accepted by finite state automata (i.e. F = FI UF2 [Final states of M]
Transition function of M = o1U0iU {(q, E) - ((q, E) - q2)}
R.L.) is closed under.
Or,
1. Union
F1UF2U{s, e, s1),(S, e, s2)}
2. Concatenation
3. Kleene star 2. Concatenation :
4. Complementation Let Ml and M2 be NDFA. We construct a NDFA M such
5. Intersection that L(M)= L(M 1) - L(M2). The construction is shown in
-B the figure.
Empty string
Sl
-+
Fl
~
-.0
s2
________ si° 7~
F2 __, F
Ml M2 M
M operates by simultaning M 1 for a while and then jumping
non-deterministically from a finite state of M 1 to the initial
state of M 2. Therefore M imitates M2 •
Formally, ·
Accepts the alphabet a
Let,
1. Union: .
· isri( Ml = (S 1, I, f1, St, f 1) or Q1, ,, Q1, F1) or'(Ql, L, ol, ql, Fl)
1
>
_ S' US' 2=union of MI and M2
Set of states ofM -S-
- I · Technique to identify the class of language for finite
- final states ofM2 (F2) automata is pumping lemma.
Final states (F)- . fMl and M2 plus (F 1X{e}X{s2})
Transition S = Umon ° Show that the language
= aqa2rap-{q +r>i,i>
L(M)=L(M1) = aP +'bP L
States of M = states of M I plus s' 1
Since xy2z is not the from a~ therefore xy2z EL. It is
Final states of M:= Final states ofM1 pl~ s' 1 . contradiction. Hence L is not regular.
Transition of M = Transition of M, plus ~FX {e}} X {s,})
Closure properties of Regular Language
F = F1UF2U{(F, e, S1)}
If L and M be regular language. Then following languages
Pumping lemma (fheorein) for Regular Language . are all regular.
.
Pumping lemma is a powerful technique for sh owmg
· certain l. Union : L U M, L + M
language to be non-regular. 2. Intersection: L nM
Statement 3. Complement : N, L and M, i =I,* \L
. t constant n 4. Difference : L\M = L n M
. Let L be a regular language. Then there ext a . w\
(which depend on L) such that for every string win L, such tbat I 5. Reversal LR= WR :wEL
~n. 6. Closure: L*
We can break w into three sub strings 7.
Concatenation : L.M
I. y-:/=E 8.
Homomorphism
2. lxyl~n h(L) = {h(w) I we L, his homomorphism}
3. For all i~, string xy'z is also in L
Insights on Discrete Structure I 99
98 1lnsi&hts on Discrete Structure
9.
Inverse homomorphism a is a homomorphism)
h·'(L) == {wE \ b(w)L, h:1: - J. Design FSA transition diagram that accepts the given set of
string over {a, b}. {2076 Baisakh, Back}
homomorphism
h:r· - 0 • ( alphabet L . 0 ) ,.• Which starts with ab and ends with baa
Solution:
w:a,a2••·····;····•anEL* FSA which starts with ab and ends with ba
h(w) == h(a,) b(a2) .........h(an)
b(L) == {h(w)\wEL}
Example
\etb:{O,l }* - {a, b} • be defined by
h(O)== a b and b( l )== E
now,
h(OOl l)==abab
b(L(lO*l))== L((ab*))
>
.....
a a b
b a
a
b
b
b
a
es the string having the
hat generat
Write a grammar t
3. 4. Design a Grammar to generate Palindrome for Binary
given proP.erlY• .
i b,1 ending with ba Numbtrr. Consider the right linear Grammar G = {N, T, P,
a. String over ia, • /2073 Bhadra/ SJ, where N = set of non-terminal = {A, B, SJ, T = Set ·of
1. b I starting with a Terminal = {a, b, c}, and P consists of the following rules:
b String over I a, 'I
• ding with ba
b} {S - t abAI bbB/ a, A - aA/ bB/b, B - BaB/aaaA).
a. String over {a, en G == (N, T, R. S) Construct the NDFA equivalent to the given grammar.
Let the grammar G be
f 1076 Baisakh, Back/
N =={S, A, B}
Solution:
::{~~}aS\bA, A-+ aB\bA, B-+ aS\bA} Grammar to generate palindrome for binary number
G = (N, T, R, S)
starting symbol is S
N = Set of non - terminal = {S}
b T = Set of terminal {O, 1}
a R = Set of Production rule= {S - OSOi 1S1 le: I 1 IO}
S=StartSymbol = {S}
b
5. Differentiate between a.Finite State Machine and a Finite
. State Automation. Design a Finite State Automata that
accepts precisely those string over {a, b} that contains an
a even no. of a's. Your design should indude the proper
definition of the Finite State Automata, transition table and
the transition diagram. "(072 Ashwin/
String over {a, b} starting with a Hints:
b.
Let the grammar G be O == (N, T, R, S) b
b
N={S, A, B}
T={a,b} a
R={S - t aA\bB, A-+ aA\bA, B ~ aB\bB}
Starting symbol is S a
to 2
5
• Non terminals (or syntactic symbols) are replaced by groups
oftenninal symbols according to the production rules.
_ 0 E s is an initial state
A£,S is accepting states. T is set of terminal symbols
Transition diagram: • Terminal symbols are literal symbols which may appear in
a the outputs of production rule or may occur in the outputs of
b
production rule or may occur in the strings of the language.
a
a
\..---~0
b
b
The lexical elements terminals and non-terminals of a
particular grammar are two disjoint sets.
P is set of production rule
. .
-
• A grammar is defined by production rule th~t specify which
Transition table: symbols may replace with other symbol to generate string.
a b
s/1
S2 S1 • A symbol substitution can be recursively perfonned to
-+S1
generate a symbol sequence.
S3 S1
S2
S3
-
• Each production rule has a head on left hand side which
S.3 S3 -
consists of the string that may be replaced, and a body, or
- -s.
,__
abstract inodel of a machine similar to finite state macbl' s/1 I
a b
with a primitive internal but with no output and ou~
I--
memory. function but it has accepriD/ S2 S2
S2
or final states. S2 s.
b
........
9.
Consider the regular grammar G == !!''
T, P, a) ~here N~
set of non-terminals == {<1, A , BJ, T - set of terminals :::: {a,
Where p is an additional non tennma
. 1 symbol.-
>
-----:::R~e---cu~r=r=e=n:ce~R~e~la;.ti~-o;;n;--......._
. Def..iru"tion of Sequences
- -- Example
1.
Let {a,J be a sequence that satisfier; th ·
. ethat
a,, = a,,.ra,,.1 fior n -- 2,3,4 and suppose
what are a1 and aj?
recurrence
a == J relation.
-
and a1 - 5
3.1 Recursive . '
From the recurrence relation.
n be defined by givmg a gene~al fonnula for
•. A sequenc~
th _ca a few o f 1·ts terms.
by wntmg · An alternative approach
. is 8n = 8n- l - 80-2
n term the sequence by finding a relationship among its terms.
tts represent
to a2 =a 1-ao = 5-3 = 2
Such relations are referred as recurrences. a3=ara 1 = 2-5=-3
Recursively defined sequences are often referred to as
Similarly a., as and also each successive tenns Th seq
recurrence relations. forms in such a way is 3,5,2,-3, ..... . e uence
A recurrence re Iauon
..: for the sequence {a.i} is. an equation J.
th t presses a.i m Determine whet?er the sequence {a,J is a solution of the
. terms o f one or more of the previous tenns . of recu"ence relation a,. = 2a,,.,-o,._1 fior n = 2 3 ~ ....,,_
thea sequence
ex namely ao, a1, a2,...... 8n- • for all integers n with n~ , ,.,, ••• "'· ,,,;;., 'I! a,,
where 1lo is a non-negative integer. . .
= Jn for every non negative integer n. Answer the· sa1t1e
question where a,, =2" and where a,.= 5.
A sequence 1s . called a solution. of a recurrence relation if Suppose that a.i = 3n for every n. therefore n::'.'2, 2a,,. -a,,.
their terms satisfy the recurrence relation. 1 2
= 2(3(n - I) - 3(n -2))
Example
= 6n - 6 - 3n + 6
Consider the following instructions for generating , =3n
sequence
=a.i
J. Start will, 3
2• Since {a,,}, where a,,= 3n, is a solution of the recurrence
relation.
Given any term, add 3 io get the n.e xt term.
The term of sequence obtained is Suppose a,,= 2° for every n. note ao == 2°- I
3 ,6, 9, 12, 15, 18,..... And a1 = 2' = 2 and a2 = 22 = 4
Ifwe denote the sequence as a1, a2, .. .. 2a.i..1 - an-2, (n = 2)
81 = 3 ············· (l) ::::: 2a1-ao
Instruction (2) can be rephrased as
= 3 t a 2, we see that {a
== 2.2-I },
a.i= au- + 3
1 n~ ........... {A)
0
-------------~--=:::-:-:--:::==--,;,11
lnslshts on Dfsaete S~ure I 111
Po::: 10,000
Solving linear homogeneous recurrence relation
Interest == 11 % ~ethod of characteristic equation
P1 == Po+ 0.11 •po We know that the line~ homogeneous recurrence relation of
== 1.1 lPo degree k with constant coefficients is of the fonn.
== 11100 3n = C13n-1+ C23n-2 + .. . .... + Ck3n-k
P2 == Pt •0.11+ Pt Let an= r° is the solution of thfa equation then
::: 1.11 Po • 0.11 + Po • 1.11 2
r"== c,r°-l + C2r"° + ...... + Ck3n-k
== 1.11pO(0.l l + 1) .
Dividing both by r""k
= (1.1 l)Po *1.11
. :::: ( 1.11 )2p0 I== c,I·' + eit·2 + ... ..+c,.
rk-c,rk•'-c2r1'·2- .....-ck = 0
3
p 3 :::: 1.l lp2 = (1,11) Po
Pn== (1,l l)Pn--t == (1.l l)"J>o This is the characteristic equation of degree k of the
Pn= (1.1 It 10,000. recurrence relation.
3.2 Solution of Linear Recurrence Relations Let us consider the liner homogeneous recurrence refations
of degree 2.
A linear homogeneous recurrence relation of degree k with
constant coefficient is a recurrence relation of the form i.e.
a,,= c,a...,+ Cia...2
a,,= Cta...t+ c2a...2+ •·············· · · · + Ckllo-k ..
Where c1, c2, ....Ck are real numbers and ck'/= 0. Its characteristic equation is of the form
The recurrence relation in the definition is linear since R.H.S r2-c,r-c2= 0
is a sum of multiples of the previous terms of the sequence. The roots of this equation can be
The recurrence relation is homogeneous since no tenn occur 1. Distinct root~ say r 1 and r2 (i.e. r 1 #; r2)
that are not multiple of the a;s.
th
1!' roots are distinct then
{a.i} is the solution of the given
The degree is k because a,, is expressed in terms of e hnear homogeneous recurrence relation if and only if a.i is of
previous k term of the sequence. the fonn
If f(n) -:;. 0 for the recurrence relation a.i= a1r,°+ a2r/ where a, and a 2 are constant
2.
Repeated roots, say r, (i.e. r1=r2=r,)
.a..= Cta...1+ c2a...2+ ....+ Ckllo-k+ f(n)
If roots are repeated root, say r0 then {a.i} is the solution of
Then it ~s called non-homogeneous recurrence relation.
~e given linear homogeneous recurrence relation if and only
If f(n) =0 then it is called linear homogeneous recurrence if 8n is of the form ·
relation.
2. Find the solution. to the recu"ence relation a,, = 6a,,.1 • The solution is given by,
11a.2 + 6a.J a,, = ( a,.o+ a1.1n+ a u n2)(-I ) 0
With the inituzl conditions a,= 2, a,= 5 and a2 = 15. = (a,.o(-J Y + a 1,1n(-J) + ai,2n2(-l)n
0
l. 3n::: a,,_ I + 2°
a omogeneous recurrence relation.
2· 3n== 8n-1+a,,..2+n2+n + I
= 2n-1(2ho+ 1) + 2n-2+ .... + 22 + 2 + 1
3· 3n = 33n-1+n3"
= 2n-l + 2n-2+ .. ... + z2 + 2 + 1
4
t(zn-1) . a(rn-1) · 8n = lln-,+2n.2+3n-3+n
= --------- ( smce Sn= ~~)
2-1 r-1
These are exam l
relation w .th
.
P es of lmear non-homogeneous recurrence
= 2°-1 h0rnogeneo• constant coeffic1ents . corresponding associated linear
Therefore, the no. hn are the partial sums of the georoetJI us recurrence relation are
sequence 1,2,22, ••• 2° and hence satisfy. l . 8n == lln-1
zn-1 2. a.i::: -n-1
SI +lln-2
2 1
_ _ _ _h_u_=~-_-_=_2_"-_1_=_2n-_•- - - - - - - -~
120 I Insights on Discrete Structure r Insights on Discrete Structure I Ul
..
for f(n) = 3"
3. · an= 3an-l Because s = 3 is a root with mult' 1..
4. an = an.1+an.2+an-3 .l". 2n• Ip ic1ty 2 part"
has the 1orm Pon 3 1f f(n) == 3 11 ' · icufar solution
n=l,a,=3 Here,
3= _ 1 - 3/2 + 3a We have,
6=-2-3+6o. f(n) = n
a= 11/6
Comparing with f(n) = p(n)s"
an= -n-3/2 + (11/6)3" · s=l
Filtd the sol11dor,s of rec11n-ence relaJion a,. = Sa,,.,- 6a.1 + Here, s is the root of characteristic equation. The particular
3. solution is in the fonn
1'
n(p,n + Po)
Solution,
The solution of its associated homogeneous recurrence = p1n2 + Poll (here m = l)
relation Now,
I
· an= Sa,..1 - 6a...2 Equation ( 1) becomes
Here, p,n2 + Poll= p,(n - 1)2+ Po(n-1) + n
f{n) = 7n Simplifying we see,
Comparing with f{n) = p(n) s" n(2p, - 1) + (po- p 1) = 0 which means
s=7 . 2p,-l =Oandp0-p 1 =0
• ·
Here s is not the root of characteristic equation,
there 1s
particular solution in the fonn Pt= Po= 1/2
Po=7D Hence,
2
Now, equation an= 5an-1 - 63n-2 + 7" becomes an<P>= n /2 + n/2 = n(n + l )/2 is a particular solution
Po7D= 5.Po7o-1 _6.Po7°"2+ 7n 3n = 3n(p) + fln(h)
Po=49/20 Bn=n(n + 1)/2 + c ......... _
......
The assoc1a e
1. Find all the solunons of recu"ence relation: I073 Bhadra
a...2
• •
Its solunon 1s 8n
(b) a,,= 7Sn-1 - 12a...2 + 3° with initial conditions ao = 1 and a, = ~
r° = 1r°· 1 - 12r°·2
r2= 3r+4
r2- 7r + 12 = 0
r2-3r-4 = 0
r2-4r - Jr+ 12 = 0
r2 - 4r + r - 4 = 0
r(r - 4) - 3(r - 4) = 0
r(r - 4) + 1( r - 4) = 0
(r - 4)(r - 3) = 0
rl =4
r1=3
r2 = -1
4° + a2 (-1)°
ao(bl =a,
r2 =4
n
Now, Finding particular solution, So(J>) 8n
(b)_
- «1r1 + «2r2n .
f{n) = 3° = «13°+ ai4°
Comparing with characteristics equation is 4 and 1, which is for particular solution
not equal to s. 8n(J>J = npo3"
Form of particular solution is npo3°= 7(n - l)po3"" 1 - 12(n - 2)J)o3n-2 + 3°
p~o=Po30 9nPo= 21npo - 2lnPo - 12np0 + 24p0 + 9
Now an= 3Sn-1 + 4 3n-2 + 3° 3po= -9
P03n= P030-I + 4 po3n-2 + 3n Po=-3
Po= Pof3 +4 Pof9 + 1 whenn=O,ao= 1
l= a,+a2
Po=-1/2
Now Sn= 3n(bl +8g(J>J when n = 1
4== a13 + «24 - 9
= «1 4° + ai (-1 )° + (-1/2) 3° 3 a, + 4a2 = 13
Putting the initial conditions, ao = 1 and a 1 = 2. I ~olving, we get,
8n = «1 4° + «2 {-1 ) + {-1/2) 3° I
0
a,== -9
1=«14° + «2 (-1)0 + (-1/2)3°
------=-=--:-~-:----:----------------
.-/1
130 I Insights ~n Discrete Structure Insights on Discrete Structure f 131
I
r
a2= 10
I
n(po)2D
2 To find constant a and
n(po)2n = 5 (n - 1)(po)2o- 1 - 6(n - 2)(po)2o- + 2n b- 20 • a2, we use the initial condition
o- a, + a2 (-1)0
put n = 0, ao= 1
and I= 2 a, - a2 ............ (2)
put n = 1, a 1 = 4 Adding equation (I) and (2)
then get, I== a1+a2
a1 =-1/5 I== 2 a, -a2
a2=6/S a,= 2/3
3n = (-1/5)2°+ (6/5)3°+ n*2/(11 - 6n)*2°
Putting value of
4. Find generol solution o f ~ = Jan-i + z ~ ~ 1 I= a,+ a2---
initud condition o,=a1 • l [071 M1111tl
l== 2/3 + a2
Solution: I
a,= 1/3
Here, Ja;i = +2 Jo.ri-1 Jo.ri-2
with aa=a = 1 1 1
Graph Theory c6
c2
4.1 Graph __
c3
Graph is a discrete structur~ consisting of vertices and edges.
c4
Edges connect the vertices.
Fig,: Graphca/ representation 0 , .
A graph G = 01, E) consists of two parameter. .
'l seven committee o••
- 'l acompan
A set V = V(G) whose elements are called vertices or nodes A graph consist of a finite n tr
vertices and a set E of element sub~eity set V of objects called
O
ofG. is a pair of two sets V and E verte V called edges. So graph
A set E = E(G) of unordered pairs of distinct vertices called • x set and ed '
ii. Vertices are also called . ge set respectively.
I
edges ofG. sometimes caJled lines or arcs. pomts or nodes. Edges are
The vertex of set G is V(G) = {
. Let us suppose that a publishing company has ten editors in E(G)= { { Ci, C2}, { CJ, C3} { C C} Ci, C2, . .. C7} and the edge set
different areas. These ten editors have a standard meeting time C2, C7},{ c3; C4},. { C3, Cs} {,C4
'
c''}s{ , { C1 ,}C7}, { C2, C3}, { C2, C4} {
' s • C4, C6 { C C } { '
during the first Sunday of every month and have divided • The number of vem· . G . ' 4, 7 , c6, C1}}
. ces m is often II d
themselves into seven committees to meet later in the day to while the number of ed . . . ca e the order of G
. ges 1s its srze w
Ofd er and s12e respectively · e use n and m for
discuss specific topics of interest of company.
• Since the vertex set of eve . .
The 10 editors have devided on seven committees C 1 = {I, 2, every graph is at least I . ry graph is non-empty, the order of
3} , Ci={l,3,4,5}, C 3={2, 5, 6, 7}, C4={4, 7, 8, 9}, C 5={2, 6, 7),
• · A graph with exact( Yone vertex
• .
1s called a tri • 1
Cc;={8, 9, 10} Cr{l, 3, 9, 10}
4.1.1 TfPes of Graphs vra graph.
They have set aside three time periods for the seven
committees to meet on those Sundays when ten editors are present 1. Labeled graph
2 - Unlabeled graph
Some committees can not meet during the same period because one
or two of the editors are on both committees. a
In this figure, there are seven small circles representing the
seven committees and a straight line segment is drawn between tw0
circles if the committees they represent have at least one committee d
member is common. In other words this means two committee witb
8
common committee memebe should not be scheduled to meet at
same time.
Fi',g.: lab l d ·
--------- e e graph Fig.: Unlabeled graph
I
4 2.1 Simple Graph h d . 0 vertices a s t
• h 1. i-tuple consists of non-empty set of vertices E of edges t at are or ered pairs of elements 0 f V In . ' e
. . this graph. •
Simple grap ~ . 0 f distinct elements of vertices called
I op is allowed but no two vertices can have ·
o . A d. . mu1tip1e edges in
v, a set of unordere th~aigrarsph as G = (V E). This kind of graph me direct10n. lfected graph having . .
w represent 1s '. . caIIed onehted
sa·.rected edges 1s . 00 symeetric pa1s of
graph A comp! t .
edges. e
bas undirected edges, no
loops and no multiple edges. dl
is called tournament. · e e onented graph
b
a
e
C
D,
D2 is oriented graph
Iv
Fig : Simple graph
I In a graph, two vertices are either adjacent or they are not, '
that is two vertices are joined by one edge or ~o edge:;
multigraph M consist of finite non empty set V of v~~ices andfinite
of E of edges where every two vertices of M are Jomed by
4.3
Fig.: Directed mutligraph
Dega:-ee of a vertex
ed :he degree of a vertex is undirected graph is. a number of
v _&es incident with it, except a loop at a vertex. Degree of a vertex
M, ~ ~
v is denoted by deg (v). A vertex of degree zero is caJled isolated
Fig.: Multigraph (Every graph is a multigraph)______, erte,c and
~ e with degree one is called pendant vertex.
138 I tnsightson8tsa_ete~truttore
Insights on Discrete Structure I 139
Loop in a vertex counts ·twice to the degree. e.g.: find the f}teorem 1:
The Handshaking Theorem
degrees.
b Let G = (V, E) be an undirected graph with
=== l:veV deg (v) a edges Then 2e
b
a r--------.-
f e
d f
deg (a)= 2 deg (b)= 3
Proof : d
deg(c) =4 deg (d) = 2
deg (f) = 2 deg(a) = deg(t) = deg(d) = 2
deg (e) = 3
deg(b) = deg(e) = 3
Let (u, v) be an edge representing edge of a directed graph G,
deg(c) = 4
u is called adjacent to v and v is called adjacent from u. The vertex
v is called initial vertex and the vertex v is called terminal or end We have
vertex. Loop had same initial and terminal vertex. LHS =2*e
In directed graph the in-degree of a vertex v, denoted by deg· =2 x 8=16
(v), is a number of edges, that have v as their terminal vertex. The · RHS = Lvev deg (v)
out:-<Iegree of a vertex v, denoted by deg+(v}, is the number of = 2 + 2 + 2 + 3 + 3 + 4 = 16
edges that have v as their initial vertex. Therefore, LHS = RHS
Loop at a vertex adds up both in-degree and out-degree to Theorem 2:
one or more than calculated in-degree and out-degree. 0
0 e 4,3.3 Cycle:
J The cycle Cru n~3, consists of .
• edges {v1, v2}, {v2, V3} {vn vert}1ces. v1, v2, ······ v and
D □·v·o.
f
b
Vertex f is isolated, vertices a, d and j are pendant.
Maximum degree is deg (h) = 5. This graph is pseudograph
(undirected loops) C3 C4
4.3.4 Wheel: cs
Q. Determine the number of its edges and sum of the degrees
ofall its vertices. ~en a new vertex is added to a c
vertex 1s connected to each of th . ycle Co and this new
There are 9 edges and sum of degrees is 18. wheel Wn. e n vertices in Cn, we obtain a
Theorem 3:
The sum of the in-degrees of all vertices in a digraph =
The sum of the out-degrees= The number of edges.
Let G = (V, E) be a graph with directed edges,
Then,
I:vevC deg-(v) )= I:vev(deg + (v) )=IE I Ws
_____•
1 position.
010
k.i ks
01 l
Fig: Complete graph
00 Ol
J
a, b, c, d
0- 4 b
I\. Ws
Ss Cs
C
Flg:2
f A B
.. Onto"
. NOT "Onto"
(all elements m B are used) (th d .
8
e an 1 10 Set B are not used)
A. function f from A to B is called onto if for all b in B there
g is an am A such that/(a) = b. All elements in Bare used.
Adjacency matrix
a b C d e f g h Such functions are referred to as surjedive.
a 0 0 1 0 0 0 0 0
b 1 I 1 1 0 0 0 0
C 0 0 0 1 1 0 0 0
d 0 0 0 1 1 0 0 2
e 0 0 0 0 1 1 0 0 B A
f 0 0 0 0 0 0 I 0 "One-to-One" NOT "One-tlrOne,.
g 0 0 0 0 0 I 0 0
E.g. : G == (V. E) and H(W, F)
h 0 0 0 0 0 2 I 0
q
ar--------b p
4.3.10 Isomorphism of Graphs
Two simple graphs G 1=(V 1, E 1) and Gt=(V2, E2) arc
isomorphic if there is a one-to-one and onto funcdon f from Vi '°r ,
f(a) and f(b) are adjacent in G2 , for all ~ and b in V1. sue
1
V2 with the property that a and b ar~ adjacent in G 1 if and 001~ a : C -G d r s
function is called isomorphism. one 1he function f with f(a) = p. f(b) = s. f(c) = r. f(d) =q is a
to one
correspondence between V and W.
a a
d G
V
H
e e
To show isomorphism of hs .
matrix For th"d" grap ' we can also use adJacency
H . ts, a ~acency matrices of two graphs
G Example : are same.
3
Both graphs have 5 vertices and six edges. But H bas a Detennine w hether the graphs are isomorphic
vertex ofdegree one, namely e, whereas G has no vertices of a
degree one. Hence G and H are not isomorphic. b s
Example 2: e f
b s
a
f d
e C V
G H
g
·
Both gra h
four v _P 8 have six vertices and seven edges. Both have
h
d------__JC ·, Also, ert1ces
Sub of d egre~ two an~ two vertices
• of degree three.
; &raphs ~phs are 1somorph1c. Here, we cannot say these
G H
i ~ e isomorphic or not. For this, we can use adjacency
l
e f
- h
Example 4: .
Determine whether given tw
I
0
graphs are isomorphic or not?
a
_ _ _ _'"""'?rb d
g
I
.. 2 4
• 5 6
.8
2 C
f
I
3 I
7
Both graphs have 8 vertices 7 edges in both hs
5 . ' · grap two
d vert1~e~ have d~gree 3, 4 vertices have degree 1 and
remammg. 2 vertices have degree 2· Since
· , the mvanants
· ·
agree m ~o~h ~e graphs, we can continue to get the function
6 such that 1t 1s isomorphism.
In above graphs, no. of vertices are same, no. of edges is
same and all vetices in both the graphs have degree 3. However,_ in case of first graph, the subgraph containing
vertex with degree 3 is not isomorphic with any graph
Since the invariants agree on both the graphs, we can try out
formed by connecting edges with vertex 2 or 6 (both of
to find the function that is isomorphism. Take the sequence
degree 3). Hence, two graphs are not isomorphic.
of vertices from the first graph as 1, 2, 3, 4, 5 and 6· N~w,
define f(l) =·c, f(2) = a here, there is adjacency preservation 4·4 Bipartite Graphs, Planar Graphs, Regular Graphs
since we have {1,2} as and edge in the first graph where as 4•4•1 ·Bipartite Graph
. ·1 ly we
·{f(l), f(2)} = {c, a} is an edge in second graph. S1m1 ar ,
can assign f(3) = b, f(4) = e, f(S) = d, f(6) = f. .. A simple graph G is bipartite if its vertex set can be
between
Since we found one to one correspondence hs ~~honed into two disjoint subsets V1 and V2 such that every edge
verticesof two graphs preserving the adjacency, above graphs V ~ graph connects a vertex from the set V I to the vertex of set
2 0
are isomorphic. Here, the adjacency matyrices of t:W0 grai J. · two vertices of the same set are connected by an edge.
in which vertices are ordered in terms of function 1.e, 1, 'nd Q. Is c, Bipartite ?
4, 5 and 6 for first graph and c, a, b, e, d and fin the sel:o
I 2
graph are same.
. pb5
One to one correspondence between vertices of two gra
3
preserving the adjacency, above graphs is isomorphic. .
Here, the adJac,
.
. ency rnatyrices of two graphs in
. ..A '
4 5311' '
* 1
6
V2.
Solution
1.
=No
/\
3L------~ 2
Regions
Euler showed that alJ planar representations of a graph split
the plane into the same number of regions, including on unbounded
region.. ·
. . g ·• K 2,5
E•• E.g. : K1.s
V• and V5 •
Any planar representation of K.3,3 V1 and V2 connected to
R2
Rl
4.4.2 Planar Graph ,
A graph is called a _planar if it can be drawn in tbe ~~ V4 -
v4 v5
without any edges crossing such drawing is called a p v2 Fig. l
Fig. 2
representation of the graph. ___-/
R21 andR22.
vl _____ _, v
graph.
•
These may help to determine if a graph ca be 1
Euler's Formula:
n P anar or not.
v2
8
Now there is no way to place vertex V 6 without forcing
crossing. k~
• If V 6 is in R2 , then {V6, V 3 } must cross an edge. Ks has 5 vertices and l Oedges.
• IfV6 is in Ru, then {V6, V2 } must cross an edge.
Here , y:::3
So• 1·r Ks ·1s planar, it must be true that
• If V6 is in R12, then {V6, V1} must cross an edge.
e 5._3v - 6
Consequently, the graph K3, 3 must be non- planar.
3
v. 6 =: J. X 5 • 6 = 15 - 6 = 9
'[ZI ~C2J
Bute== 10
Therefore Ks is non-planar.
Corollary 2 : ·~f
If G is a connected planar simple graph, the G has a vertex of d c dl[;__/
G GI G2 e
degree not exceeding 5.
Corollary 3: Graphs G1 and G2 are.homeomorphic to the graph
If a connected planar simple graph has a edges and v vertices
J(uratowski's _Theorem (Planarity Testing Algorithm)
with V2'.:3 and no circuits of length 3, then e~2V- 4
A graph is non- planar if and only if it contains a sub h
For example: homeomorphic to Kl. 3 or Ks. grap
Is K3 3 planar? v2 v3
. vll Forenmple:
v4 v6
vs
e
k3,3
K3, 3 has vertices = 6
K3.3has edges = 9
Here, v2:3 and there is no circuits of length 3, If KJ. 3 were
.
Solution
b C
.v1d VJ r:b
b
a a b
f d
d C
d C
G H b c e h
f
Graph G ls connected but graph H ls not connected. Cut vertices : c and e
Cut edge ; {c, e}
• A graph that is not connected is the union of more than one
connected graphs that do not share the common vertex. Vertex V is cut vertex of G iff deg v>2
These disjo~t connected sub graphs are called connected Connectedness in Directed graphs
components of a graph.
th A directed graph is strongly connected if there is a directed
For example: pa between every pair of vertices.
What are the connected components of the following graph? betw A directed graph is weakly connected if there is a path
b d-------- e F een every pair of vertices in the underlying undirected graph.
f or example:
Q,N. ls thefi ,
o,'/owing graph strongly connected?
a b
a C
g
b------
C
Connected components are {a, b, c,}, {d, e}, {f, g, h}
e
d
162 I Insights on Discrete Structure '-------------:-----:-:---:--:--;-;;:--
Insights on Discrete strueture 1163
♦
for example:
e d
This graph is not strongly connected because there is no
directed path between a and b, a and e etc. 4
5
However, it is weakly connected (imagine the graph as an
undirected graph) 7 8 9
The subgraphs of a directed graph of G that are stron~y
connected but not contained in larger strongly connected subgraphs Euler circuit is I, 2, 3, 6, 9, 8, ?, 4, 5, S, 6, 5, 2
(the maximal strongly connected subgraphs) are called the stron~y For connected graph G, we refer to an open trail that contains
connected components or strong components of G. every edge of G as an Eulerian trail
For example:
I graphs:
What are strongly connected components of following
a
b
C
T-
- u'S, t, U, V, W, y, U, W, X, Z. W
An euler path 1s
· a path usmg
. every edge the graph exactly
e 0
d nee. 1 ~--....:.....---- 2
This graph has three strongly connected components
• The vertex a
• The vertex e
• The graph consists of
V= {b, c, d} and
__
4
E = {{b, c}, {c, d}, {d, b}} No E I .3 .
~er CtrCUlt exist
-~~~--__:_, ____-/ Insights on Discrete Structure I 165
164 I Insights on Discrete Structure
T
.9 Hamiltonian Graph
Necessary and sufficient conditions 4
aainiJton Paths and Circuits
A connected mutligraph has a euler circuit iff each of .
1
vertices has an even degree. 1s A cycle in graph G that co ta· ·
. I C n ms eve
Hamiltontan eye e. ertainly a gra h ry vertex of G 18
.
A connected multigraph has a eulerian trail iff ~xactl If h P G (n> 3) · called
in G. a grap contains Hamil -:-- is Hamilto . a
vertices of G have odd degree . Y two Hamiltonian path. tonian cycle .t nian P~th
u v , I contams
For example: w
Q.
I. ad Zb,
Which of the following graphs is a ~ularian circuit?
2 •
b
d
Yes No
(a, e, c, d. e, b,-a)
d
C e (a, b, c, d, e, a)
d (a, b, c, d)
No
Hamilton circuit
Euler trail : (a, c, d, e, b, d, a, b)
For ffamilton Cll'CUit
.
Eulerian for Directed graph
No vertex of degree I
A non trivial connected digraph D is eulerian if and only if
od V = id v for every vertex . If a node has de . .
z , ~ any Ham.ilto . ~~ 2,. then both edges mc1dent to it must be
Cll't:uit. n crrcwt mc1dent to it must be in any Hamilton
No smaJie . . . . .
, 8~end P0int r crrcmts con~ed ~ any Hamilton circuit (the
X 19,,ice). of any smaller circwt would have to be visited
ASuff• •
ic1ent condition .
~e~ Ghea connected simple graph with a vertices with n2'._3.
C: u, v, w, y, z, x, y, x, w, u., ~ m i l t o n circuit if the degree of each vertex is 2'.. n/2.
u
is eulerian circuit. lnsi,hts on Discrete Structure I 167
166 I Insights on Discrete Structure
Weight can represent distance, cost t' ·
For example 1: . ' •me, capacity etc
a The length of a path m a weighted gra h . .
weights on the edges. p •s the sum of the
Shortest Path
There are several algorithm that find h
d
. . . a s ortest path betw
two vertices m a weighted graph. Dijkstra's al . . een
of them. gonthm 1s one
ln this graph, there is no hamilt~n circ~it since node has
degree "'.t. and both. edges from it must be. m Hamilton circuit whi'ch Dijkstra's Algorithm
is not possible one of the hamilton path ts a, b, c, d, e.
Procedure Dijkstra (G: weighted connected .
Example 2: 2 3 with all weights positive) · simple graph
Graphs that have a number assigned to each edge (u, v) has' E~d {L(6) ::::{ length of a shorter path from a to z}
weight(u, v). Each weight is a real number.
----:-:--:--------------__-/ '
168 I Insights on ~ete Structure lnslahts on Discrete Structure I· 169
'thm to find the shortest path fro,,, the 3(a,c)
01 4) S(a, c, b)
QN,l. Use Dijkstra's. !":fiollowing weighted graph given be10111
vertices a to z ,n t . 5 d
5 d
b 0 4
l) 00
a
z
0 2
z
2(a) 10 12(a,c)
10 e
C
00
0 e
5 d 3(a,c) S(a,c,b)
b
2)
00 5)
0
z 0 d 6~
a
14(a, c, b, d)
z
C e 3
2(a) 10(a,c,b,d)
e
3)
4(a)
5 d
00 0 00
3(a,c)
6
6) d
0 4 .b 5
00
z
8 2
00
2(a) 10 00
-0 e 2(a)
10 12(a,c).
e
0
4
{a,c}
0
3
{a,c,bJ
0
3
{a,c,b,df
0
3-
{a,c,b,d,e}
0
3
{a,c,b,d,e,z}
0
5 ..- 3
L(c) 00 2 2 2 2 2 2
0 4 13(a, c, b, d, e) L(d) 00 00 IO 8 8 8 .8.
z ---L(e) 00 00 12 12 10 10
0 2
-L(t) 00 00 00 00 14
Hence, the shortest path from a to z has length L(z) = 13
13
IO
13
10 tO(a, c, b, d)
· 2(a)
Q2) b 5 d
0 0
a f
B(a,c,b)
3(a, c)
() 6 Q3) b
r
5
5
d
Q
6 ff
0 4 13(a, c,b,d,e)
0 a 2 h
2 3
2(a)
10 lO(a,c,b,d)
C 10 e 5 g
IO
--
ct)
ct)
save tune
· and .energy. So he wants to detennine the shortest eyele
for his trip.
C 2 I 0 8
0 2 -----6 We can represent the cities and the distances between them
D
E
00
00
5
00
8
, IO 2 0 -----
~
bYaw ·
eighted, complete, undirected graph.
2 00 (X) 00 6 3 -~ total T~e problem then is to find the shortest cycle of minimal
Weight that visits each vertex exactly one.
rree
· I undirected simple graph WI·th no simple
A tree is· a connected •
circuit. A tree ts a partJcu ar type of graph.
Properties
56
I. . There is a unique simple path between any 2 of its vertices.
2. No loops
Kalamazo
13 Tolendo 3. No multiple edges
Route
Detroit, Toledo, Grand - Rapids - saginaw - kala - mazoo .
For example:
• a a
Detroit 610
Detroit Toledo - Grand Rapids - kalamazoo - saginav · b
•
Detroit 546
d
Detroit Toledo - Grand Rapids - kalamazoo - saginaw - C
• C
Grand - Raphids - Detroit 588
Detroit - Toledo - kalamazoo - Grand Rapids - .saginaw · e
•
Detroit458 Fig: G l Fig: G2
• Detroit - Toledo - saginaw - kalamazoo - Grand Rapids·
. . G l : It is tree because it is connected graph with no simple
Detroit 540 c1rcu1t.
• Detroit - Toledo - saginaw - Grand Rapids - kalarnazoo .
G2: It is not a free because there is a cycle a, b, e, d, a
Detroit- 504 b f
• Detroit - saginaw - Tolede - Grand Rapids - kalarnazOO ·
Detroit - 598
• Detroit - saginaw - Toledo - kalamazoo - Grand Rapids · e
Detroit - 576 .
a g
• Detroit - saginaw - kalamazoo - Toledo - Grand Rapids·
Fig: G3
·Detroit - 682
'------..::...__ _ _ _ _-:--:-----=-~-;-;:;;---
---:;:;;--;-:=;=:-:--~------~
174 I Insights on Discrete Structure 1nsIghts on Discrete Structure I 175
An undirected graph having no simple circu!t and is not • In this scenario v is c 11
.. . a ed child of u
connected is called forest. The forest has each of its connected Vertices with same parents are called·
•
components an tree G3 displays a forest. All the vertices that . Siblings
• . . appear 1n th
Theorem 1: vertex v m T, mcluding root are called
e path from root to some
An undirected is a tree if and only if there is a unique simple
• The descendents of a
. - vertex v ·ancestors of v·
path between any two of its vertices. as their ancestor. are those vertices that have V
Proof:
Assume that T is a tree. Since T is a tree. It is a connected
. All th~ vertices that have· ch'ldr
(root IS also an internal v~ ~n are called internal vertices
simple graph with no simple circuits. Let x and Y be two vertices of vertices. x if the tree has more than one
T. We know that every connected graph has a simple path between a
every pair of vertices. So, there is a simple path from x to y. This For example:
path must be unique because, if the path between x and y is not
unique then there is another path between x and Y that uses edges
different from the path, then reversing the path i.e, going to from x
to y from first path and going from y to x through second path
forms a circuit. This is a contradiction that is a tree. Hence, there is f
a unique simple path between any two vertices of a tree. e
Parent : b is parent off and g. g
Rooted (Directed) Tree Child : g and fare children of b
In many applications of trees, a particular vertex of a tree is Siblings: f and g are siblings. Y
designated as the root. A rooted tree is a tree in which one vertex Fig.: Tree
Ancestors : Ancestors of g are b a
has been designated as the root and every edge is directed away D , .
L escendents : Descendents of b .. f,g, y
from the root. We can change an unrooted true into a rooted by
choosing any vertex as the root. The tree in which root is defined eaf: Vertices with no children (y, g,e, d)
produces a directed graph. Intemal vertices : a, b, c, f
a C f th . . ·· Subgraphs cons1stmg
Sub. tree · · of V and its descentants and
· err mc1dent edges
b
Subtree rooted at b:
b
f
C
d
e a b
with root c e f
with root f
g
• Roof :Vertex with in degree o.
•• In a rooted tree, 1·r v is
· the
· vertex in T other than root, then
the Pted
dir d Of v is
arent · a vertex of u in T such that there 1·5 y
176
ec e ge from u to v.
• For m-ary trees with m>2, we can~ terms like "left m0st", A full m-ary tree with 0
--:1usii21ffll;nsdiigh;;ts;-:o;:n~D~isc=,et=e:-S::tru-ctu-:--,-e------------
Insights on Discrete Structure I 183
.....
1:
F
Step2
B A
D C
Huffman coding 0.27 0.35
Here is an algorithm that takes input the frequencies of o/\1 0.35
Step3
:(\I
F
symbols in a string and produces as output a prefix code that
D C
encodes the string using fewest possible bits. This algorithm is
called Huftman coding. It is used in data compression. The subject
devoted to reducing no. of bits required to represent information. B A
Procedure
0.38 0.62
F: Forest of n rooted trees. Step4
While F is no a tree.
O~I :~
begin:
Replace the rooted trees T and T' of least weight from F with A D C
I
W (T) ~ W (T') with a tree having a new root that has T as its left
subtree and T' as its right subtree. Label the new edge to T with 0
and new edge to T' with I.
0
Again ~ (T) + W (T') as weight of new tree end.
F
U~ H~ffman coding to encode following symbols with the
frequenCies listed what is the average no. of bits used to encode a
character.
A
-1Mll~;;:::--;~-:-----------
184 Insights on Discrete Structure
lnsl1hts on Discrete Structure I 185
From the graph; we can encode A by 111 , B by 11 0, c by Example: 2
011, D by 010, Eby 10 , and F by 00. a b
C
The average number of bits used to encode a symbol using d
this encoding is
. Pklk (Pk : Probability, lk : length)
e
= 0.08x3 + 0. t0x3 + 0. J2 x3 + 0. J5X3 + o.2x2 + 0.35 x2
= 2.45
4.14 Spanning Tree
a b
Let G be a simple graptt. A spanning tree is a sub graph of G C
d
that is a tree contain~g every vertex of G.
Consider a system of roads in Maine. The only way the roads e
can be kept open in the winter is by frequently plowing them. The
highway department wants to plow the fewest roads so that there
will always be cleared roads connecting any two towns. At least 5
roads must be plowed to ensure that there is a path between any
two towns. Fig (b) represents one such set of roads. Note that the {a, e}
a
~.
subgraph representing these roads in a tree because it. is connected d
and contains six vertices and five edges.
This problem was solved with a connected subgraph with the e •
minimum number of edges containing all vertices of the original
simple graph such a graph must be a tree.
Example: 1
{e, f}
Etha Old Town Etha Old Town
a b C d
Herman
• •
Orono
Banger
Hampden Hampden
e
(a) (b)
I I .-!.
b le
e Solution
e f b
f
---;;;-;--;::;:;:=-::::-::--~- --------
188 I lnslpts on Discrete Structure
Insights on Discrete Structure I 189
Solution e
. called back tracking Algorithm
Depth first searcb 1s a1s0 ·
·Fs (G· onnected graph with vertices V 1, v2,
Procedure D ·c
···· ······•Vn) rtex V1 visit (V 1) '
T: tree consisting only Of tbe ve
a
Procedure visit (Vertex of G)
for each vertex w a~jacent to and ~ot yet in T.
m
begin, Depth first search in Directed Graphs
add vertex wand edge {v, w} to T visit (w)
In directed graphs, there can be spanmng
. forest.
end. a b C
Depth first search can be used to find paths and circuits in a d
-
graph, can be used to det~nnine the connected components of a
- ~
--
Choose a root to the vertex from the vertices of the graph.
• '~ ,.
Then, add all edges incident to this vertex. The new vertices h
k
~
h J
j M· . .
lllimum spanning trees:
m spann _A minimum spanning tree in a connected weighted graph is a
k
edge tng tree that has the smallest possible sum of weights of its
s.
3
into the spanning tree. 3 l
Successively add to the tree edges of minimum weight that
are incident to a vertex already in the tree and not fonning a simple
I. J k
--,
circuit with those edges already in the tree. Stop when n-1 edges I Fig: II
have been added.
$2000
{b, f}= l
{f, i}=2
San New York
{a, b} =2
{a,e}=3
{i,j} = 3
{f,g}=3
{c, g} = 2
{c, d} = I
{g, h} = 3
{Chicago, Atlanta}= S700 {h, I} =3
{Atlanta, New York}= S800 {k, I} = I
{Chicago, San Fransico}= $1200 24
{San Fransico, Denver}= $900
a 2 b C d
Total $3600
San Fransico SllOO New York -
Chicago 1 2
3
e f 9 g 3 h
I
$900 3
$800 I
3 l
- j
--
k
Denver Atlanta
=~1199':t{~
. .
Ji~•"~.~~;M~~
. ."'
t ~-;;_~
- ~~ =~~------------
Fig.: Minimum Spanning tree
--~-~=
~-
1---
Fig.: minimum spanning tree
Krushal's Algorithm
This algorithm is given by Jospeh Krushal (c)
a b
C
For this algorithm, • I d
Firstly choose an edge in the graph with minimum weight.
.... ...
Successively add edge with minimum weight that do not
form a simple circuit with those edges already choosen. Stop after
e
=I
f II g,
h
ri-1 edges have been selected.
{b, f} • I
j
1
3
k
4
1
3
e
•
{c,g} =2
f II gr I
h
Sol11don
1
(a) b d
a
.... •
C
(e)
• •j k
e f
• • a 2 b C 1 d
{c, d}= 1
(b)
a
•
•
•-
j
b
•
•k
C
•
i
l
•
d
•
1
e
•
{a, b} ~ 2 1
f g
r. 1
h
f . h
e• • g.
• • •j •k • I
1
• • • • l
j k
{le, I} =I
194 I lnsishts on Discrete Structure ________;___------=~-=-=::-:-::==-;-;;;;---
1nsIshts on [)lscrete Structure 1195
(h) a
(t) 2 b
C d 3 C
a b ~ 1 d
2
-..
1 ·2
2 f
e g 3
.f g h •
e
• {f, j} =2 • {g, h} =3
2
·- :
h
2 3 1
• -
• j k
j k - I
(i)
a 2 b C
3 1 d
(t)
a 2 b 3 C 1 d
-
1 2
f g
1 2 e 3 h
f g h
• -
e
• {b, c} = 3
• 2 {i, j} = 3
3 3 1
2
1 i.
.. - - I
j k
•
k
(j)
a 2 b 3 C 1 d
(g)
a 2 b 3 C 1 d
3 1 2
1 2 f g 3 h
e
e
f g h II -
.
• {j, k} = 3 • {a, e} = 3
2
2 3 3 1
3 1 -
• j k
j k Total = 24
-1 ---
minimum spanning tree
196 I lnsipits on Discrete Structure I
E
8 F
17
Fig.: Dualgraph
e Example 2:
4.15 Graph Coloring b
. of a sunp
A colonng . le graph is the assignment
. of a .color to
each vertex of the graph so that no two adJacent vertices are
a
assigned the sm.ie color.
Smallest number of colors must be used instead of just
assigning every region its own color.
A chromatic number of a graph is the least no. of colour a
Map Dual grapu
needed for coloring graph. QJ. What is the chromatic no. ofgraph.
4 color Map Theorem: b e
The chromatic number of a plannar graph is no greater than
four. a
g
It can be shown that any two dimensional map can be
painted using four color in such a way that adjacent regions are C f
different color5.
Chromatic no. must be at least 3 since a, b, c must be
Dual graph assigned different colors
l
200 I Insights on Discrete Structure
l
r The capacity of a cut denoted by (p .
• 15
s-m of the capacities of thos c d' p') _defmed to be the
I d
· · e e ges d1 ted
vertices m set p to the vertices in p'. , rec from the
a 4,11
If the edge is backward edge put th ·
• edge :: 0. e value of the backward
t
A cut is called minimum cut if its .
s • capacity of any other cut of the networ
cakpacity
. not exceed the
In above network,
If p:: {s} and p' = {a, b, c, d, t} then c(p p')- (
b b) = 2 + l = 3. ' :-- c s, a)+ c(s,
Max flow
Here the unused capacity = slack in f- augmenting path s, a, If p:: {s, a} and p'={b, c, d, t} then c(p _
I
+ c(a, d) = l + 3 + 4 = 8. 'p') - c(s, h) + c(a, b)
d, tare
S(s, a)= 2-l = l
S(a, d) = 4-l = l
I I
Similarly,
Table .fior DOSS
p
' ible s-t cut
p'
.
Capacity c(p, p')
S(d, t) = 4-1 = 3 _ {s} {a, b, c,,d, t} 3
The minimum value is 1 in above slack value. So, now add
{s, a} {b, C, d, t} 8
the value 1 in the flow of s, a, d, t. {s, b} {a, c, d, t} 13
f(s, a)= l + l = 2 {s, c} {a, b, d, t} 7 .
f(a, d) = l + l = 2 {s, d} {a, b, c, t} 15
f(d, t) = l + 1 = 2 {s, a, b} {c, d, t} 15
Now s(s, a) = 2-2 = 0. So, there is not necessity for further {s, a, C} {b, d, t} 20
calculation of slack f-augmenting path containing s(s, a) {s, a, d} {b/C, t} 16
edge.(remember for f-augmenting path (c(e)-f(e))>O). 12 ·
{s, b, c} {a,d,t}
Again, in s(s, b) = 1-1 = 0, So, there is no necessity for {s, b, d} 19
{a, C, t}
further calculation of slack in the augmented path containing edge
{s, c, d} {a, b, t} 11
(s, b)
~{s, a, b, c} {d/t} 10
The max flow = flow from source s = 2 + 1 = 3
_j_s, a, b, d} {c, t} 17
Min cut .J.s, a, c, d} {b, t} 12
• In min cut we calculate the capacity by separating the ~ b, c, d} {a, t} 10
vertices into two subsets p and p' ~a, b, c, d} {t} 8
• p contains sonly ors and other vertices which are not in p'. Mm cut= 3
• p' contains t only or t and other vertices which are not in P· Hence, in the above example max flow = min cut= 3.
• If there are 4 vertices other than source and sink, then there
are 24 = 16 s - t cuts. ·
. (. -----------------~--:-:-~--
I lnsl1hts on Discrete Structure 203
---202w11i-;1n:sights:i::i:;:::on:--;Dlsa~::--:-ete:--:Struct::---u-re_ _ _ _ _ _ _ __;.:..-
l
of the graph. So suppose a connected a .
and e edges has a planar embedding 'tbgr ph With v vertices
WI f faces .
b · rtite explam. with figures. If G •is a In a planar embedding of a connected ·
1. Are C1 and C6 1P" ' . h E edges and V vertices,
connected planar s,·mple w,t < 3 V-6. traversed once by each of two different f:ph, ~ch edge is
th exactly twice by one face. s, or Is traversed
where V~ 3, then prove at E - /2076 Baisakh, Back}
So, every edge is traversed exactly twi ·
1 2 boundaries. So the sum of the lengths of th c; by the face
is exactly 2e. Also, in a planar embedd. e ace boundaries
3 . . h at least three Vertices each f:mg of
graph wit . a connected
.
6
least three. ' ace JS of length at
4
5
when v ~ 3, each face boundary is of length t
th1s . at Ieast 3f . Th.1s llI)pJies
. sum 1s · that a 1east three,
• so
In C3 its vertex can not be Partitioned into • two th disjointh 3fS2e
d V2 such that every edge m e grap
subsets VI an th t V 1 to the vertex of set V2 and But f = e ~ v + 2 by Euler's formula, and substituting into
connec~ a vertex from et s;e connected by an edge. So C3 thea00ve gives
no vertlces ~f the same se
3(e - v + 2) S 2e
is not bipartite. .
But in C6 ·1.ts vetex can be partitioned mto two sets VI = e - Jv+ 6S 2e
. an
={1 ,3,5} - ,4,6}• Every edge. of. C6 . connects a
, d V2 -{2 =esJv-6
vertex in VI with a vertex in V2. So, C6 is b1part1te. 2.
Define Binary tree, M-ary tree t111d Spanning tree. Find the
minimal spanning tree from the graph pen below.
/2076 Baisakl,, Bllck/
b 2 e
a
g
Suppose a connected planar graph has v~3 vertices and e
edges. Then we have to prove ~3v- 6
By defmition, a connected graph is planar iff it has a planar
C 5 f
embedding.
rn-ary tree
In graph theory, a planar graph is a graph that can ~e
embedded in the plane, i.e., it can be drawn on the plane m A rooted tree is called m-ary if every internal vertex has no
such a way that its edges intersect only at .their endpoints: ··· more than m children. It is full m-ary if every internal vertex
has exactly m children. A 2-ary tree is called a b_inary tree.
Such a drawing is called a plane graph or planar embeddmg
-
1 lnslpb.on:Discr.ltlil5ttud"'8 rl1209oi:
(2)
b b 2 e
b
a • 3
g •
d
f f g
g f
y
g
C - f
(3)
b 2 e
A minimum spanning tree in a connected weighted graph is a
spanning tree tha~ has the smallest possible sum of weights
of its edges. a • 4 3
We use two algorithms, Prism's algorithm or Krushkal
•
d
algorithm, for constructing minimum spanning trees. 4
Here we use Prism's algorithm. In this algorithm we begin C f
by choosing any edge with smallest weight, putting it into (4)
the spanning tree. b 2 e
Successively add to the tree edges of minimum weight that
are incident to a vertex already in the tree and not forming a
simple circuit with those edges already in the tree. Stop when a 4
n-1 edges have been added. 5
3 d
b 2 e
C f
a a f
• d•
. 2 e
------------------::---::-
; C
·,·:. ---~~~:-;;:=:=-=-~-------
206 I lnsilhts on Discrete Structure Insights on l)lscrete Structure I 207
f
00 (4)
3(a) 3(a) -12(a,b)
(1) 9 d
b b 9
f 00
a
a f CX)
C 2
2 e e
C
S(a) 7(a,c)
00
5(a)
S(a,b) 7(a, b, c)
12(a,b) (5) l l(a, b, c, e)
(2) 3(a)
l l(a, c, e)
b 9 d
9
00
a f a f 15(a, ci e)
l S(a, b, c, e)
C
2 e
C e
5(a) 9(a,b)
S(a) -7(a,c)
5(~b) 5(a ,b) 7(a, b, c)
(3)
12(a,b)
3(a) (6) 1 l (a, b, c, e)
b 9 d
3(a) l l~ap.,e)
b. 9
3 3
a f 00
a f 14(a, C, e, d)
14(a, b, c, e, d)
5
C 2 e C 2 e
5(a) 9(a,b) 5(a) 7(a,c)
5(a,b) 5(a, b) 7(a, b, c)
f(e) ~ c(e).
I
/10 76 Baisakh, Back/ •
4. Write short notes on: The unique starting vertex that has in d _ .
a. Regular Graph with example • source s EV egree - O is called
b. Max Flow and Min Cut The~rem The unique ending vertex rat has out degree _ .
• sink, tEV - 0 Is called
Regular Graphs:
h . a graph where each vertex In a network there is one source and one sink. An
In graph theory, a re~ar gra~ is every vertex has the same •
bas the same number of neighbors .1.e., of degree k is called a k-
degree. A regular gra
ph with vernces
b of degree k. Regular grap of
h I •
vertex : ca.ied intermediate vertex. Y other
Flow conservation : For any intennediate vertex, total flow
into x equals to the flow out of x .
regular graph or regular ~p .fy A o-regular graph consists of I
degree at most 2 ~e easy to c ~s• · ph consists of disconnected
disconnected vernces a l-rhegu ar. ~\f disconnected cycles. A 3- I Lwev f (w, x)=Lvev f (x, v)
,s L
edges, and a 2-regular grap ~ons1s
regul: ~b: known cubic graph
•
•
Sum of flow from the source = Sum of flow to the sink.
Saturated flow: The flow along an edge e(v, w) is said to be
saturated if f(e) = c(e).
• If f( e) < c(e), then the flow is unsaturated, then residual
•
•
• "\\ · V capacity or slack is s(e) = c(e) - f{e).
Flow augmenting path
o-regular graph 1- regular graph 2-regular graph • The edge ei is called forward edge if: is directed to X; to x; +1
and transportation flow from x, to x, ... 1, it is backward edge
if transportation flow from xi +1 to x; .
• If a flow f is given by path p:s = x i. x2, Xt.,. Xt =tis called a
flow augmenting path (i) every forward edge of path has
excess capacity that is f{e) < c(e). (ii) every backward edge
has f{e)>O .
1 210
non-negative real numbers.
Insights on
f)iscrete Structure I 21l
l
• P contains
.
sonly ors and other vertices wh· h .
ic are not ID p'.
• P' contams t only or t and other vertices which are not ID
.
p
fl.= min(c(e)-f(e))
If there are 4 vertices other than source and sink, th ·
f'4' = f + fl. (for forward edge) • are 24 = 16 s-t cuts. en there
f'4' = f - fl. ( for backward edge)
The capacity of a cut denoted by c(p, p') is defined t be
a 4, 11
d • •• f
s-m of t he capaett1es o those edges directed fr
o the
. set p to t he vertices
vertices m . m . p'. om the
•
further calculation of slack in the augmented path contauu g
edge (s, b)
-- {s,,a, d}
{s, b, c}
{b/C, t}
{a, d, t}
16
12
• The max flow = flow from source s = 2 + 1 = 3 ~ s , b,d} 19
{a, c, t}
Min cut ~ s , c, d} {a, b, t} 11
. the
• In min cut we calculate the capacity by separattng {s, a, b, c} {d/t} 10.
(,. vertices into two subsets p and p'
------:::-:-7=-.-::-:---=::---:-----------------
212 I Insights on Discrefe Structure .i
---------------=--==-:~Hl-
lnslpts on Discrete.Structure I 213
l
Using Dijkstra's algorithn, tofi111d ◄
p p' Capacity c(p, p') 6.
path between the vertices a a d the. lengt.'h ofthe sl,
{c, t} 17 n z ,n th orte,,
{s, a, b, d} displayed below./ 071 Magi,/ e Weiglr~d graph
{b, t} 12
{s, a, c, d} C 5 e
{s, b, c, d} {a, t} 10
b 5 d
(oo,t) (7,t) (oo,t) b 5 d
Step3
Calculate possible adjacent node from node c.
Step 5 (7,p) (12,t)
• Node d and e can be reached from the current node c Calculate possible adjacent node from node e
• update d and z can be reached from node e
• Update distance values these nodes
d.t=min{l2, 11 +3} = 12(a, c)
• <Li= min{ oo,6 + 6} = 12(a, c)
dz= min{oo, 11 + 6} = 17(a, c, e)
de= min{oo,6 + 5} = l l(a, c)
• • The status of node d changes to permanent.
(6, p) (11,t)
(6,p) (11,t)
C 5 e
C 5 e
(oo,t)
(O,p) (oo,t)
(O,p)
a z!
a z
5 d
.b
(7,t) (12,t) b 5 d
(7,p) (12,p
C 5 e
(16.p)
(0,p)
a z
b 5 d
Red 4
(7.p (12,p) 6 Red
Red 7
The iterations of dijkstra•s atgorithm are aescnoed is the following Red
Fig: BipartJt.e graph lc3,f
table.
s L(a) L(b) L(c) L(d) L(e) L(z) Blue
Initial 0 00 00 00 00 00
{a} 0 7 6 00 00 00 Blue
5 2 Green
{a, c} 12 11 00
{a, c, d} 16
{a, c, d, z} 16 Blue ...__ _...J Red
4 3
7. In II round robin tollTIUUllffll the tigers beat the blue jays. C.
- Ftg2:cS
The tigers beat tire C11Tduuds, the tigers be.at the orioles, the
bb,e jays beat tM oriola, and the cardinals beat the The chromatic number of complete bipartite graph k3,4 is
orioles. Moul this 011tco111e with a directed graph.{071 two
Maghj .
The chromatic number of cycle. graph c5 is four.
Tiger 9
Blue Jays • .State necessary and sufficient contlinons for niler circuits
and paths. /071 MgllJ
Solution:
a
z
C e
e b d C Source= a
GI G2
destination =z
Euler's formula
Step 1:
. Let G be a connected planar simple graph with e edges and v
vertices. Let r be the number of regions in a planer representation
• N . .
ode a Is designated as the current node
ofG. then r = e-,v + 2 • The state of node a is (0, p)
Corollary 1: • Every other node has state (a, t)
If ~ is a connected planar simple graph with e edges and v
vertices where v2:J, then ~3v-6.
(1, p)b
(oo.t)b 5 (a:i, c) (10, t)b
C
C
b 9
d
(O,p)p
Step 2:
• Node b and c can be reached from the current node a. a (a:i,t)b
(1,p) (9,p)
9 . d
b e d
(O,p)p (10,p) Fig: complete graph with 6 vertJces(lc J
6
a z Graph coloring:
A coloring of a simple graph is the as .
sigrunent of a color to
each vertex of the graph so that no two ad" .
(3,p) 5 (8,p) assigned the same color. ~acent vertices are
C
e Smallest number of the colors must be used . .
Step 6: · • . . mstead of Just
assignmg every region its own color.
• Node e and z can be reached from node d
Red
• Update the distance value a
Blue
de= min{8, 9 + 3} = 8(a, b, c) b
dz= m in{lO, 9 + 8} = IO(a, b, c, e)
Hence, the shortest path using dijkstra's algorithm is lO(a, b,
c, e, z)
(I,p) (9,p)
Red
b 9 d
d Blue c
(0,p)p (10,p)
Chromatic number:
a z 1
A chr ·
omattc number of a graph is the . least no. of color
• needed for co!oring graph.
d
l
r
C
Blue
The highway department want .
Red
that there wiJI always be clearsdto plow the fewest road
a b e roads co . s so
towns. At least 5 roads must be 1 . nnecting any tw
p owed to ens o :
a path between any two towns. p·ig(b) rep ure that the~e is
· ,
Green f of roads. Note that the sub graph . r~sents one such set j
c Black b . . representmg th ,
tree ecause 1t 1s connected and . . ese roads is a
I edges.
This problem was solved with a
contams six ·
vertices and five
---------•-----
How should items in a list be stored so that an item can be
easily IOcated? For this, we Use the concept of binary search
tree.
•••