0% found this document useful (0 votes)
71 views59 pages

Automata - Shubhanshu Singh

The document discusses various proof techniques in computer science including direct proof, proof by contradiction, and proof by induction. It also covers basic graph theory concepts such as degree of a vertex, isolated vertex, distance between vertices, radius and diameter of a graph.

Uploaded by

vijaysharma3370
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views59 pages

Automata - Shubhanshu Singh

The document discusses various proof techniques in computer science including direct proof, proof by contradiction, and proof by induction. It also covers basic graph theory concepts such as degree of a vertex, isolated vertex, distance between vertices, radius and diameter of a graph.

Uploaded by

vijaysharma3370
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Automata - Shubhanshu Singh

1. Proof Techniques

2. Set Theory

3. Sequence & Tuple

4. Graph Theory

5. Formal Language Theory

6. Grammar

7. Finite Automata

8. Regular Expression

9. Non-Deterministic Finite Automata

10. NFA to DFA

11.∈ - NFA
12. ∈ - NFA to NFA

13. ∈ - NFA to DFA

14. DFA State Minimization

15. Pumping Lemma

Automata - Shubhanshu Singh 1


Proof Techniques
In computer science, proof techniques are methods and approaches that are
used to prove the correctness of algorithms and other logical statements.

Direct Proof or Proof by Construction

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:

Let a and b be two even positive integers.


By definition, an even number is a number that can be expressed in the form
2k .
Therefore, we can write:

a = 2x
b = 2y

for some integers x and y.

Multiplying a and b, we get:

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

Theorem: If a is an odd integer and b is an even integer, then a*b is always an


even integer.

Automata - Shubhanshu Singh 2


Proof:

Let a be an odd integer, and let b be an even integer.

By definition, an odd integer is a number that can be expressed in the form 2x


+ 1 for some integer x. Therefore, we can write:

a = 2x + 1

for some integer x.

By definition, an even integer is a number that can be expressed in the form


2y for some integer y. Therefore, we can write:

b = 2y
for some integer y.

Multiplying a and b, we get:

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.

Therefore, a*b is always an even integer.

QED

Proof by Contradiction or Indirect Proof


Proof by contradiction is a method of proof that involves assuming that the
statement being proved is false, and then showing that this leads to a logical
contradiction.

Theorem: The square root of 2 is an irrational number.

Proof:

Suppose, for the sake of contradiction, that the square root of 2 is a rational

Automata - Shubhanshu Singh 3


number. This means that it can be expressed as the ratio of two integers p
and q, where q is not equal to 0 and HCF (p, q) =1.

We can write this as:

√2 = p/q

Squaring both sides of this equation, we get:

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

Since p and q are even number so there HCF(p, q)!=1.

Therefore, our assumption that √2 is a rational number must be false. This


means that √2 is an irrational number.

QED

Theorem: The square root of 3 is an irrational number.

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.

Automata - Shubhanshu Singh 4


Theorem: For all positive integers n, 1 + 2 + 3 + ... + n = n(n+1)/2.

Proof:

Base case: We will show that the statement is true for


n=1— 1 = 1(1+1)/2

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

1+2+3+4+….+k+(k+1) = k(k+1)/2 + (k+1)


(k+1)(k+1+1)/2= (k+1)((k+1)+1)

