Automata - Shubhanshu Singh
Automata - Shubhanshu Singh
1. Proof Techniques
2. Set Theory
4. Graph Theory
6. Grammar
7. Finite Automata
8. Regular Expression
11.∈ - NFA
12. ∈ - NFA to NFA
Method of proof that involves directly showing that a statement is true, using
logic and reasoning.
Theorem: If a and b are two even positive integers, then a*b is always even.
Proof:
a = 2x
b = 2y
ab = (2x)(2y)
= 4xy = 2(2xy)
This is an expression for an even number, because the coefficient of the term
xy is even.
Therefore, a*b is always even.
QED
a = 2x + 1
b = 2y
for some integer y.
ab = (2x + 1)(2y)
= 4xy + 2y =2(2xy+y)
This is an expression for an even integer, because the coefficient of the term
2m is even.
QED
Proof:
Suppose, for the sake of contradiction, that the square root of 2 is a rational
√2 = p/q
2 = (p/q)² = p²/q²
2q²=p²——— (i)
here, p² is even that mean p is even
then p = 2x
put in equation (i)
2q²= 4x
q² = 2x
q² is even then , q is even
QED
Proof by Induction
Proof by induction is a method of proof that is used to establish that a given
statement is true for all positive integers n. It involves showing that the
statement is true for the base case n = 1, and then using the assumption that
the statement is true for some arbitrary positive integer k to show that it is also
true for k + 1.
Proof:
1=1
n=2— 1+2 = 2( 2+1)2
3=3
then
n=k
1+2+3+4+….+k = k(k+1)/2
n = k+1
Therefore, we have shown that if the statement is true for some positive
integer k, then it is also true for k + 1.
Since the statement is true for the base case n = 1, and we have shown that if
it is true for some positive integer k, then it is also true for k + 1, we can
conclude by induction that the statement is true for all positive integers n.
QED
Proof by contrapositive
Parallel edges : Parallel edges are two or more edges that connect the same
two vertices.
deg-(v1) = 2
deg-(v2)= 2
Outdegree of vertex v1 is 1
deg+(v1) = 1
deg+(v2)= 1
In Undirected graph :
Σd(v) = 2 ∗ E
In Directed graph :
Σindegree(v) = Σoutdegree(v) = E
deg(v)= 0
Pendent Vertex :
deg(V) = 1
Distance b/w two vertices : Minimum number of edges that must be traversed
to go from one vertex to the other.
d(v1, v4) = 2
r(G) = 1
D(G) = 5
r(G) = 3 ——— Radius
D(G) = 5 ——— Diameter
Center Point : The center of a graph is the set of vertices with the minimum
eccentricity.
Center Point or CP =
v2, v7
Girth of a Graph : The girth of a graph is the length of the shortest cycle (a
path that starts and ends at the same vertex) in the graph. The girth of a graph,
denoted as g(G), is defined as the minimum length of any cycle in the graph.
Type of Graph
1. Finite Graph
2. Infinite Graph
e, v − Infinite
3. Trivial Graph
Only one vertex
4. Simple Graph
No loop
No multiple edges
5. Multi Graph
6. Null Graph
7. Complete Graph
a complete graph is a graph in which every pair of distinct vertices is
connected by an edge. A complete graph with n vertices is denoted as
Kn.
8. Regular Graph
This graph is 2-
regular graph
K - regular graph
deg(vi) = K
9. Bipartite Graph
Bipartite graph is a graph whose vertices can be divided into two disjoint
sets such that every edge in the graph connects a vertex in one set to a
vertex in the other set.
Question
Case I : Distance between two vertexes(Vi) is same
Q : We have 11 villages and have to place 3 shops in between them. Find the
locations of the villages where you can place the shops.
Σ = {0,1}
ex : { a⁰ , a¹ , a² , a³ , a⁴ , ……….. }
a⁰ = λ (Empty String)
a⁺ = Repetition of a, 1 or more time.
Prefix :
Prefix is any string that will obtain after removing 0 and more character from
end of string.
S = abcabca
Suffix :
Suffix is the string that will be obtain after removing 0 or more character from
front of the string
S = abcabca
Proper Prefix or Suffix : All the prefix and suffix excluding { abcabca, λ }
Substring : Removing 0 or more character form beginning or from end.
Example :
w = 1010001
wᴿ = 1000101
L = { 0ⁿ 1ⁿ | n≥0 }
L = { λ, 01, 0011, 000111, 00001111, ……..}
L’ = Σ* - L
Lᴿ = { 1ⁿ 0ⁿ | n≥0 }
L* = { λ, 0ⁿ1ⁿ, 0ⁿ1ⁿ0ⁿ1ⁿ, 0ⁿ1ⁿ0ⁿ1ⁿ0ⁿ1ⁿ, ……..}
Σ = { a, b }
L₁ = { aⁿ bⁿ cⁿ | n≥1 }
L₂ = { aᵐ bᵐ | m>0 }
L₁ U L₂ = { aⁿ bⁿ cⁿ U aᵐ bᵐ | n≥0 & m>0 }
L₁ U L₂ = { λ, abc, aabbcc, .…., ab, aabb, aaabbb, .…..}
L₁ ∩ L₂ = λ
L₁ . L₂ = { aⁿ bⁿ cⁿ aᵐ bᵐ | n≥1 & m≥0 }
Question :
Σ = {a, b}
Grammar
G =< T , V , S, P >
T is a finite set of terminals, which are the basic symbols of the language.
P is a finite set of production rules, which specify how strings in the language
can be constructed by replacing non-terminals with strings of terminals and
non-terminals.
Start Symbol = S
A → aAb / λ
V={A}
T = { a, b }
S={A}
Types of Grammars :
There are different types of grammars, each with their own set of rules and
capabilities:
1. Regular Grammar
2. Context-Free Grammar
3. Context-Sensitive Grammar
4. Unrestricted Grammar
Example :
Σ={a} L = { aa or
L={a} } S → aB
S → aa
S→a B→a
S=S
S=S S= { S }
T={a}
T={a} T={a}
V={S}
V={S } V = { S, B }
1: 2: 3:
Question :
Q : Write a language that contains all the strings over the alphabet {a,b}
such that the strings have exactly 2 b’s.
Σ = { a, b }
L = { aⁿ b aⁿ b aⁿ | n≥0 }
S → AbAbA
A → aA / Φ
S={S}
T = { a, b }
V = { S, A }
Q : It starting start with a and end with b or start with b and end with a.
L = { a(a+b)ⁿb U b(a+b)ⁿa}
S → aAb/bAa
T = { a, b }
V = { S, A }
Q : Write a language over {a, b, c} all the string that contain abc as
prefix and cba as suffix.
L = { abc (a+b+c)ⁿ bca | n≥0 }
Q : Write a language over {a, b, c} all the string that contain ‘aba’ is
present starting side & ‘cba’ is end side of string.
{ (a+b+c)ⁿ aba (a+b+c)ⁿ cba (a+b+c)ⁿ | n, m, p≥0}
S = abc ab cba
S ∈ L ( Yes / No )
Σ = { 2, 4, 5}
[1, 2] → 2
[2, 4] → 5
[5, 2] → F
Finite Automata
M = (Q, Σ, δ, q₀, F )
M : Finite automata
q₀ : Starting state
Representation
States representation
Dead state
Transition function
δ:Q*Σ →Q
δ ( qᵢ , a) → qᵢ₊₁
Deterministic
Non-
Deterministic
Example
L={a} Σ={a}
Q = { q₀ , qf }
Σ={a}
δ : ( q₀ , a) → qf
q₀ = q₀
F = { qf }
Complete DFA
Q = { q0, qf, qD }
Σ={a}
δ : ( q0, a ) → qf
δ : ( qD, a ) → qD
q0 = q0
F = { qf }
Transition Table
State Input
L = { a b} Σ = { a, b }
Q= { q0, q1, qf, qd}
S : ( q0, a) → q1
S : ( q0, b) → qd
S : ( q1, a) → qd
S : ( q1, b) → qf
S : ( qf, a or b) → qd
F = { qf }
Transition Table
State Input
a b
L = { (a + b)ⁿ | n=2 } Σ = { a, b }
S : ( q0, a) → q1
S : ( q0, b) → q1
S : ( qf , a/b) → qd
S : ( qd, a/b) → qd
L = { aⁿ | n≥0 }
Q = { q0 }
S : ( q0 , a ) → q0
L = { aⁿ | n >1 }
Q = { q0 , qf }
S : ( q0 , a ) → qf
S : ( qf , a ) → qf
L = { (a + b)ⁿ | n > 2 }
L = { aⁿ | n > 3 }
L = { ab(a + b) U bc(a + b) }
L = { cⁿ a cᵐ b cᵖ U cⁿ b cᵐ a cᵖ | n,m,p≥0 }
L = { bⁿ aʳ bᵐ aᵉ bᵖ | n, m, p ≥0 & (r + e) =2x ,x ≥ 0 } Σ = { a, b }
L={w|w ∈ (a + b)* }
i) Language contain all the language had last 3rd position is b
ii) From the left the 2nd position will be ‘a’ and 4th position from the right
will be ‘b’
iv) L = { w | w ∈ (a + b)* }
| w | mod 5 > 2
| w | mod 5 < 2
| w | mod 5 ≤ 2
Σ = { a, b }
1 1 Reject
0 0 Reject
2 2 Reject
0 1 Reject
0 2 Reject
1 2 Reject
1 0 Accept
2 0 Accept
2 1 Accept
Regular Expression
Regular Language : A regular language is a language for which there exists at
least one finite automata that will accept all the strings of the language.
1. ∅ = { } ( empty set )
2. λ = { λ } ( null set )
Regular Language → L = { a, b }
( r1.r2 ) → R.E
( r1 )* → R.E
( r1 ) → R.E
( r1 )* + ( r1 + r2 ) → R.E
Question :
1. L = { a }
a → R.E
2. L= { a, b }
( a + b) → R.E
4. L = { a, aa, aaa }
( a + aa + aaa ) → R.E
7. If atleast one ‘a’ come at start then one ‘b’ come at end or atleast
one ‘b’ come at start then one ‘a’ come at end
R.E → (aa)*
R.E → a(aa)*
Union Operation
L2 = a(aa)*
L1 U L2 = (aa)* + a(aa)*
L1 U L2 = { λ, aa, aaaa, ….. , a, aaa, aaaaa, ….. }
L1 U L2 = a*
Intersection Operation
L1 = { aⁿ | n≥0 }
L2 = { aᵐ | m≥ even no }
L1 ∩ L2 = R.L
L1 = { λ, a, aa, aaa, aaaa, …. }
Concatenation
L1 = { aⁿ | n≥0 }
L2 = { bᵐ | m≥0 }
L1L2 = { aⁿbᵐ | n,m≥0 }
Replication
L1 = { aⁿ | n≥0 }
L1* = L1 = a*
Complement
L2 - L1 = { a, aaa, aaaaa, …. }
check L1’ = ( R or Not ) = L2 - L1 = a* - (aa)*
a(aa)* = L1’
Regular Grammar
A → xB ( Right Linear G )
A → Bx ( Left Linear G )
A→x Where A and B ∈V x ∈ T*
Example :
i ) L = {a} ii ) L = a*
S→a S → aS/ ∈ or S → aS | S → ∈
S = {S} S = {S}
T = {a} T = {a, ∈}
V = {S} V = {S}
P:S→a P : S → aS | P : S → ∈
iii ) (aa)* iv ) a(aa)*
S → aaS/ ∈ S → aaS/a
or S → Saa | S → ∈
v ) a*b*
S = {S}
∈
S → aS/A/
T = {a, ∈} A → bA/∈
V = {S}
viii ) L = Contain all the string over
Vii ) L = { a, ab, aa, aab, aba a and b , aba as suffix
,abb, …. }
R.E = (a+b)*aba
R.E = a(a+b)*
S → Aaba
S → aA
A → aA/bA/ ∈
A → aA/bA/ ∈
ix ) Language having a in 3rd
position always from the start.
R.E = (a+b)(a+b)a(a+b)*
S → aaaA
S → abaA
S → baaA
S → bbaA
A → aA/bA/ ∈
(qi, xi)
No state { }
δ : ( q0, a) → { q0 }
{ q1 }
{ q0, q1 }
Example :
Σ = { a, b } δ : ( q1, a ) = { q2, qf }
δ : ( q1, b ) = { q1, qf }
Transition Table : -
Q a b
{ q2, qf } { q1, qf }
{ qf } { q3, qf }
{ qf } { qf }
Question :
2. a ( a+b )* b
(ab)*
(abc)*
R.E = b* + (b*a b*) + (b*a b*a b*) + (b*a b*a b*a b*)
NFA to DFA
M=
(Q, Σ, δ, q₀, F )
Q = { q0, q1, q2 }
Σ = { 0, 1}
q0 = q0
F = { q2 }
Transition Table :
States Input
0 1
{ q1, q2 } { q1, q2 }
{ q2 } { q2 }
DFA equibalance to M
q0’ = q0
Step 1 ⇒ Add q0 to Q’
Q’ = { q0 }
for this q0’ = q0
q1 is not in Q’
Add q1 in Q’
for this Q’ = { q0, q1 }
δ’ : ( q1, 1 ) → {q1}
now, Q’ = {q0, q1, {q1, q2}}
All the state that contains final state of NFA will be the final
state of DFA.
For this Final State in NFA q2 so in DFA Final State F’ = {q1, q2}
Transition Table :
Q’ 0 1
At {q2} there is no incoming arrow from other state so this is unreadable state
(we can remove this)
δ’ : ( q0, a ) → {q0}
δ’ : ( q0, b ) → {q0, q1}
Now the states are {q0} ,{ q0,q1}, {q0,q2}, {q0, q1, q2}
because q2 was the final state then in DFA final states are {q0, q2}, {q0, q1,
q2}
Transition Table :
Name Q’ a b
Name Q a b
Example :
Representation :
r1 and r2 are two regular expression
r1 + r2
r1.r2
r2.r1
Question :
Transition Function :
δ:( q0, 0 )→ ∈ ∈
closer(δ:( closer(q0),0))→ ∈ closer(δ:( {q0,q3},0))→ ∈
closer(δ:(({q0}, 0) U ({q3}, 0)))→∈ ⇒
closer({q2}U{q3}) {q2,q3,q4}
δ:( q1, 0 )→ ∈
closer(δ:( ∈ closer(q1), 0))→ ∈ closer(δ:( {q1}, 0 )) → ∈
closer{q2} ⇒ {q2,q3,q4}
δ:( q2, 0 )→ ∈
closer(δ:( ∈ closer(q2), 0))→∈ closer(δ:( {q3,q4}, 0))→ ∈
closer(δ:(({q3}, 0) U ({q4}, 0)))→∈ closer({q3}U{q4})⇒ {q3,q4}
δ:( q2, 1 )→ ∈
closer(δ:( ∈ closer(q2), 1))→∈ closer(δ:( {q3,q4}, 1))→ ∈
closer(δ:(({q3}, 1) U ({q4}, 1)))→∈ ⇒
closer({q4}U{q4}) {q4}
Question :
1.
2.
∈ ∈ ∈
δ’:(q0, 0)→ (δ’:( (q0), 0))→ (δ’:({q0,q1,q2}, 0))→ ∈(δ’:(({q0},
∈
0)U({q1}, 0)U({q2}, 0))→ ({q0}) ⇒
{q0,q1,q2}
δ’:(q0, 1)→ ∈(δ’:(∈(q0), 1))→ ∈(δ’:({q0,q1,q2}, 1))→ ∈(δ’:(({q0},
1)U({q1}, 1)U({q2}, 1))→ ∈({q1}) ⇒ {q1,q2}
∈ - NFA to DFA
1. q0 = {q0,q1} = A
= ∈({}U{q2,q3})
= ∈(q2,q3) = {q1,q2,q3} = B
= ∈(q1,q3) = {q1,q2,q3} = B
= ∈({q2}U{}U{q3})
= ∈(q2,q3) = {q1,q2,q3} = B
2. q0’ = {q0,q1} =A
= ∈(q0) = {q0,q1} = A
= ∈(q1) = {q1}
= ∈({q1}) ={q1}
Question :
By Equivalence Theorem
Zero equivalence(k=0) :
Two equivalence(k=2) :
Step-2: Mark all the pairs (qi, qj) such a that qi is Non-Final state and qj is
Final State.
q0,a→ q1
q1,a→q3
Step-4: Combine all the unmarked pairs and make them as a single state
in the minimized DFA.
Pumping Lemma