Professional Documents
Culture Documents
UNIVERSITY INSTITUTE OF
ENGINEERING
COMPUTER SCIENCE
ENGINEERING
Bachelor of Engineering
Theory of Computation
(CST-390)
Topic: Introduction
DISCOVER . LEARN .
Course Co-ordinator: Ms. Tanvi
APEX Institute of Technology (AIT) EMPOWER
Department of Computer and Science Engineering (CSE)
Outcome:
• Student will understand the
Basics of automata
• English mathematician
state
F: final state
δ: Transition function
Alphabet
Powers of an alphabet
Let ∑ be an alphabet.
– ∑* = ∑0 U ∑1 U ∑2 U …
– ∑+ = ∑1 U ∑2 U ∑3 U …
Strings
A string or word is a finite sequence of symbols
chosen from ∑
• Empty string is (or “epsilon”)
FAQ
:
1. What are types of finite automata.
Languages
L is a said to be a language over alphabet ∑, only if L ∑*
this is because ∑* is the set of all strings (of all possible length
including 0) over the given alphabet ∑
Examples:
1. Let L be the language of all strings consisting of n 0’s followed by n
1’s:
L = {,01,0011,000111,…}
2. Let L be the language of all strings of with equal number of 0’s and
1’s:
L = {,01,10,0011,1100,0101,1010,1001,…}
Language:
A language is a collection of appropriate string. A language
which is formed over Σ can be Finite or Infinite.
Example: 1
• L1 = {Set of string of length 2}
= {aa, bb, ba, bb} Finite Language
Example: 2
• L2 = {Set of all strings starts with 'a'}
= {a, aa, aaa, abb, abbb, ababb} Infinite
Language
Course Co-ordinator: Ms. Tanvi
Department of Computer and Science Engineering (CSE)
Finite Automata
• Some Applications
– Software for designing and checking the behavior of
digital circuits
– Lexical analyzer of a typical compiler
– Software for scanning large bodies of text (e.g., web
pages) for pattern finding
– Software for verifying systems of all types that have a
finite number of states (e.g., stock market transaction,
communication/network protocol)
Example: 1
• L1 = {Set of string of length 2}
= {aa, bb, ba, bb} Finite Language
Example 2 :
• Example of Finite Language: L1 = { set of string of 2 } L1 = { xy,
yx, xx, yy }
Example: 3
• L2 = {Set of all strings starts with 'a'}
Example 4 :
• Example of Infinite Language: L1 = { set of all strings
starts with 'b' } L1 = { babb, baa, ba, bbb, baab, ....... }
FAQ
:
1. Construct the powerset for the following sets.
• {a, b}
• {0, 1}𝖴{1, 2}
• {z}
• {0, 1, 2, 3, 4}∩{1, 3, 5, a}
• {0, 1, 2, 3}−{1, 3, 5, a}
• ∅ (the empty set)
2. Prove that 12 +22+32+……+ n2= ∑n2 =
(n(n+1)(2n+1))/6.
δD 0 1 δD 0 1
δN 0 1
Ø Ø Ø {q0} {q0,q1} {q0}
q0 {q0,q1} {q0} {q0} {q0,q1} {q0} {q0,q1} {q0,q1} {q0,q2}
q1 Ø {q2} {q1} Ø {q2} *{q0,q2} {q0,q1} {q0}
*q2 Ø Ø *{q2} Ø Ø
{q0,q1} {q0,q1} {q0,q2} 1. Enumerate all possible subsets
*{q0,q2} {q0,q1} {q0} 2. Determine transitions
*{q1,q2} Ø {q2} 2. Retain only those states
reachable from {q0}
*{q0,q1,q2} {q0,q1} {q0,q2}
δN 0 1
δD 0 1
q0 {q0,q1} {q0} {q0} {q0,q1} {q0}
q1 Ø {q2} {q0,q1} {q0,q1} {q0,q2}
*q2 Ø Ø *{q0,q2} {q0,q1} {q0}
Applications
• Text indexing
– inverted indexing
– For each unique word in the database, store all locations
that contain it using an NFA or a DFA
• Find pattern P in text T
– Example: Google querying
• Extensions of this idea:
– PATRICIA tree, suffix tree
FA with -Transitions
• We can allow explicit -transitions in finite
automata
– i.e., a transition from one state to another state without
consuming any additional input symbol
– Makes it easier sometimes to construct NFAs
*q’0 Ø Ø {q’0,q0} x 0
ECLOSE(q’0)
q0 {q0,q1} {q0} {q0} q1
q1 Ø {q2} {q1} ECLOSE(q0) 1
*q2 Ø Ø {q2} q2
δE 0 1
*q’0 Ø Ø {q’0,q0,q3}
q0 {q0,q1} {q0} {q0,q3}
q1 Ø {q2} {q1}
*q2 Ø Ø {q2}
q3 Ø {q2} {q3}
15
Course Co-ordinator: Ms. Tanvi
APEX Institute of Technology (AIT)
Department of Computer and Science Engineering (CSE)
• Implication:
– DFA ≡ NFA ≡ -NFA
– (all accept Regular Languages)
Eliminating -transitions
Let E = {QE,∑,δE,q0,FE} be an -NFA
Goal: To build DFA D={QD,∑,δD,{qD},FD} s.t. L(D)=L(E)
Construction:
1. QD= all reachable subsets of QE factoring in -closures
2. qD = ECLOSE(q0)
3. FD=subsets S in QD s.t. S∩FE≠Φ
4. δ : for each subset S of QE and for each input symbol a∑:
• D Let R= U δE(p,a) // go to destination states
r in R
q0 0 q1 1 q2
start q’0
δE 0 1
δD 0 1
*q’0 Ø Ø {q’0,q0}
q0 {q0,q1} {q0} {q0} *{q’0,q0}
q1 Ø {q2} {q1} …
*q2 Ø Ø {q2}
Arden’s Theorem
In order to find out a regular expression of a Finite
Automaton, we use Arden’s Theorem along with the
properties of regular expressions.
Statement −
• Let P and Q be two regular expressions.
• If P does not contain null string, then R = Q + RP has a
unique solution that is R = QP*
PROOF
• Solution −
• Here the initial state is q1 and the final state is q2
• Now we write down the equations −
• q1 = q10 + ε
• q2 = q11 + q20
• q3 = q21 + q30 + q31
• Now, we will solve these three equations −
• q1 = ε0* [As, εR = R]
• So, q1 = 0*
• q2 = 0*1 + q20
• So, q2 = 0*1(0)* [By Arden’s theorem]
• Hence, the regular expression is 0*10*.
Course Co-ordinator: Ms. Tanvi
APEX Institute of Technology (AIT)
Computer and Science
Construct aEngineering (CSE) to the
regular expression corresponding
automata given below −
• Solution −
• Here the initial state and final state is q1.
• The equations for the three states q1, q2, and q3 are as follows
−
• q1 = q1a + q3a + ε (ε move is because q1 is the initial state0
• q2 = q1b + q2b + q3b
• q3 = q2a
• Now, we will solve these three equations −
• q2 = q1b + q2b + q3b
• = q1b + q2b + (q2a)b (Substituting value of q3)
• = q1b + q2(b + ab)
• = q1b (b + ab)* (Applying Arden’s Theorem)
• q1 = q1a + q3a + ε
Course Co-ordinator: Ms. Tanvi
APEX Institute of Technology (AIT)
Department of Computer and Science Engineering (CSE)
Regular Languages
Definition
• We define regular languages as the smallest class of
languages which contains all finite languages and closed
with respect to union, concatenation and Kleene closure.
• Every regular expression denotes a regular language.
Example
• (a*b) is a regular expression that denotes the set of
strings formed by a sequence, also empty, of a's followed
by a b.
Regular
Languages
Formal language
classes
Language Operators
Precedence of Operators
• Highest to lowest
– * operator (star)
– . (concatenation)
– + operator
• Example:
– 01* + 1 =( 0 . ((1)*) ) + 1
-NFA NF
A Kleene Theorem
Theorem 2
Reg Ex DFA
Example: 1 0 0,1
q0 0 q1 1 q2
1* 00* 1 (0+1)*
1*00*1(0+1)*
Course Co-ordinator: Ms. Tanvi
APEX Institute of Technology (AIT)
RE to -NFA construction
Reg Ex -NFA
Theorem 2
Example: (0+1)*01(0+1)*
(0+1)* 01 (0+1)*
0
0
0 1
1
1
Algebraic Laws…
• Distributive:
– E(F+G) = EF + EG
– (F+G)E = FE+GE
• Idempotent: E + E = E
• Involving Kleene closures:
– (E*)* = E*
– Φ* =
– * =
– E+ =EE*
– E? = +E
True or False?
1. ((R*)*)* = R* ?
2. (R+S)* = R* + S*?
p
w
AND
q
i) Any string w rejected by starting at p is also rejected by starting at
q.
p
w
q
p≡q
Course Co-ordinator: Ms. Tanvi 4
Computing equivalent states in a DFA
(Myhill- Nerode Theorem )
A =
0 1
B = =
0 1 0
A C E G C x x =
1 0 1
0 1 D x x x =
B 1
D 1
F 0
H E x x x x =
Pass #0 1 0 F x x x x x =
1. Mark accepting0states ≠ non-accepting states G x x x = x x =
Pass #1
1. Compare every pair of states H x x = x x x x =
2. Distinguish by one symbol transition
3. Mark = or ≠ or blank(tbd)
A B C D E F G H
Pass #2
4. Compare every pair of states
5. Distinguish by up to two symbol transitions
(untiluntil
(keep repeating different
tableor same or tbd)
complete)
….
Course Co-ordinator: Ms. Tanvi
Table Filling Algorithm - step by step
A =
0 1
B =
0 1 0
A C E G C =
1 0 1
0 1 D =
B 1
D 1
F 0
H E =
1 0 F =
0 G =
H =
A B C D E F G H
A =
0 1
B =
0 1 0
A C E G C =
1 0 1
0 1 D =
B 1
D 1
F 0
H E X X X X =
1 0 F X =
0 G X =
A =
0 1
B =
0 1 0
A C E G C X =
1 0 1
0 1 D X =
B 1
D 1
F 0
H E X X X X =
1 0 F X =
0 G X X =
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X =
0 G X X X =
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X =
0 G X X X X =
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X X =
0 G X X X = X =
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X X =
0 G X X X = X X =
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X X =
0 G X X X = X X =
A =
0 1
B = =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X X X X =
0 G X X X = X X =
A =
0 1
B = =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X
1 1 0 =
E X X X X
B D F H
1 =
F X X X X X =
0
0
G X X X = X X =
1. Mark X between accepting vs. non-accepting state H X X = X X X X =
2. Pass 1: A B C D E F G H
Look 1- hop away for distinguishing states or strings
3. Pass 2:
Look 1-hop away again for distinguishing states or strings Equivalences:
continue…. • A=B
• C=H
• D=G
Course Co-ordinator: Ms. Tanvi
Table Filling Algorithm - step by step
0 1 0 1
0 1 0 0 1
A C E G A C E
1 0 1 1 0
0 1 0
1 1 0 1
B D F H D F
1 0 1 0
0
Equivalences:
• A=B
• C=H
• D=G
Course Co-ordinator: Ms. Tanvi
Table Filling Algorithm – special case
A =
0 1
B =
0 1 0
A C E G C =
1 0 1
0 1 D =
B 1
D 1
F 0
H E ? =
1 0 F =
0 G =
H =
A B C D E F G H
• Example
• Let us consider the following DFA −
a B C
b A D
c E F
d E F
e E f
f F f
Q δ(q,0) δ(q,1)
3
Pumping Lemma for Regular Sets
– You win!!
Course Co-ordinator: Ms. Tanvi
Note: This N can be anything (need not necessarily be the #states in the DFA.
It’s the adversary’s choice.)
Proof…
Because |xy|≤N, xy should contain only
you
0s (This and because y≠ , implies y=0+)
Therefore x can contain at most N-1 0s
Also, all the N 1s must be inside z
By (3), any string of the form xykz Leq for all k≥0
Case k=0: xz has at most N-1 0s but has N 1s
Setting k=0 is
referred to as Therefore, xy0z L eq
“pumping down”
This violates the P/L (a contradiction)
13
Course Co-ordinator: Ms. Tanvi
Closure properties for R egular Sets ( RL)
This is different
from Kleene
• Closure property: closure
– If a set of regular languages are combined using an
operator, then the resulting language is also regular
• Regular languages are closed under:
– Union, intersection, complement, difference
– Reversal
– Kleene closure
– Concatenation
– Homomorphism Now, lets prove all of this!
– Inverse homomorphism
q0 qi q0 qi
qF2 qF2
…
qFk qFk
Assumes q0 isCo-ordinator:
Course a non-final state.
Ms. IfTanvi
not, do the opposite. 16
RLs are closed under intersection
a a
q0 qi qj p0 pi pj
qF2 pF2
…
DFA for
LM (qF1 ,pF1)
a
(qi ,pi) (qj ,pj)
…
(q0 ,p0)
DFA for
L qF1
q0 qi
a
qj qF2 q’0 New start
state
Make the
…
old start state
as the only new qFk
final state
11
Course Co-ordinator: Ms. Tanvi
Department of Computer and Science Engineering (CSE)
• Example 1:
• Convert the following Mealy machine into equivalent
Moore machine.
• For state q1, there is only one incident edge with output
1. So, we don't need to split this state in Moore machine.
• For state q2, there is 2 incident edge with output 0 and 1.
So, we will split this state into two states q20( state with
output 0) and q21(with output 1).
• For state q3, there is 2 incident edge with output 0 and 1.
So, we will split this state into two states q30( state with
output 0) and q31( state with output 1).
• For state q4, there is only one incident edge with output
1. So, we don't need to split this state in Moore machine.
• Transition table for Moore machine will be:
• Example 1:
• Convert the following Moore machine into its equivalent
Mealy machine.
Q A b Output(λ)
q0 q0 q1 0
q1 q0 q1 1
FAQ
:
1. Construct a finite automata that accepts {0,1}+.
2. Eliminate the e production from the CFG given below
• A-> 0 B 1 | 1 B 1
• B-> 0 B | 1 B | e
3. Find the derivation tree for the grammar, G = {{s , A , B },
{a , b }, P , s } ,whereP = {S / bA / bB , A / ab , B / aBb
/
a}
FAQ
:
1. Construct a finite automata that accepts {0,1}+.
2. Eliminate the e production from the CFG given below
• A-> 0 B 1 | 1 B 1
• B-> 0 B | 1 B | e
3. Find the derivation tree for the grammar, G = {{s , A , B },
{a , b }, P , s } ,whereP = {S / bA / bB , A / ab , B / aBb
/
a}
IMPORTANT TOPICS
For example:
• G1 = {S → AB, S → c, A → a, B → b}
• G2 = {S → aA, A → a, B → c}
The production rules of Grammar G1 satisfy the rules specified for CNF,
so the grammar G1 is in CNF. However, the production rule of Grammar
G2 does not satisfy the rules specified for CNF as S → aZ contains
terminal followed by non-terminal. So the grammar G2 is not in CNF.
Context-Free Grammar
Context Free Grammar is formal grammar, the syntax or structure of a
formal language can be described using context-free grammar (CFG), a
type of formal grammar. The grammar has four tuples: (V,T,P,S).
Pushdown Automata
Pushdown Automata is a finite automata with extra memory called stack which helps Pushdown
automata to recognize Context Free Languages.
Context-sensitive grammar
Context-sensitive grammar has 4-tuples. G = {N, Σ, P, S}, Where
• The context sensitive grammar may have more than one symbol on the left hand side of their
production rules.
• The number of symbols on the left-hand side must not exceed the number of symbols on the
right-hand side.
• The rule of the form A → ε is not allowed unless A is a start symbol. It does not occur on the right-
hand side of any rule.
• Production is in the form of V → T
Where the count of symbol in V is less than or equal to T.
Turing machine
• Turing machine was invented in 1936 by Alan Turing. It is an accepting device which
accepts Recursive Enumerable Language generated by type 0 grammar.
REFERENCES :
• Martin J.C., “Introduction to Languages and Theory of
Computation”, Tata McGraw-Hill Publising Company
Limited, 3rd Edition.
• Hopcroft J.E. and Ullman J.D., “Introduction to Automata
Theory Languages and Computation”, Narosa
Publications.
• https://www.javatpoint.com/conversion-from-mealy-
machine-to-moore-machine
• https://www.javatpoint.com/conversion-from-moore-
machine-to-mealy-machine