This is the expression for the sum 1 + 2 + 3 + ... + (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

Theorem: For all positive integers n, 5 + 10 + 15 + ... + 5n = 5n(n+1)/2.

Proof by contrapositive

Automata - Shubhanshu Singh 5


Basic of Graph Theory
G = ( V, E)
Loop : it is a path that begins and ends at the same edge.

Parallel edges : Parallel edges are two or more edges that connect the same
two vertices.

Degree of vertex [deg(v)] : Degree of a vertex is a measure of the number of


edges incident to it, or connected to it.

Indegree [deg-(v)] : Indegree of a vertex is the number of edges pointing


towards it.

Automata - Shubhanshu Singh 6


Indegree of vertex v1 is 2

deg-(v1) = 2
deg-(v2)= 2

Outdegree [deg+(v)] : Outdegree of a vertex is the number of edges pointing


away from it.

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

Isolated Vertex : If the degree of a vertex is 0, the vertex is an isolated vertex


and is not connected to any other vertices.

deg(v)= 0

Pendent Vertex :

deg(V) = 1

Automata - Shubhanshu Singh 7


Simple Graph : No loop / No multiple edge.

Multiple Graph : Which have atleast one mutli or parallel edge.

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

Eccentricity of vertex : The eccentricity of a vertex v, denoted as e(v), is defined


as the maximum distance from v to any other vertex in the graph.

e(v2) : d(v2, v1) = 1


d(v2, v3) = 1
d(v2, v4) = 2
d(v2, v5) = 2
d(v2, v6) = 2
d(v2, v7) = 1 e(v2) = 3
d(v2, v8) = 2

Automata - Shubhanshu Singh 8


d(v2, v9) = 3

Radius of Graph : Radius of a graph is a measure of the centrality of the graph.


It is defined as the minimum eccentricity of any vertex in the graph. r(G)

r(G) = 1

e(v1) : 3 d(v1, v2) = 1


d(v1, v3) = 2
d(v1, v4) = 2
d(v1, v5) = 1
In this case, the
d(v1, v6) = 1
minimum distance is 1,
d(v1, v7) = 2 which occurs for the
d(v1, v8) = 3 distances from v1 to v2,
v5, and v6. Therefore,
d(v1, v9) = 2
the radius of the graph is
1. r(G) = 3

Note : that the radius of a graph is the minimum eccentricity of


any vertex in the graph, not just the minimum distance from a
particular vertex (v1 in this case). To find the eccentricity of
each vertex, you would need to find the maximum distance
from that vertex to any other vertex in the graph.

*Diameter of Graph : The diameter of a graph is a measure of the centrality


and the spread of the graph. It is defined as the maximum eccentricity of any
vertex in the graph. D(G)

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.

Automata - Shubhanshu Singh 9


or e(Vi) = r(G)

Center Point or CP =
v2, v7

Center of The Graph :


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.

v6, v7, v8, v9, v6 = 4

* Circumference of Graph : The circumference of a graph is the length of the


longest cycle (a path that starts and ends at the same vertex) in the graph. The
circumference of a graph, denoted as C(G), is defined as the maximum length of
any cycle in the graph.

v1, v2, v7, v6, v9, v8, v4, v5, v1 =


8

Type of Graph
1. Finite Graph

Automata - Shubhanshu Singh 10


e, v − F inite

2. Infinite Graph

e, v − Infinite

3. Trivial Graph
Only one vertex

4. Simple Graph

No loop
No multiple edges

5. Multi Graph

Which have atleast one multi or parallel edges

6. Null Graph

A null graph is a graph in which there are no edges between its


vertices. A null graph is also called empty 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

Automata - Shubhanshu Singh 11


Regular graph is a graph in which all the vertices have the same degree
(i.e., the same number of edges).

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.

10. Complete Bipartite Graph


A complete bipartite graph is a bipartite graph in which every vertex in
one set is connected to every vertex in the other set.

Automata - Shubhanshu Singh 12


11. Star Graph

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.

Eccentricity e(Vi) e(7) = 4


e(1) = 4 D(1 to 9) e(8) = 4

e(2) = 3 D(2 to 9) e(9) = 4


e(3) = 3 D(3 to 7) e(10) = 4
e(4) = 3 e(11) = 3

e(5) = 3 For 3 shops we


can choose any 3

Automata - Shubhanshu Singh 13


e(6) = 4 from
{2,3,4,5,11}

Case II : Distance between two vertexes(Vi) is not 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.

e(1) = 10 e(2) = 8 e(3) = 7 e(4) = 9 For 3 shops


we can
d(1, 2) = 2 d(2, 1) = 2 d(3, 1) = 5 e(5) = 8
choose
d(1, 3) = 5 d(2, 3) = 3 d(3, 2) = 3 e(6) = 11
{2,3,5}
d(1, 4) = 7 d(2, 4) = 5 d(3, 4) = 2 e(7) = 10
d(1, 5) = 3 d(2, 5) = 4 d(3,5)=7
e(8) = 9
d(3,6)=7
d(1, 6) = 2 d(2, 6) = 4 e(9) = 10
d(3, 7) = 6
d(1, 7) = 1 d(2, 7) = 3

Automata - Shubhanshu Singh 14


d(1, 8) = 7 d(2, 8) = 5 d(3, 8) = 2 e(10) =
d(1, 9) = 8 d(2, 9) = 6 d(3, 9) = 3
11
d(1,10)=10 d(2,10)=8
d(3, 10) =
e(11) = 9
d(1, 11) = 2 d(2, 11) = 5
3
d(3, 11) =
6

Q : Put a village (v=12) in case I and case II

Formal Language Theory


Symbol : A symbol is a basic unit of a language.

Alphabet : Finite set of symbols. Ex : Σ= {0,1}


String : Sequences of symbols drown from alphabet (finite length).

Language : Collection of string drown from alphabet.

Finite : A finite language is a language that contains a finite number of


strings.
For example, the set of all strings that are made up of the letters 'a' and 'b'
and have a length of less than 5 is a finite language.
Infinite : A infinite language is a language that contains an infinite number of
strings.
For example, the set of all strings that are made up of the letters 'a' and 'b' is
an infinite language. The set of all strings that starts with 'a' and ends with 'b'
is also an infinite language.

Σ = {0,1}

L = { aⁿ bⁿ | n>0 and n≤2 }


L = { ab,a²b² }
a² = a.a = aa

a* = Repetition of a, 0 or more time.

ex : { a⁰ , a¹ , a² , a³ , a⁴ , ……….. }
a⁰ = λ (Empty String)
a⁺ = Repetition of a, 1 or more time.

Automata - Shubhanshu Singh 15


ex : { a¹ , a² , a³ , a⁴ , ……….. }

Prefix :

Prefix is any string that will obtain after removing 0 and more character from
end of string.

S = abcabca

abcabca - 0 char remove


Prefix : λ - 7 char remove

abcabc - 1 char remove


abcab - 2 char remove
abca - 3 char remove

abc - 4 char remove

Suffix :
Suffix is the string that will be obtain after removing 0 or more character from
front of the string
S = abcabca

abcabca - 0 char remove

Suffix : λ - 7 char remove


bcabca - 1 char remove

cabca - 2 char remove


abca - 3 char remove
bca - 4 char remove

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

Automata - Shubhanshu Singh 16


Σ = {0, 1}
Σ* = { λ, 0 , 1, 00, 01, 10, 11, ……}
Σ⁺ = Σ* - λ

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}

Q - 1 : Define a language which container exactly 2 a’s.


L = { bⁿ a bⁿ a bⁿ }
Q - 2 : Prefix will be aba always.

L = { aba (a + b)ⁿ | n≥0 }


Q - 3 : Start with ‘a’ an with ‘b’.
L = { a (a + b)ⁿ b | n≥0 }

Grammar
G =< T , V , S, P >
T is a finite set of terminals, which are the basic symbols of the language.

Automata - Shubhanshu Singh 17


V is a finite set of non-terminals, which represent the variables or syntactic
categories of the language.

S is the start symbol, which is a non-terminal that represents the beginning of


the derivation process.

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.

Capital Symbols = V (non-terminals)


Σ (Small Symbols) = T (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:

Automata - Shubhanshu Singh 18


L = { aⁿ | n>0 } L = { aⁿ | n≥0 } L = { aⁿ | n≥k }
L = { a, aa, aaa, aaaa, L = { λ, a, aa, aaa, let k = 3
.... } aaaa,...}
S → aS / aaa
S → aS / a S → aS / Φ
T={a}
T={a} T = { a}
V={S}
V={S} V={S}
S={S}
S={S} S={S}
6:
4: 5:
L = { aⁿ bⁿ | n>0 }
L = { aⁿ bᵐ | n,m>0 } L = { aⁿ bᵐ | n≥2, m≥3 S → aSb / ab
}
S → AB
T = { a, b }
S → AB
A → aA / a
V={S}
A → aA / aa
B → bB / b
S={S}
B → bB / bbb
T= { a, b }
7 : L = { aⁿ bⁿ | n≥0 }
V = { S, A, B} T = { a, b }
S → aSb / Φ
V = { S, A, B}
S={S}
S= { S }

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

Automata - Shubhanshu Singh 19


A → aA / bA / ε
S={S}

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}

Finite Automata(Finite State Machine)


Basic

L = { abc (a+b+c)ⁿ cba | n≥0 }

S = abc ab cba
S ∈ L ( Yes / No )

Σ = { 2, 4, 5}

Automata - Shubhanshu Singh 20


Input String = { 2, 4,2, 4, 5 ,4 ,2
,5 }
(No of State) Q * Σ → Q (Next
output State)

[1, 2] → 2
[2, 4] → 5

[5, 2] → F

Note : Input String


should be consume

Finite Automata
M = (Q, Σ, δ, q₀, F )
M : Finite automata

Q : Finite set of states

Σ : Finite set of input symbol

δ : Transition function (Give us the next state)

q₀ : Starting state

F : Finite set of final state

Representation

States representation

Representation of final state

Dead state

Automata - Shubhanshu Singh 21


Representation of starting state

Transition function
δ:Q*Σ →Q
δ ( qᵢ , a) → qᵢ₊₁

Deterministic

Non-
Deterministic

Example
L={a} Σ={a}

Finite automata check the given string is belong to given language


or not.

Q = { q₀ , qf }
Σ={a}
δ : ( q₀ , a) → qf

q₀ = q₀
F = { qf }

Complete DFA
Q = { q0, qf, qD }

Σ={a}
δ : ( q0, a ) → qf

Automata - Shubhanshu Singh 22


δ : ( qf, a ) → qD

δ : ( 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

Automata - Shubhanshu Singh 23


q0 = q0 S : ( qd, a or b ) → qd

F = { qf }

Transition Table
State Input

a b

L = { (a + b)ⁿ | n=2 } Σ = { a, b }

L = { aa, bb, ab, ba }

Q = { q0, q1, qf, qd }

S : ( q0, a) → q1
S : ( q0, b) → q1

Automata - Shubhanshu Singh 24


S : ( q1, a/b) → qf

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 }

Automata - Shubhanshu Singh 25


L = { aⁿ | n ≤ 3 }

Q = { q0, q1, q2, q3, qD }


F = { q0, q1, q2, q3, qD }

L = { All strings over {a, b, c} that start with ab or bc }

L = { ab(a + b) U bc(a + b) }

Design a finite automata for language L={ aⁿbⁿ | n ≥ 0 }

This is not possible with finite automata

L = { A language that contain exactly 2 a’s } Σ = { a, b, c }


L = { (b+c)ⁿ a (b+c)ᵐ a (b+c)ᵖ | n, m, p ≥ 0 }

Automata - Shubhanshu Singh 26


Exactly one a and one b

L = { cⁿ a cᵐ b cᵖ U cⁿ b cᵐ a cᵖ | n,m,p≥0 }

Design a DFA all over { a, b } , { a, b, c }


L = { All the string even no of a }

L = { bⁿ aʳ bᵐ aᵉ bᵖ | n, m, p ≥0 & (r + e) =2x ,x ≥ 0 } Σ = { a, b }

Automata - Shubhanshu Singh 27


L = { (c+b)ⁿ aʳ (b+c)ᵐ aᵉ (b+c)ᵖ | n, m, p ≥0 & (r + e) =2x ,x ≥ 0 } Σ = { a,
b, c }

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’

iii) L = { w | w ∈ (a + b)* and |w| mod 3 = 1 } |w| : length of the string


L = { a, b , aaaa, bbbb, abab, baba ,….. }

| w | mod n = k ( Where n = no of states, k = final state )

iv) L = { w | w ∈ (a + b)* }

| w | mod 5 > 2

Automata - Shubhanshu Singh 28


| w | mod 5 ≥ 2

| w | mod 5 < 2

| w | mod 5 ≤ 2

Σ = { a, b }

L={w|w ∈ (a + b)* and No ‘a’ mod 3 > No ‘b’ mod 3 }


for mod of 3 we get { 0, 1, 2 }

No ‘a’ mod 3 > No ‘b’ mod 3

1 1 Reject

0 0 Reject

2 2 Reject

0 1 Reject

0 2 Reject

Automata - Shubhanshu Singh 29


No ‘a’ mod 3 > No ‘b’ mod 3

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.

Regular Expression : It is a specific arrangement of notation through which we


can generate the entire set of strings.

Regular Set : The set which generated by Regular Expression.

1. ∅ = { } ( empty set )
2. λ = { λ } ( null set )

3. a ∈ Σ then a is Regular Expression.


4. a, b ∈ Σ then (a + b) is a Regular Expression

Regular Language → L = { a, b }

Automata - Shubhanshu Singh 30


5. a, b ∈ Σ then ( a.b ) is a Regular Expression
Regular Language → L = { ab }

6. a ∈ Σ then a* is a Regular Expression.


7. a ∈ Σ then a⁺ is a Regular Expression.

r1 and r2 is a regular expression then


( r1+r2 ) → R.E

( 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

3. L = { aa, ab, bb, ba }

( a+b )( a+b ) → R.E

4. L = { a, aa, aaa }

( a + aa + aaa ) → R.E

5. L = { w | w contains ‘ab’ as a prefix and w ∈ Σ } and Σ = { a, b}


(ab (a + b)* ) → R.E

6. L = { w | a ∈ Σ and w start and end with different symbol } and Σ = {


a, b}
( a ( a+b )* b) + ( b (a+b)* a) → 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

(a+b)* ((a (a+b)* b) + (b (a+b)* a)) (a+b)* → R.E

8. L = { w | w contains even no of a’s } and Σ = { a }

Automata - Shubhanshu Singh 31


L = { λ, aa, aaaa, ….. }

R.E → (aa)*

9. L = { w | w contains odd no of a’s } and Σ = { a }

L = { a, aaa, aaaaa, ….. }

R.E → a(aa)*

Regular languages are closed under the following operations:

Union Operation

L1 = { w | w contains even no of a’s }

L2 = { w | w contains odd no of a’s }


L1 = (aa)*

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, …. }

L2 = { λ, aa, aaaa, aaaaaa, ….. }

L1 ∩ L2 = { λ, aa, aaaa, aaaaaa, …. } = (aa)*

Concatenation

L1 = { aⁿ | n≥0 }

L2 = { bᵐ | m≥0 }
L1L2 = { aⁿbᵐ | n,m≥0 }

Replication

L1 = { aⁿ | n≥0 }

L1 = { λ, a, aa, aaa, aaaa, …. }

Automata - Shubhanshu Singh 32


L1* = { λ*, a*, aa*, aaa*, aaaa*, …. }

L1* = { λ, ( a, aa, aaa,… ), ( aa, aaaa, aaaaaa,… ), (aaa, aaaaaa,…. ) ,


……. }

L1* = { λ, a, aa, aaa, aaaa, …. }

L1* = L1 = a*

Complement

L1 = { w | w ∈ a* and w is even number of a’s }


L2 = { w | w ∈ a* } = U ( universal set )
L1 = { λ, aa, aaaa, aaaaaa, ….. }

L2 = { λ, a, aa, aaa, aaaa, …. }

L2 - L1 = { a, aaa, aaaaa, …. }
check L1’ = ( R or Not ) = L2 - L1 = a* - (aa)*

a(aa)* = L1’

Regular Grammar

G =< T , V , S, P > is said to be regular grammar if all the production are


in the form of :

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

Automata - Shubhanshu Singh 33


or S → aaS | S → ∈ or S → aaS | S → 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/ ∈

Non - Deterministic Finite Automata

(qi, xi)

Automata - Shubhanshu Singh 34


M = (Q, Σ, δ, q₀, F )

No state { }
δ : ( q0, a) → { q0 }

{ q1 }

{ q0, q1 }

{ { }, { q0 }, { q1 }, { q0, q1 } } → power set

Example :

Q = { q0, q1, q2, q3, qf } Transition Function : -

q0 = { q0 } δ : ( q0, a ) = { q0, q1, q3 }


F = { qf } δ : ( q0, b) = { q0, q2, q3 }

Σ = { a, b } δ : ( q1, a ) = { q2, qf }

δ : ( q1, b ) = { q1, qf }

Transition Table : -

Q a b

{ q0, q1, q3 } { q0, q2, q3 }

{ q2, qf } { q1, qf }

Automata - Shubhanshu Singh 35


{ q2, qf } { qf }

{ qf } { q3, qf }

{ qf } { qf }

Question :

1. L = { w | w having b at third last position }


R.E = (a+b)* b (a+b) (a+b)

2. a ( a+b )* b

3. ( a+b )* a ( a+b )* b ( a+b )*

Automata - Shubhanshu Singh 36


4. R.E = (ab+abc)*

(ab)*

(abc)*

5. L = { w | w having ab at staring and bc at the end }


R.E = ( ab ( a+b+c )* bc + abc )

6. L = { w | w having maximum 3 a’s }

R.E = b* + (b*a b*) + (b*a b*a b*) + (b*a b*a b*a b*)

7. L = { w | w having last 5th position a and last 3rd position b }

Automata - Shubhanshu Singh 37


R.E = (a+b)* a (a+b) b (a+b) (a+b)

8. L = { aⁿbᵐ | n>3 m>4 }

NFA to DFA
M=
(Q, Σ, δ, q₀, F )
Q = { q0, q1, q2 }

Σ = { 0, 1}

q0 = q0
F = { q2 }

Transition Table :

States Input

0 1

Automata - Shubhanshu Singh 38


{ q1 } { q0 }

{ q1, q2 } { q1, q2 }

{ q2 } { q2 }

DFA equibalance to M

M’ = (Q’, Σ’, δ’, q₀’, F ’)


Σ’ = Σ
Q’ = { }

q0’ = q0

Step 1 ⇒ Add q0 to Q’
Q’ = { q0 }
for this q0’ = q0

Step 2 ⇒ Find the transition of q0


δ’ : ( q0, 0 ) → {q1}
δ’ : ( q0, 1 ) → {q0}

q1 is not in Q’

Add q1 in Q’
for this Q’ = { q0, q1 }

Step 3 ⇒ Find the transition for q1


δ’ : ( q1, 0 ) → {q1, q2}

δ’ : ( q1, 1 ) → {q1}
now, Q’ = {q0, q1, {q1, q2}}

Step 4 ⇒ Find transition for {q1, q2}


δ’ : ( {q1, q2}, 0 ) → δ’:(q1, 0) U δ’:(q2,0)

Automata - Shubhanshu Singh 39


{q1,q2} U {q2} ⇒ {q1,q2}
δ’ : ( {q1, q2}, 1 ) → δ’:(q1, 1) U δ’:(q2, 1)

{q1} U {q2,q2} ⇒ {q1,q2}


There is no new state.

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

{q0} {q1} {q0}


{q1} {q1, q2} {q1}

{q1, q2} {q2} {q1, q2}

{q2} {q2} {q1, q2}

At {q2} there is no incoming arrow from other state so this is unreadable state
(we can remove this)

Automata - Shubhanshu Singh 40


Question :
(a+b)* b (a+b)

δ’ : ( q0, a ) → {q0}
δ’ : ( q0, b ) → {q0, q1}

δ’ : ( {q0,q1}, a ) → δ’ : ( q0, a ) U δ’ : ( q1, a ) → { q0, q2 }

δ’ : ( {q0,q1}, b ) → δ’ : ( q0, b ) U δ’ : ( q1, b ) → { q0, q1, q2 }

δ’ : ( {q0,q2}, a ) → δ’ : ( q0, a ) U δ’ : ( q2, a ) → { q0 }


δ’ : ( {q0,q2}, b ) → δ’ : ( q0, b ) U δ’ : ( q2, b ) → { q0, q1}

δ’ : ( {q0, q1, q2}, a ) → δ’ : ( q0, a ) U δ’ : ( q1, a ) U δ’ : ( q2, a ) → { q0, q2 }

δ’ : ( {q0, q1, q2}, b ) → δ’ : ( q0, b ) U δ’ : ( q1, b ) U δ’ : ( q2, b ) → { q0, q1,


q2 }

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

A {q0} {q0} {q0,q1}


B {q0,q1} {q0,q2} {q0, q1, q2}

C {q0,q2} {q0} { q0, q1}

D {q0, q1, q2} {q0,q2} {q0,q1,q2}

Number of unreachable state - 2 states are q1 and q2.

Automata - Shubhanshu Singh 41


Transition Table :

Name Q a b

A {q0} {q0} {q0,q1}

B {q0,q1} {q0,q2} {q0,q1,q2}

C {q0,q2} {q0,q3} {q0,q1,q3}


D {q0,q1,q2} {q0,q2,q3} {q0,q1,q2,q3}

E {q0,q1,q3} {q0,q2} {q0,q1,q2}

F {q0,q1,q2,q3} {q0,q1,q2,q3} {q0,q1,q2,q3}


G {q0,q2,q3} {q0,q3} {q0,q1,q3}

H {q0,q3} {q0} {q0,q1}

Automata - Shubhanshu Singh 42


∈ - NFA

Example :

∈ - closer of q0 : ∈ - closer of q1 : ∈ - closer of q2 :


{q0,q3} {q1} {q2,q3,q4}
∈ - closer of q3 : {q3}

Automata - Shubhanshu Singh 43


∈ - closer of q4 :
{q4}

Representation :
r1 and r2 are two regular expression

r1 + r2

r1.r2

r2.r1

Question :

1. Design ∈-NFA for a*

2. (0+1)* (00+11) (0+1)*

Automata - Shubhanshu Singh 44


3. 00 (0+1)* 11

Automata - Shubhanshu Singh 45


∈ - NFA to NFA
Change from ∈ - NFA to NFA, Initial State, Final State and
Number of state are same as ∈-NFA.

∈-NFA : M = ( Q, Σ, δ, q₀, F ) NFA : M’ = ( Q’, Σ’, δ’, q₀’, F’ )

Σ’ = Σ | Q’ = Q | q0’ = q0 | F’ = F | δ : (qi , x) ⇒ ∈ (δ : ( ∈-closer(qi),


x))

∈(q0) = { q0,q1,q2 } (∈-closer of q0)

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}

δ:( q0, 1 )→ ∈ closer(δ:( ∈ closer(q0), 1))→ ∈ closer(δ:( {q0,q3}, 1))→ ∈


closer(δ:(({q0}, 1) U ({q3}, 1)))→∈ closer({q1}U{q4})⇒ {q1,q4}

δ:( q1, 0 )→ ∈
closer(δ:( ∈ closer(q1), 0))→ ∈ closer(δ:( {q1}, 0 )) → ∈
closer{q2} ⇒ {q2,q3,q4}

Automata - Shubhanshu Singh 46


δ:( q1, 1 )→ ∈
closer(δ:( ∈ closer(q1), 1))→ ∈ closer(δ:( {q1}, 1))→ ∈
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}

δ:( q3, 0 )→ ∈ closer(δ:( ∈ closer(q3), 0))→ ∈ closer(δ:( {q3}, 0)) ⇒ {q3}


δ:( q3, 1 )→ ∈ closer(δ:( ∈ closer(q3), 1))→ ∈ closer(δ:( {q3}, 1)) → ∈
closer({q4}) ⇒ q4
δ:( q4, 0 )→ ∈ closer(δ:( ∈ closer(q4), 0))→ ∈ closer(δ:( {q4}, 0)) ⇒ {q4}

δ:( q4, 1 )→ ∈ closer(δ:( ∈ closer(q4), 1))→ ∈ closer(δ:( {q4}, 1)) ⇒ {q4}

Question :

1.

∈(q0)={q0,q1} ∈(q1)={q1} ∈(q2)= ∈(q3)=


{q2} {q1,q2,q3}

Automata - Shubhanshu Singh 47


∈-NFA : M = ( Q, Σ, δ, q₀, F )
NFA : M’ = ( Q’, Σ’, δ’, q₀’, F’ )

Q’ = Q Σ’=Σ q₀’=q₀ F’ = F={{q2},{q3}}

δ’:(q0, 0)→ ∈(δ’:(∈(q0), 0))→ ∈(δ’:({q0,q1}, 0))→ ∈(δ’:(({q0}, 0)U({q1},


0))→

∈({q0})U∈({q3})→ {q0,q1}U{q1,q2,q3} ⇒ {q0,q1,q2,q3}


δ’:(q1, 0)→ ∈(δ’:(∈(q1), 0))→ ∈(δ’:({q1}, 0))→ ∈({q3}) ⇒ {q1,q2,q3}

δ’:(q1, 1)→ ∈(δ’:(∈(q1), 1))→ ∈(δ’:({q1}, 1))→ ∈(q2) ⇒ {q2}

δ’:(q2, 0)→ ∈(δ’:(∈(q2), 0))→ ∈(δ’:({q2}, 0))→ ∈({q2}) ⇒ {q2}

δ’:(q2, 1)→ ∈(δ’:(∈(q2), 0))→ ∈(δ’:({q2}, 0)) ⇒ {q2}


δ’:(q3, 0)→ ∈(δ’:(∈(q3), 0))→ ∈(δ’:({q1,q2,q3}, 0))→ ∈(δ’:
(({q1},0)U({q2},0)U({q3}, 0))) → ∈({q3})U∈({q2})U{} ⇒ {q1,q2,q3}

δ’:(q3, 1)→ ∈(δ’:(∈(q3), 1))→ ∈(δ’:({q1,q3}, 1))→ ∈(δ’:({q1},1) U


({q3},1))→ (∈({q2})U{} ⇒ {q2}

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}

Automata - Shubhanshu Singh 48


∈ ∈ ∈
δ’:(q0, 2)→ (δ’:( (q0), 2))→ (δ’:({q0,q1,q2}, 2))→ ∈(δ’:(({q0},

2)U({q1}, 2)U({q2}, 2))→ ({q2}) {q2} ⇒
δ’:(q1, 0)→ ∈(δ’:(∈(q1), 0))→ ∈(δ’:({q1,q2}, 0))→ ∈(δ’:(({q1}, 0)U({q2},
∈ ⇒ {}
0))→ ({})

δ’:(q1, 1)→ ∈(δ’:(∈(q1), 1))→ ∈(δ’:({q1,q2}, 1))→ ∈(δ’:(({q1}, 1)U({q2},


1))→ ∈({q1}) ⇒ {q1,q2}

δ’:(q1, 2)→ ∈(δ’:(∈(q1), 2))→ ∈(δ’:({q1,q2}, 2))→ ∈(δ’:((q1, 2)U({q2},


2))→ ∈({q2}) ⇒ {q2}

δ’:(q2, 2)→ ∈(δ’:(∈(q2), 2))→ ∈(δ’:({q2}, 2))→ ∈(δ’:(({q2}, 2))→


∈({q2}) ⇒ {q2} ∈ - NFA to DFA

∈(q0)={q0,q1,q2} ∈(q1)={q1,q2} ∈(q2)={q2}


∈-NFA : M = ( Q, Σ, δ, q₀, F )
NFA : M’ = ( Q’, Σ’, δ’, q₀’, F’ )

Σ’=Σ Q’={ } q0’= ∈-closer(q0)


q0={q0,q1,q2}=A

⇒ ∈(δ’:( A, a)) ⇒ ∈(δ’:( {q0,q1,q2}, a)) ⇒


δ’ : (A, a)

∈(δ’:( (q0, a) U (q1,a) U (q2,a) )) ⇒ ∈({}U{q1}U{q1}) ⇒ ∈(q1) ⇒ {q1,q2} =


B

δ’ : (A, b) ⇒ ∈(δ’:( A, b)) ⇒ ∈(δ’:( {q0,q1,q2}, b)) ⇒

Automata - Shubhanshu Singh 49


∈(δ’:( (q0,b) U (q1,b) U (q2,b) )) ⇒ ∈({q0}U{}U{q0}) ⇒ ∈(q0) ⇒ {q0,q1,q2}
=A

δ’ : (B, a) ⇒∈ (δ’:( B, a)) ⇒∈ (δ’:( {q1,q2}, a))⇒ ∈(δ’:( (q1,a) U (q2,a) )) ⇒


∈ ({q1}U{q1}) ⇒∈ ⇒ (q1) {q1,q2} = B

δ’ : (B, b) ⇒ ∈(δ’:( B, b)) ⇒ ∈(δ’:( {q1,q2}, b)) ⇒ ∈(δ’:((q1,b) U (q2,b)) ⇒


∈({}U{q1}) ⇒ ∈(q0) ⇒ {q0,q1,q2} = A
All the state which have q2 is final state

∈ - NFA to DFA
1. q0 = {q0,q1} = A

δ’ : (A, 0) = ∈(δ’:( {q0,q1}, 0))


= ∈(δ’:((q0, 0)U(q1,0))

= ∈({}U{q2,q3})
= ∈(q2,q3) = {q1,q2,q3} = B

δ’ : (A, 1) = ∈(δ’:( {q0,q1}, 1))


= ∈(δ’:((q0, 1)U(q1, 1))

Automata - Shubhanshu Singh 50


= ∈({q0}U{q1})
= ∈(q0,q1) = {q0,q1} = A

δ’ : (B, 1) = ∈(δ’:( {q1,q2,q3}, 1))

= ∈(δ’:((q1, 1)U(q2, 1)U(q3,1))


= ∈({q1}U{}U{q3})

= ∈(q1,q3) = {q1,q2,q3} = B

δ’ : (B, 0) = ∈(δ’:( {q1,q2,q3}, 0))

= ∈(δ’:((q1, 0)U(q2, 0)U(q3,0))

= ∈({q2}U{}U{q3})

= ∈(q2,q3) = {q1,q2,q3} = B

2. q0’ = {q0,q1} =A

δ’ : (A, 0) = ∈(δ’:({q0,q1}, 0))


= ∈(δ’:((q0, 0)U(q1,0))

= ∈(q0) = {q0,q1} = A

δ’ : (A, 1) = ∈(δ’:({q0,q1}, 1))


= ∈(δ’:((q0, 1)U(q1,1))

= ∈(q1) = {q1}

Automata - Shubhanshu Singh 51


δ’ : (q1, 0) = ∈(δ’:({q1}, 0))
= ∈({}) ={}

δ’ : (q1, 1) = ∈(δ’:({q1}, 1))

= ∈({q1}) ={q1}

DFA State Minimization

Question :

By Equivalence Theorem

Zero equivalence(k=0) :

P0 = {{ q0, q3, q5}, {q1, q2, q4}}

Automata - Shubhanshu Singh 52


One equivalence(k=1) :

For group I ⇒ { q0, q3, q5}


δ:(q0, 0)→ q3 (nf) δ:(q0, 1)→ q1 (f)

δ:(q3, 0)→ q0 (nf) δ:(q3, 1)→ q4 (f)

⇒ (q0, q3) ⇒ (q0, q3) | q3=q0 ⇒ k=1


δ:(q3, 0)→ q0 (nf) δ:(q3, 1)→ q4 (f)

δ:(q5, 0)→ q5 (nf) δ:(q5, 1)→ q5 (nf)

⇒ (q3, q5) ⇒ q3≠q5 ⇒ k=1


for this q1≠q5
Now, P1 = {{ q0, q3}, {q5}}

For group II ⇒ { q1, q2, q4}


δ:(q1, 0)→ q2 (f) δ:(q1, 1)→ q5 (nf)
δ:(q2, 0)→ q2 (f) δ:(q2, 1)→ q5 (nf)

⇒ (q1, q2) ⇒ (q1, q2) | q1=q2 ⇒ k=1


δ:(q2, 0)→ q2 (f) δ:(q2, 1)→ q5 (nf)
δ:(q4, 0)→ q2 (f) δ:(q4, 1)→ q5 (nf)

⇒ (q2, q4) ⇒ (q2, q4) | q2=q4 ⇒ k=1


δ:(q1, 0)→ q2 (f) δ:(q1, 1)→ q5 (nf)

δ:(q4, 0)→ q2 (f) δ:(q4, 1)→ q5 (nf)

⇒ (q1, q4) ⇒ (q1, q4) | q1=q4 ⇒ k=1


Now, P1 = {q1,q2,q4}

P1 = {{q0, q3}, {q5}, {q1, q2, q4}}

Two equivalence(k=2) :

For group {q0,q3}

Automata - Shubhanshu Singh 53


δ:(q0, 0)→ q3 (nf) δ:(q0, 1)→ q1 (f)

δ:(q3, 0)→ q0 (nf) δ:(q3, 1)→ q4 (f)

⇒ (q0, q3) ⇒ (q1, q2) | q1=q2 ⇒ k=2


For group {q1,q2,q4}

δ:(q1, 0)→ q2 (f) δ:(q1, 1)→ q5 (nf)


δ:(q2, 0)→ q2 (f) δ:(q2, 1)→ q5 (nf)

⇒ (q1, q2) ⇒ (q1, q2) | q1=q2 ⇒ k=2


δ:(q2, 0)→ q2 (f) δ:(q2, 1)→ q5 (nf)
δ:(q4, 0)→ q2 (f) δ:(q4, 1)→ q5 (nf)

⇒ (q2, q4) ⇒ (q2, q4) | q2=q4 ⇒ k=2


δ:(q1, 0)→ q2 (f) δ:(q1, 1)→ q5 (nf)
δ:(q4, 0)→ q2 (f) δ:(q4, 1)→ q5 (nf)

⇒ (q1, q4) ⇒ (q1, q4) | q1=q4 ⇒ k=2


P2 = {{q0, q3}, {q5}, {q1, q2, q4}}

P 1 = P 2 If this happened then stop.


Initial state which state contain q0 ⇒ {q0,q3}
q1,q4,q2 was the final states then final state ⇒ {q1,q2,q4}

Automata - Shubhanshu Singh 54


Table Filling Method

q6 is non-reachable state remove it


Step-1: Create the pairs of all the states involved in DFA

Step-2: Mark all the pairs (qi, qj) such a that qi is Non-Final state and qj is
Final State.

Final State = {q3,q4,q5}

Non-Final state = {q0,q1,q2,q6}

Automata - Shubhanshu Singh 55


Step-3: If there is any unmarked pair (qi, qj) such a that δ(qi,x) and δ(qj,x)
is marked, then mark (qi,qj). x = { a, b }

q0,a→ q1
q1,a→q3

Step-4: Combine all the unmarked pairs and make them as a single state
in the minimized DFA.

(q1, q2) and (q4,q5) are unmarked then q1=2 , q4=q5

Pumping Lemma

Automata - Shubhanshu Singh 56


Automata - Shubhanshu Singh 57
Automata - Shubhanshu Singh 58
/ima

Automata - Shubhanshu Singh 59

You might also like