0% found this document useful (0 votes)
50 views189 pages

Automata Lectures PDF

Theory of automata studies abstract machines and computational problems using formal languages and mathematical models of computation. A formal language consists of strings of symbols from a finite alphabet that can be used as input for an abstract machine. For example, a formal language could be defined as strings over the alphabet {a,b,c} that both start with 'b' and end with 'b'.

Uploaded by

Haider Ali
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)
50 views189 pages

Automata Lectures PDF

Theory of automata studies abstract machines and computational problems using formal languages and mathematical models of computation. A formal language consists of strings of symbols from a finite alphabet that can be used as input for an abstract machine. For example, a formal language could be defined as strings over the alphabet {a,b,c} that both start with 'b' and end with 'b'.

Uploaded by

Haider Ali
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/ 189

o m

g .c
uit n
m p
co
ee
.a z
ww
w
What is Automata

o m
• Automata plural of automaton
g .c
uit n
• In simple words we can say that it is “something that works
p
automatically” or self-acting.
o m
e c
z e
• Automatic machine is machine that take input from user then it
w .a
performs all steps itself.
w w
• For example; computer, ATM etc.
What is Theory of Automata
m
• Theory of automata is more theoretical (mathematical) subject as
o
compared to practical subjects.
g .c
u it n
p
• It is much different from other computer science courses such as
m
programing.
co
e
e
a z
• This subject focuses on theoretical
. aspects of computer science that deals
with study of abstract
w w machines (mathematical models) as well as
computational problems.
w
Why we study this subject
• As we all know that computer works in 3 steps.
o m
• How these steps perform?
g .c
• What happens when we give it an input?
u it n
p
• If we go in this detail then this will lead us towards electronics side or
m
hardware side.
co
e e
.a z
Input w
w Computation
output
w (process)
Continue…
• Theory of computation allow us to think systematically about machine
working without going into its hardware details. o m
• How we can do that?
g .c
are easy to understand for machines. u it n
• Our machines works on programing languages, these programming languages

m p
o
• It allows us learning of languages and computational techniques
c
e e
• It allow us to design theoretical (abstract) models of machines to learn
.a z
its working without going into hardware details.
w
• Here theoretical model means we define the machine in form of states,
w
w 1, state 2, state 3 so on , and each state perform specific
• For example; state
operation.
Other different names of Automata
o m
• Theory of automata
g .c
• Automata Theory
uit n
• Theory of computation
m p
• Theory of computer science co
• Computer theory e e
.a z
ww
w
Languages
o m
• How machine works systematically?
g .c
u it n
• To study or understand a machine the basic step is how to gives an
p
input
o m
e c
z e
• Language is first step to interact with machine.
w .a
w w
Cont…
m
• For example we can interact with computer with citsokeyboard and we
can interact with ATM with its keypad. g .
t i n
p u
o m
• If we use computer keyboard for giving input to ATM machine what
happens?
e c
z e
.
• ATM machine has specifica keypad for input it has limitations that it
w
can not understandwthe meaning of all keys of computer keyboard.
w
language
o m
• Language is set of strings with rules
g .c
• L1= {aba, aa, ababa, abba, aabba,…} uit n
• Language of string that start with “a” and end with “a”

m p
co
e e
.a z
ww
w
Type of languages
o m
• There are two main types
g .c
1. Formal languages
uit n
2. Informal languages
m p
co
ee
.a z
ww
w
formal languages
• Formal languages are used as a basic for defining computer languages
• Pre defined set of symbols and strings
o m
• Concerned with just rules/syntax not with meaning.
g .c
• Formal language is syntactic language
uit n
• For example:
m p
• We define language that starts with “a” and end with “e”
➢ We will have diff combinations co
e e
a) Admhe
.a z
b) Amue
c) page ww
w
• According to definition of formal language both (a) and (b) above cases are true.
Although (c) has meaning but it don’t follow the defined rule of language.
Informal languages
• Concerned with rules and meaning.
• Informal language is semantic language. o m
g .c
For example:
u it n
p
• If we talk about English language and have two words
m
co
a) page
e e
b) aegp
.a z
w w
• Both above w follow
words English language rule that each word contains
alphabets (i.e; a, b, c … x, y, z) but only first word has meaning.
• According to definition of informal language first word is correct.
Theory of Automata
o m
g .c
uit n
m
Lecture-3 p
c o
Basic Terminologies in Automata
e e
. a z
w w
w
Some basics of Automata
• First we need to clear basic concepts about: m
.co
• letters
it ng
• alphabet
pu
• string m
• empty string co
• word e e
• string length .a z
• Reverse of stringww
• w
Power of alphabet
• Power of string
Definitions
➢Letters are characters or symbols out of which c o
we
m
build language for
machine. g .
• For example; t i n
• a,b,c…. p u
• 0,1,2,3…..
o m
➢ Alphabets are finite not empty e c
z e set of letters (symbols) that are denoted by
∑ (sigma)
.a
• For example;
• ∑ = {a,b} w w
w
• It means that language with above alphabet contains only a and b characters
Definitions
➢ String is concatenation of letters
• For example; o m
• If ∑ = {a,b} then we may have g .c
uit n
• ab, aaab, abbaa, babba, ababababb….
m p
co
e e
• For example;
.a z
• If ∑ = {1,0} then we may have
ww
w
• 10, 10010, 1100010, 1111100000 …..
Example
o m
end with “b” from ∑ = {a, b, c} g .c
• Make a language for a machine in which string starts with “b” and

t i n
pu
o m
L1= { bb, bab, baab, baccb, bccbbab…..}
e c
z e
.a
w w
w
Definitions
➢ Word is string that is permissible in language m
o.c
g
• In previous example we make a languageinfor a machine in which
u
string starts with “b” and end with “b” from
t ∑ = {a, b, c}
L1= { bb, bab, baab, baccb, bccbbab…..} m p
c o
e e
We will have some other a zstrings but that are not permissible in
. ccaabb, accba …..
language. For example; w baaac,
w w
Definitions
m
➢Empty string is a string that has no letter, also known as null string, it is
o
denoted by ^ or λ
g .c
• Length of empty string will always be 0.
it n
u
➢ Length of string is the number of lettersmin p
string denoted by │s│
• Example: s= ababb Then, │s│= 5 co
e e
• Example: ∑ = {B, aB, bab, d}.a
z
s= B aB bab Bw d w
Tokenizing= (B), w
(aB), (bab), (B), (d)
│s│= 5
Definitions

o
➢Reverse of string can be obtained by writing thecelements
m of string in
reverse order. It is denoted by Rev(s). g .
• For example; if string is; s= ababb then t i n
Rev(s)= bbaba p u
o m
c
• Example: ∑ = {a, aba, ca, d} ee
S= aabacad.a
z
If we tokenize w w
above string: s= a aba ca d
w Rev (s)= d ca aba a
Definitions

➢Power of Alphabet
o m
.c
• The length of string that made from alphabet should be equal to power of
g
alphabet.
uit n
Example:
m p
∑ 2 = { a, b} 2
co
∑ 2 = {aa, ab, ba, bb} ee
Example: .a z
∑3 = { a, b, c} 3 ww
w
∑3 = {aaa, abc, ccc, bbc, cca,….}
Definitions
➢Power of String
o m
• Determine the length of string
g .c
Example:
uit n
S= (aba)2
m p
S= abaaba
co
Example: e e
S= ab2a .a z
S= abba ww
w
Palindrome
m
• It is language whose reverse is same as string i.e; S= Rev(s)
o
g .c
• Example:
u it n
• We have string s= { abcba} m p
Rev(s)= {abcba} co
ee
.a z
ww
w
Theory of Automata
o m
g .c
uit n
Lecture-5m p
c o
Descriptive definition of language
e e
. a z
ww
w
Defining Languages
➢ How do automata accept or reject input?
o m
.c
➢ How can automata know that given string is valid or not?
g
it n
• The answer of above questions is “language”
u
p
• There are different method with which we can define language
m
• A language can be defined in following ways:
o
i. Descriptive e c
z e
ii. Recursive
w .a
iii. Regular Expressions (RE)
w w
iv. Finite Automata (FA)
v. Transition Graphs (TG)
Types of Languages in Automata
• A language can be defined in following ways:
o m
i. Descriptive g .c
ii. Recursive
u it n
iii. Regular Expressions (RE)
m p
iv. Finite Automata (FA) co
ee
v. Transition Graph (TG)
.a z
ww
w
Descriptive definition of language
• It describe the condition imposed on its words.
o m
➢ Example:
g .c
it n
• The language L of string of even length, defined over ∑ = {c} can be written as:
u
L= {cc, cccc, cccccc,…}
m p
➢ Example:
co
e
• The language L of string that does not start with “y” defined over ∑ = {x,y,z} can be
e
written as:
.a z
L= {x, z, xz, xy, zx, zy,zzz, zzy,…}
➢ Example: ww
w
•The language L of string of length 2 ,defined over ∑ = {0,1,2} can be written as:
L= {00,01,11,12,21,02,…}
Cont…
➢ Example:
m
Write a language L of strings ending in 0, defined over Σ ={0,1},
o
L={0,00,10,000,010,100,110,…}
g .c
➢ Example: u it n
p
Write a language EQUAL, of strings with number of a’s equal to number of b’s,
m
defined over Σ={a,b},
co
L= {Λ, ab, aabb, abab, baba, abba,…}
e e
.a z
➢ Example:
ww
Write a language EVEN-EVEN, of strings with even number of a’s and even number of
w
b’s, defined over Σ={a, b},
L= {Λ, aa, bb, aaaa, aabb, abab, abba, baab, baba, bbaa, bbbb,…}
Cont…
➢Example:
o m
Write a language {anbn }, of strings defined over Σ={a, b}, as {anbn : n=1,2,3,…},
L= {ab, aabb, aaabbb, aaaabbbb, …} g .c
u it n
➢Example (practice tasks): m p
co
• Write a language that contain at least one ‘a’, defined over alphabet Σ=
{a,s,d} ee
.a z
• Write a language that contain at exactly two ‘cc’, defined over alphabet Σ=
{a,b,c} ww
w
• Write a language that start with ‘bb’ and end with ‘c’, defined over alphabet
Σ= {a,b,c,d}
Theory of Automata
o m
g .c
uit n
Lecture-6m p
c o
Recursive definition of language
e e
.a z
w w
w
Defining Languages
• A language can be defined in following ways:
o m
i. Descriptive g .c
ii. Recursive
u it n
iii. Regular Expressions (RE)
m p
iv. Finite Automata (FA) co
ee
v. Transition Graph (TG)
.a z
ww
w
Recursive definition of language
➢ In this method we describe the language with three steps.
i. Some basic words are specified in the language. o m
g .c
ii. Rules for constructing more words are defined in the language.
u it n
iii. No strings except those constructed in above, are allowed to be in the
language.
m p
c o
e e
Example: Defining language of positive even numbers using recursive
definition.
.a z
Step 1: 2 is positive even number
Step 2: If x is positive w
w
even then so is , x+2
w
Step 3: No strings except those constructed in above, are allowed to be in
positive EVEN.
Examples (recursive definition)
o m
➢ Defining the language L, of strings beginning and
letters , defined over Σ={a, b} g .c ending in same

t i n
L= { aa,bb, abbba,uabababa, babbaab,bbbbaaabb,…}
Step 1: a and b is in L
m p
c o
e
ealso in L, where s belongs to Σ*
.a z
Step 2: (a)s(a) and (b)s(b) are

w w
step 3: No strings except those constructed in above, are allowed to be
in L w
Examples (recursive definition)

o m
➢ Defining the language L, of strings containing aa or
Σ={a, b} g .c bb , defined over

t i n
p u
L={ aa, bb , aaa, baa, babaa, bbabaab, abababb,
babbab,….}
Step 1: aa and bb are in L
o m
e c
z
Step 2: s(aa)s and s(bb)s are alsoein L, where s belongs to Σ*
.a
w
Step 3: No strings except
w those constructed in above, are allowed to be in L
w
Theory of Automata
o m
g .c
it n
u
Lecture-7 p
o m (RE)
e c
Regular Expression
Part-1
z e
.a
ww
w
Defining Languages
• A language can be defined in following ways:
o m
i. Descriptive g .c
ii. Recursive
u it n
iii. Regular Expressions (RE)
m p
iv. Finite Automata (FA) co
ee
v. Transition Graphs (TG)
.a z
ww
w
Regular Expressions (RE)
• RE is one of the language defining method.
o m
• In RE, language is represented in term of strings.
g .c
{^, x, xx, xxx, xxxx, .....} u it n
• In a regular expression, x* means zero or more occurrence of x. It can generate

p
• In a regular expression, x+ means one or more occurrence of x. It can generate
m
{x, xx, xxx, xxxx, .....}
co
e e
➢ Example
.a z
ww
• Consider a alphabet Σ={a}, the language L, made from given alphabet is L={^,
a,aa,aaa,aaaa,….}. How we can write the RE of this language?
w
RE= a*
RE (Examples)

➢Consider a alphabet Σ={a}, the language L, made from o m given alphabet


is L={ a, aa, aaa, aaaa,….}. How we can write the g .cRE of this language?
t i n
RE= a pu
+

o m
e c
➢Write a RE for string that start from ‘a’ and contain any ‘b’ letter
defined over Σ={a, b}.
z e
.
According to given conditiona language must start from letter ‘a’ and
w w
contain any no. of ‘b’ letter .
w abbbbb…..}
L= {a, ab, abb, abbb,
RE= ab*
RE (examples)

o m
• Write a RE for string that start from ‘a’ and contain at least one ‘b’
letter defined over Σ={a, b}. g .c
u it n
According to given condition language must
m p start from letter ‘a’ and
contain at least one ‘b’ letter .
co
e e
.a
L= {ab, abb, abbb, abbbbb…..}
z
w w
RE= ab + w
RE (examples)

m
➢ Write a RE for string that contains ‘a’ or ‘b’ defined over Σ={a, b}.
o
g .c
L= {a, b}
u it n
We will represent or with ‘+’ sign. L (r1 + r2) = L (r1) 𝖴 L (r2)
p
o m
RE= a + b e c
z e
w .a
w w
RE (examples)

m
➢ Write a RE for string that contains any ‘a’ or any ‘b’ defined over Σ={a, b}.
o
L = { ^, a, b, aa, bb, aaa, bbb, ab, aab,…}
g .c
RE= (a + b)*
uit n
m p
co
e e
.a z
ww
w
RE (examples)

m
➢Write a RE for string that contains at least one ‘a’ or at least one ‘b’ defined
o
over Σ={a, b}.
g .c
L = {a, b, aa, bb, aaa, bbb, ab, aab,…}
u it n
RE= (a + b)+
m p
co
ee
a z
➢ Write a RE for string that start
. with ‘a’ or end with ‘a’, defined over Σ={a, b}.
L= { aa, aba, abba, ababa, w
abbba, abaaaba, ….}
w w
RE= a (a + b)* a
RE (examples)

m
➢Write the regular expression for the language accepting all the string
o
g .c
which are starting with 1 and ending with 0, over ∑ = {0, 1}.

u it n
According to given condition string will be following type:
s= 10, 100, 110,1110, 100010, 1100,… m p
co
e e
RE= 1 (0+1)* 0
.a z
ww
w
Practice Task
➢Write the regular expression for the language starting and ending with ‘a’
o m
and having any having any combination of b's in between, over ∑ = {a, b}.
g .c
➢Write the regular expression for the language t i nL over ∑ = {0, 1} such that
u
all the string do not contain the substringp01.
o m
➢Write the regular expression for e c the language containing the string in
e
which every 0 is immediatelyzfollowed by 11.
.a
w w
➢ Write RE for the language, defined over Σ ={a, b} of words starting with ‘a’
w starting with ‘b’ and ending in ‘a’ .
and ending in ‘b’ OR
o m
g .c
t i n
Thankmyou pu
co
e e
.a z
ww
w
o m
g .c
uit n
m p
co
ee
.a z
ww
w
Theory of Automata
o m
g .c
it n
u
Lecture-8 p
o m (RE)
e c
Regular Expression
Part-2
z e
.a
ww
w
Practice Task
➢ Write the regular expression for the language starting and ending with
m
‘a’ and having any having any combination of b's in between, over ∑ =
o
{a, b}.
g .c
t i n
p u
➢ Write the regular expression for the language
all the string do not contain the substring 01.
L over ∑ = {0, 1} such that

o m
e c
➢Write the regular expression
z e for the language containing the string in
.a
which every 0 is immediately followed by 11.

w w
➢Write RE for thewlanguage, defined over Σ ={a, b} of words starting with
‘a’ and ending in ‘b’ OR starting with ‘b’ and ending in ‘a’ .
RE (examples)
m
• Write the regular expression for the language starting and ending
o
.c
with ‘a’ and having any having any combination of b's in between,
g
over ∑ = {a, b}.
uit n
p
According to given condition string willmbe following type:
c
s= aa, aba, abba, abbba, abbbba,e….
o
z e
.a
RE= ab*a
ww
w
RE (examples)
➢ Write the regular expression for the language L over ∑ = {0, 1} such that
all the string do not contain the substring 01. o m
g .c Note:
As we know substring is part of string

➢ The give statement means string should be u t i n


following type
L= { ^, 0, 1, 00, 11, 10, 110,….} m p
R = (1* 0*) co
e e
.a z
w w
w
RE (examples)

o m
in which every 0 is immediately followed by 11.g .c
➢Write the regular expression for the language containing the string

t i n
p u
o m
• String should be L= {011, 11011, 0111, 01111,…..}
e c
• R = (011 + 1)* z e
.a
w w
w
RE (examples)

➢Write RE for the language, defined over Σ ={a, b}cof o mwords starting
with ‘a’ and ending in ‘b’ OR starting with ‘b’g
.
and ending in ‘a’ ,
t i n
p u
o m
e c
z e
.a
w w
• then its regular expression may be a(a+b)*b + b(a+b)*a
w
RE (examples)
• Lets have some practice to strengthen our concept about RE. Now we will
make a string from RE. o m
g .c
RE = b*
uit n
S = ^, b, bb, bbb, bbbb, …..
m p
co
RE= b+ ee
S= b, bb, bbb, bbbb, ….. .a z
ww
RE= ab* w
S= a, ab, abb, abbb, …..
RE (examples)

➢Exhibit the language L (a* · (a + b)) in set notation. c o


OR
m
convert given RE in
language form g .
t i n
L (a∗ · (a + b)) = L (a*) L (a + b) p u
o m
= (L (a) (L (a) 𝖴 L (b))c
*

e e
.
= {^, a, aa, aaa,z
a ...} {a, b}
w w
= {a, aa, aaa, ..., b, ab, aab, ...} .
w
RE (examples)

➢ Exhibit the RE (0 + 10*) in set notation.


o m
.c
we have RE = (0 + 10*) , we may write it as [ (0) + (1).(0)* ]
g
L = { 0, 1, 10,100,1000, …}
u it n
m p
co
ee
.a z
ww
w
o m
Lec 9 g .c
uit n
m p
co
ee
.a z
ww
w
Defining Languages
• A language can be defined in following ways:
o m
i. Descriptive g .c
ii. Recursive
u it n
iii. Regular Expressions (RE)
m p
iv. Finite Automata (FA) co
ee
.a z
ww
w
Finite Automata (FA)
m
• In FA we can represent language in form of diagram or graphically.
o
g .c
• FA are also known as:
uit n
• Finite Machine (FM)
• Finite Automatic Machine (FAM) m p
• Finite State Machine (FSM) co
e e
.a z
ww
w
FA (formal definition)
➢ A finite automaton is a 5-tuple (Q,,,q0,F), where m
.co
g
1. Q is a finite set called the states. (e.g. q0, q1,q2,q3..)
it n
u
2.  is a finite set called the alphabet. (e.g.  = {a,b})
p
om
3.  : Transition/movement c
e e
4. q0 is the start state.a
z
(initial state)
w w
5. w
F (final states).
FA Tuples definition
➢ q0 (start state or initial state)
o m
g .c
• Every finite automata always start with q0
uit n
m p
o
• In FA there will be only one initial state
c
e e
• It is represented by:
z
.a q or
ww 0

w
Cont…
➢ FA (Final state)
o m
g
number of final states can be more then 1. .c
• In FA the minimum number of final state should be 1 and maximum
it n
u
m p
• It means we may have more then 1 finial states in FA.
co
• At final state machine mayeestop or may not stop depend on our
language (input).
.a z
ww
w
It is represented by: + OR
Cont…
➢ Q (states/normal states)
o m
g .c
• These are the states other then initial and final sates.

t i n
u start nor finish.
• These are such states from with our FApneither
o m
• These are represented by: e c
z e
.a
w
➢  : Transition/movement
w
w is represent with
• Transition or movement sign.
Types of FA

o m
• There are two main types of FA
g .c
• NFA (non deterministic finite automata)
• DFA (deterministic finite automata)
u it n
m p
co
e e
.a z
ww
w
Theory of Automata
o m
g .c
u it n
Lecture-10p
o mAutomata(NFA)
e c
Non-Deterministic Finite
Part-1
z e
.a
w w
w
Types of FA
o m
• There are two main types of FA
g .c
• NFA (non deterministic finite automata)
• DFA (deterministic finite automata) u it n
m p
co
e e
.a z
ww
w
NFA
• NFA stands for non-deterministic finite automata.
o m
g .c
• The finite automata are called NFA when there t i n exist many paths for
specific input from the current state to p u next state.
the
o m
c
• In other words, the exact stateeto which the machine moves cannot
be determined. Hence, it is z
e
called Non-deterministic Automaton.
.a
w w
• In NFA empty statewtransition is also allowed
NFA examples

o m
g .c
it n
We have two choices

q1 puq2
o m
e c
q0 z e
w .a
w w q3
First Choice

o m
All input is consumed g .c
uit n
q1 p q2 “accept”
o m
e c
q0 z e
w .a
w w q3

68
Second Choice

o m
g .c
uit n
q1
m p q2
co
q0 ee
.a z
ww q3
w
69
Second Choice

o m
Input cannot be consumed g .c
u it n
q1
m p q2
co
q0 eeAutomaton Halts
.a z
ww q3 “reject”
w
70
An NFA accepts a string:
if there is a computation of the NFA
that accepts the string o m
c g .
it n
u
m p
i.e., all the input string is processed and the
automaton is in an accepting co state
e e
.a z
w w
w
71
aa is accepted by the NFA: m
.co
it ng
“accept” u
q1 q2 m p q1 q2
co
e
ze q0
q0
q3 .a q3 “reject”
because this
w w
w
computation this computation
accepts aa is ignored
72
An NFA rejects a string:
if there is no computation of the NFA
that accepts the string.
o m
g .c
it n
u
For each computation: mp
All the input c o
is consumed and the
• e
eis in a non final state
automaton
a z
w .
w w OR
• The input cannot be consumed
73
Rejection example

o m
g .c
uit n
q1
m p q2
co
q0 ee
.a z
ww q3
w
74
First Choice

o m
“reject” g .c
uit n
q1
m p q2
co
q0 ee
.a z
ww q3
w
75
Second Choice

o m
g .c
uit n
q1
m p q2
co
q0 ee
.a z
ww q3
w
76
Second Choice

o m
g .c
uit n
q1
m p q2
co
q0 ee
.a z
ww q3 “reject”
w
77
Another Rejection example

o m
g .c
uit n
q1
m p q2
co
q0 ee
.a z
ww q3
w
78
First Choice

o m
g .c
uit n
q1
m p q2
co
q0 ee
.a z
ww q3
w
79
First Choice

o m
Input cannot be consumed g .c
uit n
q1 p q2 “reject”
o m
e c
q0 z e
w .a Automaton halts
w w q3

80
Second Choice

o m
g .c
uit n
q1
m p q2
co
q0 ee
.a z
ww q3
w
81
Second Choice

o m
Input cannot be consumed g .c
u it n
q1
m p q2
co
q0 ee Automaton halts
.a z
ww
w q3 “reject”

82
is rejected by the NFA:
o m
g .c
n
it “reject”
pu
q1 q2
o m q1 q2
e c
ze
q0 q0
q3 .a
“reject”
ww q3

w
All possible computations lead to rejection
83
is rejected by the NFA:
o m
g .c
“reject” uit n
q1 q2 m p q1 q2
co
e
ze q0
q0
q3 .a q3 “reject”
ww
w
All possible computations lead to rejection
84
Theory of Automata
o m
g .c
u it n
Lecture-11p
o mAutomata(NFA)
e c
Non-Deterministic Finite
Part-II
z e
.a
w w
w
Language accepted: L = {aa}
o m
g .c
uit n
q1
m p q2
co
q0 ee
.a z
ww q3
w
Lambda Transitions
o m
g .c
u it n
m p
co
e e
q0
.a z
q1 q2 q3
ww
w
o m
g .c
u it n
m p
co
ee
q0
.a z
q1 q2 q3
ww
w
o m
g .c
u it n
m p
co
ee
q0
.a z
q1 q2 q3
ww
w
input tape head does not move

o m
g .c
u it n
m p
co
ee
q0
.a z
q1 q2 q3
ww
w
all input is consumed

o m
g .c
u it n
m p
o “accept”
e c
q0 z
q1e q2 q3
.a
ww
w
String aa is accepted
Rejection Example

o m
g .c
u it n
m p
co
ee
q0
.a z
q1 q2 q3
ww
w
o m
g .c
u it n
m p
co
ee
q0
.a z
q1 q2 q3
ww
w
(read head doesn’t move)

o m
g .c
u it n
m p
co
ee
q0
.a z
q1 q2 q3
ww
w
Input cannot be consumed

o m
g .c
Automaton halts u it n
m p
o “reject”
e c
q0 qe1
z q2 q3
w.a
w w
String is rejected
o m
Language accepted: L = {aa} g .c
t i n
pu
o m
e c
q0 z
q1e q2 q3
.a
ww
w
Another NFA Example

o m
g .c
uit n
m p
co
a ee
q0 .a z
q1 b q2 q3
ww
w
a b m
.co
it ng
pu
o m
e c
a z
q1e b q2 q3
q0 .a
ww
w
a b m
.co
it ng
pu
o m
e c
a z
q1e b q2 q3
q0 .a
ww
w
a b m
.co
it ng
pu
o m“accept”
e c
a z
q1e b q2 q3
q0 .a
ww
w
Another String

a b a b m
.co
it ng
pu
o m
e c
a z e b q3
q0
w .a q1 q2
w w
a b a b m
.co
it ng
pu
o m
e c
a z e b q3
q0
w .a q1 q2
w w
a b a b m
.co
it ng
pu
o m
e c
a z e b q3
q0
w .a q1 q2
w w
a b a b m
.co
it ng
pu
o m
e c
a z e b q3
q0
w .a q1 q2
w w
a b a b m
.co
it ng
pu
o m
e c
a z e b q3
q0
w .a q1 q2
w w
a b a b m
.co
it ng
pu
o m
e c
a z e b q3
q0
w .a q1 q2
w w
a b a b m
.co
it ng
pu
o m“accept”
e c
a z e b q3
q0
w .a q1 q2
w w
Theory of Automata
o m
g .c
u it n
Lecture-12p
o mAutomata(NFA)
e c
Non-Deterministic Finite
Part-III
z e
.a
w w
w
NFA Examples

o m
• Draw NFA for RE = a
g .c
uit n
q0
a
q1 m p
co
e e
.a z
ww
w
NFA Examples
o m
• Draw NFA for RE = a + b
g .c
uit n
q0
a
q1 m p
b co
e e
.a z
ww
w
NFA Examples
o m
• Draw NFA for RE = ab
g .c
uit n
q0
a
q1
m pb
q2
co
ee
.a z
ww
w
NFA Examples
m
➢ Draw NFA for string that end with ‘aa’ defined over ∑ = {a, b}.
o
• First we nee to write its RE g .c
RE= ? aa
uit n
= (a+b)*aa m p
co
a, b
e e
a .a z a
q0
ww q1 q2

w
NFA Examples

➢ Draw NFA for all strings defined over ∑ = {a} o m


• We have only one letter in given alphabet. g .c
t i n
u
• So language should be {^, a, aa,aaa,aaaa….}
p
RE = (a)*
o m
a
e c
z e
.a
q
0
w w
w
NFA Examples
➢Draw NFA for all strings that starts with ‘a’ and end with ‘bb’, defined
m
over alphabet ∑ = {a, b}.
.co
g
• The string that will be generated according to given condition may be of
it n
following type
pu
S= a ?? bb
o m
= a [^, a, b, ab, aaa,bbb…] bb c
e
e a, b
RE = a (a+b)* bb
.a z
w w b b
q0 w a
q 1
q2 q3
NFA Examples
➢ Draw a NFA for all possible strings start and end with same letter defined
over alphabet ∑ = {a, b}.
• Given condition means if string start with ‘a’ then it alsoo m end with ‘a’ or if it
start with ‘b’ then it also end with ‘b’ g . c
• L1= { a ?? a} t i n a, b

pu a
= {a (a+b)*a}
o m q1
q 2

• L2= {b ?? b}
e c a

= {b (a+b)*b} z e q b
.a 0
b

w w q 3

RE= a(a+b)*a +wb (a+b)* b a, b


NFA Examples
➢ Draw a NFA for all possible strings start and end with different letter
defined over alphabet ∑ = {a, b}.
o
• Given condition means if string start with ‘a’ then it should
m end with ‘b’ or if
it start with ‘b’ then it should end with ‘a’ g . c
• L1= { a ?? b} t i n a, b

p u b
= {a (a+b)*b}
o m 1q q2

• L2= {b ?? a}
e c a

= {b (a+b)*a} z e q a
.a 0
b

w w q 3

RE= a(a+b)*b +wb (a+b)* a a, b


NFA Examples
➢Draw NFA for all the strings that contains ‘aa’, defined over alphabet ∑ = {a,
b}.
o m
.c
• According to given condition in our language there should be ‘aa’ in every
g
• L= { aa, aaa, abaa, baab, aabba, bbbabaa….} u it n
string so our defined language may be be of following type

p
• AS we see in our language “aa” may be in start or in end or in between any
m
letter defined over alphabet ∑ = {a, b}.
co
ee
• RE= (a+b)* aa (a+b)*
.a z
a, b
ww a, b
w a a
q0 q1 q2
NFA Examples
• Draw NFA for string that contain at least one ‘a’ and end with ‘b’ defined
m
over alphabet ∑ = {a, b}.
.co
it ng
• Language will be L= { ?? a ?? b } pu
• RE = { (a+b)* a (a+b)* b} o m
e c
a, b
.a ze a, b

ww
a b
q0
w q1 q2
Theory of Automata
o m
g .c
uit n
Lecture-13 m p
c o
Deterministic Finite Automata(DFA)
e e
.a z
w w
w
DFA (Deterministic Finite Automata)
➢ Remember 3 points for DFA
o m
g .c
i. no empty string
u it n
p
ii. No. of transaction from each sate is equal to number of letters
m
given in alphabet.
c o
e
• For example, if ∑ = {a, b}. This alphabet
beetwo transaction. (two arrows on each state)
has two letter i.e, a and b. That means
from every state there will z
.a
iii. It may also contains
w
• Reject state is a state
w reject state.
which never allow us to reach final state
w
DFA (Deterministic Finite Automata)

To accept a string: o m
g .c
it n
isuscanned
all the input string p
omis accepting
and the last state
c
ee
To reject a string: .a z
all the
w winput string is scanned
w
and the last state is non-accepting
DFA Examples

o m
• Draw DFA for RE = a, defined over ∑ = {a, b}.
g .c
u
accept state
it n
q1
a
q2 m p q1
a
q2

co
e
ze b
a a,b
b OR b
.a
w w
q
3

reject state
q3

w
reject state a, b a, b
DFA Examples
➢ Draw DFA that starts with ‘b’, define over alphabet ∑ = {a, b}.
m
.co
• The RE of above statement will be: RE= b (an+gb)*
u t i
m p
c o
a, b

b e e
q0
.a z q1
accept state

w w a, b
aw
q2
reject state
DFA Examples
➢ Draw DFA for string that starts with ‘ab’, define over alphabet ∑ =
m
{a, b}.
.co
i ng
• The RE of above statement will be: RE= uabt (a + b)*
m p
c o a, b

a e e
q0
.a z q
b
1 q2 Accept state

w w a
wb q3
reject state
a, b
DFA Examples
➢ Draw DFA for string that starts with ‘aba’, define over alphabet ∑ =
{a, b}. o m
g . c
t
• The RE of above statement will be: RE= aba i n
(a + b)*
pu a, b

o m
a
e c b a
q0
z e q1 q 2 q3

.a accept state

w wb
a
b
w q4 a, b
reject state
DFA Examples
➢Draw DFA for language that has ‘b’ as second letter define over
alphabet ∑ = {a, b}. o m
.c
• The RE of above statement will be: RE= ( a+nb)gb (a + b)*
u t i
m p a, b

a,b c o
q
e e q
b
q
0

.a z 1 2

accept state

w w a
w q3
a, b
reject state
Theory of Automata
o m
g .c
uit n
m
Lecture-14 p
c o
Transition Table
e e
.a z
ww
w
Transition Table
o m
g .c
• Transition table is tabular representation of transition function.

t i n
u
• Transition table can be generated fromptransition diagram.
• For example diagram of FA
o m
e c
e specific transition take place from
• Transition table shows thatzwhich
specific state. . a
w w
w
• We write all states in column and transitions in a row.
Example
1, 0 o m
g .c 0 1
q1
0
q2
q ti
n
1
pu 0 q3 q1

q0
o m q1 q1
0
1
e c q1, q2
q3
z e
.a
q2 - -
1, 0

ww q3 q3 q3, q2
w
Examples

a, b
o ma, b

g .c
q0
a
q1
a
t i n
pu q
2

o m
c
e a
z e b

w
q0
.a q0, q1 q0

qw q2 -
w 1

q2 q2 q2
Example 1, 0

1 0 1
q0 q1 q2
o m q3

.c
0 ng
1
0
u t i
q 1, 0 p
4

o m
e c
z e 1 0
q0
w.a q1 q4
q1
q2 w w q4
q3
q2
q4
q3 q3 q3
q4 q4 q4
Theory of Automata
o m
g .c
uit n
m
Lecture-15 p
DFAc o
VS NFA
e e
.a z
ww
w
NFA VS DFA
m
• In NFA dead configuration is allowed, in DFA dead configuration is not
o
allowed.
g .c
➢ Example
u it n
• Draw NFA & DFA for RE = 1, defined over ∑ = {1, 0}.
p
o m
e c 1
1 z e q1 q2

q1 q.a
1,0
ww 2

0
NFA w q3
1, 0

DFA
NFA VS DFA
• In NFA multiple transactions are allowed correspond to input while in
o m
DFA multiple transactions are not allowed correspond to input.
➢ Example g .c
u it n
• Draw NFA and DFA for RE= (a+b)*b, defined over ∑ = {a, b}.
m p
co
a, b
e e a
b

b
.a z b
q0 q1
ww q0 q1
a
NFA w
DFA q2
a, b
NFA VS DFA
m
• Empty transaction is allowed in NFA while in DFA no empty transaction
o
is allowed.
g .c
u it n
• NFA features is not associated with real computers while DFA features is
p
associated with digital computers.
o m
e c
z e
• Designing and understanding of NFA is easy and simple while designing
.a
and understanding of DFA difficult.
w
w w
Theory of Automata
o m
g .c
uit n
m
Lecture-16p
co
TG
e e
.a z
ww
w
Transition Graph (TG)
➢ It is a method to define a language. m
• Properties of TG are given below: .co
I. Number of states should be finite. it ng
pu
II. There must be at least one initial state and one final state.
m
• initial and final states can be more than one
o
III. No dead end state. e c
z e
IV.
V. w .a
Multiple transitions are allowed.
Can read more than one character at a time.
VI. w w
It allows null transactions.
TG Examples
1
• Draw transition Graph (TG) of RE= 1*(1+ 0)
oqm 1
1
g .c 0 q1

u it n 1

q0
1,0
q1
m p q2
0
q3

co
1 ee1
.a z q0 1

q0
1
q w
w q1
w
1
1

0 0
q2
q2
TG Examples
• Draw a TG that accepts all words with aa or bb defined over ∑ = {a, b}.
RE= (a+b)* (aa + bb) (a+b)* o m
a, b
g .c a, b
a, b
a, b
u it n aa

a a m p q0 q1

q0 q1 q2
co bb

e e q2
a, b
b q3 b z
.a a, b a, b

ww aa a, b
w q0 q1
aa, bb
a, b

a, b q0 q1
bb
q0
Theory of Automata
o m
g .c
u it n
m
Lecture-17p
co
Kleene’s Theorem (part 1 & 3)
e e
.a z
ww
w
Kleene’s Theorem
➢ Kleene’s Theorem has three parts: o m
g .c
1) i n
If language can be accepted by FA (Finite tAutomata) then it can also
be accepted by TG (Transition Graph).pu
o m
2) If language can be acceptedeby
c
e TG (Transition Graph) then it can also
a z
be expressed by RE (Regular
. Expression).

w w
3) If language canwbe expressed by RE (Regular Expression) then it can be
accepted by FA (Finite Automata)
Kleene’s Theorem Proof (part 1)
• If language can be accepted by FA (Finite Automata) then it can also
be accepted by TG (Transition Graph).
o m
• Lets S= aba
g .c
u it n
m p
a b a co
q0 q1
e
q2
e q 3
aba

b.a
z q0 q1
a
b ww a, b
w
q4
reject state
a, b
Kleene’s Theorem Proof (part 3)
• If language can be expressed by RE (Regular Expression) then it can be
accepted by FA (Finite Automata) o m
g .c
• language that has ‘b’ as second letter define over alphabet ∑ = {a, b}.
RE= ( a + b) b (a + b)*
u it n
m p a, b

a,b c o
q0
eeq b
q2

.a z 1

ww a
w q3
a, b
reject state
Theory of Automata
o m
g .c
u it n
m
Lecture-18 p
co
Kleene’s Theorem (part 2)
e e
.a z
ww
w
Kleene’s Theorem Proof (part 2)
➢If language can be accepted by TG (Transition Graph) then it can also be
expressed by RE (Regular Expression). o m
g .c
➢ For the proof of part 2, we need to remember following rules;
u it n
m p then introduce a new start
Rule 1: If a TG has more than one start states,
state connecting the new state to the old start states by the transitions
co
labeled by Λ and make the old start states the non-start states.
e e
b b .a z b b
q0
aa
q1
ww ^ q0
aa
q1

a
w
a
s
^ a a
q q q3
q2 3 2

bb bb
Kleene’s Theorem Proof (part 2)

m a new
Rule 2: If a TG has more than one final states, then introduce
o
.c
final state, connecting the old final states to the new final state by the
g
transitions labeled by Λ.
u it n
m p b
b b co b
^ q0 q1
e e ^ q0 q1
s
aa
.a z s
aa
^
f
a a
^ q2
a
ww
q3 ^ q2
a q3 ^
bb w bb
Kleene’s Theorem Proof (part 2)
Rule 3: If a state has two (more than one) incoming transition edges,
o m
then replace all these transition edges with a single transition
edge labeled by the sum (+) g .c
u it n
m p
a c co c+d
e e a+b
q0
b
q1
.a z q0 q1

wwd
w
Kleene’s Theorem Proof (part 2)

m
Rule 4 (state elimination): If three states in a TG, are connected in
o
.c
sequence then eliminate the middle state and connect the first state with
g
the third by a single transition.
u it n
r m p
co
a b e
ze
q0 q1 q2 ar* b
q0 q2
.a
ww
w
TG to RE Example
• We have TG:
b a
a
o m
( (^ a* b). b*.a). a*. ^

q0
b q1
a
q2 g .cs f

b
u it n
^
a
b m
a
p a

s q0 q1
co q2 ^ f
e
eb
.a z a
s
^ a* b
ww q1
a
q2 ^ f
w
a
s
(^ a* b). b*.a ^
q2 f
Mealy Machine
• Mealy Machine is Finite Automata (FA)
o m
g .c
• A Mealy Machine is an FSM whose output depends on the present
state as well as the present input.
u it n
m p
co FA

e e
.a z
FA without FA with

ww O/P O/P

TG
w NFA DFA
Mealy Moore
Machine Machine
Tuples of Mealy Machine
➢ A Mealy Machine has 6-tuple 6-tuple (Q,,, q0, O, λ ), where
o m
1. 0, 1
g .c
Q is a finite set called the states. (e.g. q q , q ,..
2 ..)

2. t
 is a finite set called the alphabet. (input i nalphabet e.g.  = {a,b})
p u
3.  : Transition/movement: Q ×o∑m →Q
e c
4. z estate)
q is the start state (initial
0
.a
5. O is a finite set w
w
of symbols called the output alphabet
w
6. λ is the output transition function where λ: Q × ∑ → O
How to Design Mealy Machine (Example 1)
• Design a Mealy Machine from given Transition Table
o m
g .c 0/c , 1/b

Next State
uit n 0/b

Present state Input= 0 Input= 1


m p 1/c
state output state output
co q1
q3

e
ze
q0 q1 a q2 a
q0
q1 q1 b q3 c
.a q2
0/c
q2
q3
q3
q3
c
c
ww
q2
q3
a
b
w
1/a
Mealy Machine (Example 2)
m
• Find the output of a string “011011” by given mealy machine
o
0/c , 1/b
g .c
0/b

uit n
1/c m p
• We have given string:
q1
q3
co string= 0 1 1 0 1 1
q0 e e Output= a c b c b b
q2 .a
0/c z
ww
w
1/a
Mealy Machine (Example 3)
• Design a Mealy Machine that produce 1’s compliment of any binary input string.
o m
g .c
t i n
Suppose we have string:
1/0
pu string= 0 1 1
binary 1’s
o m
compliment
e
q0 c
ze
1 0 0 1 1
q0 q0 q0 q0
0 1
.a 0/1
ww 1 0 0

w
Moore Machine
o m
.c
• Moore Machine is Finite Automata (FA) with output
g
u it n
m p
• A Moore Machine is an FSM whose output depends only on the
present state.
co
e e
.a z
w w
w
Tuples of Moore Machine
➢ A Moore Machine has 6-tuple (Q,,, q0, O, λ ), where
o m
1. 0, 1
g .c
Q is a finite set called the states. (e.g. q q , q ,..
2 ..)

2. t
 is a finite set called the alphabet. (input i nalphabet e.g.  = {a,b})
p u
3.  : Transition/movement: Q ×o∑m →Q
e c
4. z estate)
q is the start state (initial
0
.a
5. O is a finite set w
w
of symbols called the output alphabet
w
6. λ is the output transition function where λ: Q → O
How to Design Moore Machine (Example 1)
• Design a Moore Machine from given Transition Table
o m
g .c
Next State
u it n 0 0
Present state
Input 0 Input 1
output
m p 1
q0 q1 q2 a
co q1 / c q3 / b
e
ze
q1 q1 q3 c q0 / a
1
q2 q2 q3 a
.a 1
q3 q3 q2
ww b
q2 / a

w
0
Moore Machine (Example 2)
• Find the output of a string “101100” by given Moore machine
o m
.c
• We have given string:
g
0 0
u it n
string= 1 0 1 1 0 0
1
m pOutput= a a a b a a a
q1 / c
co
q3 / b

q0 / a e
1e
1

.a z
q2 / a
ww Note
w
0
• In Moore machine output of string will always be: n+1
• In Mealy machine out put of string will always be: n
• Where n in length of string
Moore Machine (Example 3)
• Design a Moore Machine that produce 1’s compliment of any binary input string.
o m
g .c
binary 1’s
u it n 0

1
compliment
0 m p 0 q1 / 1

0 1 co q0 / 0
e 1

ze
0
1
Suppose we have string:
.a 1
string= 1 1 0
ww q2 / 0

1
w1 0
q0 q2 q2 q1

0 0 1
Mealy to Moore Conversion
• Convert the given Mealy Machine into Moore Machine.
o m
0/c , 1/b
g .c q1/b
0/b

uit n q1/a

1/c m p
q1
q3
co
q0 e e q0 q 3 /c

q2
0/c
.a z
ww q 2 /a

Mealy Machine w q 3 /b

1/a
Moore Machine
Mealy to Moore Conversion using transition table
• Construct Moore Machine transaction table from given Mealy transition table

o m
Mealy Transition Table
g .c
Next State n state
it Present Next State
output

Present state Input= 0 Input= 1 pu Input 0 Input 1

state output state output


o m q0 q0, a q2, a a
q0 q0 a q2 a
e c q1 q1', b q30, c b
q1 q1 b q3
z e c q2 q30,c q2, a a
q2 q3 c q2
w .a a q30 q30,c q31,b c
q3 q3 c

w wq3 b
q31 q30,c q31,b b

Moore Transition Table


Mealy to Moore Conversion using transition table
• Construct Moore Machine transaction table from given Mealy transition table

o m
Mealy Transition Table
g .c
Next State n state
it Present Next State
Present state Input= 0 Input= 1 pu Input 0 Input 1
output

state output state output


o m q0 q0 q2, a
q0 q0 a q2 a
e c q1 q1 q30 b
q1
q2
q1
q3
b
c
q3
q2
.a ze c
a
q2
q30
q30
q30
q2
q31
a
c
q3 q3 c
ww
q3 b q31 q30 q31 b

w Moore Transition Table


Moore Machine to Mealy Machine Conversion
• Convert given Moore Machine into Mealy Machine
o m
g .c
0 0

uit n 0/c 0/b

q1 / c
1
q3 / b m p 1/b

co q1 q3
q0 / a
1 e q0
ze
1/b
1 1/a
q2 / a .a
ww q2

Moore Machine
0 w 0/a Mealy Machine
Moore Machine to Mealy Machine Conversion
• Design a Mealy machine from given Moore machine. m
.co
0 i/n
g
0
u t 0
q1 /1
m p q1
q0 / 0 1
co q0 1/0
1
ee 1/1
0
q2 / 0 .a z 0/0
q2

ww
Moore Machine w Mealy Machine
Moore to Mealy Transition Table conversion
Construct a Transition table of given Moore machine and convert it into
transition table of Mealy machine.
o m
Present state .c
Next State

i n g Input 0 Input 1
output

0 u t q0 q0 q1 0

q1 /1
m p q1 q2 q0 1

q0 / 0 1 co q2 q0 q1 0

ee
0
1

.a z Next State

ww
q2 / 0 Present state
Input= 0 Input= 1

w q0
state
q0
output
0
state
q1
output
1
q1 q2 0 q0 0
q2 q0 0 q1 1
Pumping Lemma
• Pumping Lemma is used to find out whether the language is regular or not.
o m
• There are two types of language finite and infinite. g .c
u it n
• Finite language in always regular.
m p
c o
• Infinite language may be a regulare or may be non-regular
e to find language is regular or not.
• Pumping Lemma is one of thezmethod
. a
• Pumping Lemma performs
w w negative test.
w lemma test on language and language pass that test, than there
• if we apply pumping
will be no surety that language is regular or non-regular.
• If language fail pumping lemma test, then it is sure that language is non-regular
Steps for pumping Lemma Test
1. Suppose language is regular.
o m
.c
2. If language is regular then we can make its Finite Automata.
g
3. Suppose finite automata has 8 states.
u it n
m p
o
4. Take word of length greater than states
c
e e
• Make sure that length of .Xa
z
5. Divide word into 3 parts i.e; x,y,z
+ Y <= N

6. X and Z can be Nullw w


but Y can not be Null. Y>=1
w
7. Will decide language is regular or not
pumping Lemma for Regular Language (Example)
1) Suppose language is regular. ➢ Prove that language is regular for all the
2) If language is regular then we o m
strings ending with “bab” defined over
can make its Finite Automata. ∑ = {a, b}.
g .c
3) Suppose finite automata has 8 • We suppose
t i nlanguage is regular, than we can
states. u
make its
p FA. (step 1 & 2)
4) Take word of length greater than
states o m
• N=8 (step 3)

5) Divide word into 3 parts i.e; x,y,z e c• Word= aabbababab (step 4)


z e
1) Make sure that length of X + Y <= N • Length of x= 4, y=3, z=3 (step 5)

w .a
6) X and Z can be Null but Y can not • Increase power of Y (step 7)
be Null. Y>=1
w w • X= aabb ; y= aba; z= bab
7) Increase the power of Y (pump Y) • X YY Z
to decide language is regular or String belong to
not • aabbabaababab Language (L), Hence L is
RL
pumping Lemma for Non-Regular Language
(Example)
1) Suppose language is regular. ➢Prove that language is non-regular for L
2) If language is regular then we o m
is an bn over ∑ = {a, b}.
can make its Finite Automata. .c
➢Our language can be L= {ab, aabb,
g
3) Suppose finite automata has 8
states. u it n
aaabbb, aaaabbbb,…….}
• We suppose language is regular, than we can
4) Take word of length greater than
m p
make its FA. (step 1 & 2)
states
co
• N=8 (step 3)
5) Divide word into 3 parts i.e; x,y,z
e e • Word= aaaaabbbbb (step 4)

.a z
1) Make sure that length of X + Y <= N • Length of x= 1, y=4, z=5 (step 5)

be Null. Y>=1 ww
6) X and Z can be Null but Y can not • Increase power of Y (step 7)
• X= a; y= aaaa; z= bbbbb
w
7) Increase the power of Y (pump Y) • X YY Z
to decide language is regular or String does not belong to
not • a aaaaaaaabbbbb Language (L), Hence L is
non RL
o m
g .c
uit n
m p
co
ee
.a z
ww
w
Decidability

o m
• Decidability is making decision about following:
g .c
• Is given FA/RE accept any string or not? u it n
p
• Is given FA/RE represents finite or infinite language?
m
co
• Whether two languages are equivalent or not?
e e
• The problems that solve.a z
in finite steps and their answer is Yes or No,
w w
such problems are called decidable problems.
w
Decidability
➢ Decide whether given FA/RE accept any string or not?
o m
➢ To find out that given FA/RE accept any string or not
g . c
➢ We will perform following steps on given FA, If we have
t i n
given RE then first we
construct FA from RE then we perform following steps.
p u
• Mark the initial state.
o m
• Mark the states that are connected with
e c initial states.
• Remove the edges that connectzinitial e state with other states.
• Remove the edges of next marked .a state and if next marked state edges
connected with another state
w w then also marked that state.
w
• Repeat the above process until final state is marked
• If we are unable to reach to final state, it means our FA does not accept any string
• If we reach to final state, it means our FA accept any string
Decidability (Example)
• Is given FA/RE accept any string or not?

o m• Mark the initial state.

g .c • Mark the states that are connected

uit n •
with initial states.

Remove the edges that connect

m p •
initial state with other states.

co Remove the edges of next marked


state and if next marked state edges

e e connected with another state then


also marked that state.

.a z • Repeat the above process until final

ww state is marked
• If we are unable to reach to

w final state, it means our FA


does not accept any string
• If we reach to final state, it
means our FA accept any string
Cont..
• After performing the desired steps, our final automata will be in following form, as we
can see that we are unable mark the final state. o m
.c
• So we can conclude that given FA will not accept any string.
g
u it n
m p
co
e e
.a z
ww
w
Cont..
Lets suppose in our example, transaction is performed from q3 to q4.
o m
g .c
u it n
m p
co
e e
.a z
ww
w
Context Free Grammar (CFG)
• Grammar consist of set of rules to construct a sentences in a language.
o m
• CFG is used to generate all possible pattern of strings in given finite
language.
g .c
it n
• It consist of set of production rules that generates the string of language.
u
p
• CFG can be defined by four tuples. CFG = (V,T,P,S)
m
c o
e
• V= finite set of variables (non terminals)
e
• V always denoted by capitalzletters
.a
w
• T= finite set of terminals
w
(V∩T=∅)
• T always denoted by
w small letters and terminals help to generate string
• P= production rules (substitution rules)
• S= start variable
CFG Tuples Example
• V= finite set of variables (non terminals)
o m
• V always denoted by capital letters
g .cS aS1
• T= finite set of terminals ( V ∩ T = ∅ )
• T always denoted by small letters and terminals
u it n S ε
help to generate string
m p
V= S
• P= production rules (substitution rules)
co T= a, 1, ε
• S= start variable
e e
.a z S aS1 | ε
ww
w
RE to CFG Conversion (Examples)
1) RE= a+b 2) RE= (a+b) (a+b) 4) RE= (a+b) (aa+bb) (a+b)
S AA o m
S a|b
A a|b
S ABA
g .c
or A. a|b
u it n
B. YY | ZZ
S a 3) RE= (a+b)a + ab
m p
S b
S X Y co
Y. a
or X JK ee Z. b
S X|Y J. a|b .a z
X. a K. a
ww
Y. b
Y
B
w
KB
b
CFG Derivation
• Derivation is generation of string from grammar. m
.co
• We can use CFG derivation to find out:
it ng
• Which string is produced by grammar
pu
• specific string is generated by grammar or not
o m
e c
e
• We can draw derivation tree to find out string produced by grammar
z
w .a
w w
CFG Derivation (Example)
• Find out the string generated by given CFG
o m
g .c S

u it nX Y

m p ε
co bbX aY ε

e e
will be: .a z
string generated by given grammar bbX ε aY ε

bbbbbbaaa w
w ε
w
In general: b2n an ; n>=1
bbX
aY ε

ε ε
CFG Derivation (Example)
• Find out is “baab” valid string of given CFG?
o m
g .c
S A B n
ti A
A
S
S
a|b
a|b puB
YY|ZZ A
S o m
a|b aa|bb A
Se c a|b aa|bb a|b
z e
w .a Yes, baab is valid string for given grammar
w w
Chomsky Normal Form (CNF)
m
• A Context Free Grammar (CFG) is in Chomsky Normal Form (CNF) if:
o
g .c
i. i n
Non-Terminal variable represents exactly twotnon-terminal variables
p u
ii. m
Non-Terminal variable represents exactly
o one terminal variable

e c
z e
.a
w w
w
Push Down Automata (PDA)
• PDA is a way to implement a context-free grammar (CFG) into
m
diagrammatic form.
.co
it ng
u
• Its implementation is same as DFA, but DFA has finite memory and PDA
p
has infinite memory.
o m
e c
z e
• It use stack data structure (LIFO)
w .a
w say PDA is =
• In simple words wewcan finite state machine + Stack
PDA (General Block Diagram)

Input o m
Tape
a b c
g .c
uit n
Read
m p POP
Header
co PUSH

e e
.a z
w
Finite Control Unit
w
STACK

w
PDA Tuples
• A PDA can be formally described as a 7-tuple (Q, ∑, S, δ, q0, Z0, F)
o m
Q is the finite number of states g .c
∑ is input alphabet u it n
q0 is the initial state (q0 ∈ Q) m p
co
F is a set of accepting states
e e
z
Z0is bottom/initial stack top symbol
.a
S is stack symbols
ww
w
δ is the transition function: Q × ∑ × S Q × S*
Pushdown Automata (PDA) Example
• Construct a PDA for language; L= anbn where n>=1. m
.co
Input it ng
Tape
pu
o m
e c
Finite Control z e
Unit
w .a
w w
Stack
Turing Machine (TM)

o m
RE CFL
g .c
it n
TM

pu
o m
Finite
Automata
Push Down
e c
z e
Automata

w.a
w w
TM Tuples
• A TM can be formally described as a 7-tuple (Q, ∑, τ, δ, q0, B, F)
o m
Q is the finite number of states g .c
∑ is input alphabet u it n a b
I/O Tape

q0 is the initial state (q0 ∈ Q) m p Read write

co Header
F is a final state
e e Finite Control
B is blank
.a z Unit

τ is symbols allowed on w
tape
w w
δ is the transition function: Q×τ Q x τ x (L,R)
Turing Machine Example
➢ Design a TM for an bn where n >= 1
o m
B B a
g .c a b b B B
• If n =1; then L= ab n
• If n=2; then L= aabb uY t i Y, R

m p a a, R
a a, L
B B, R
co Y Y, L
e
q0
.
a
a zeX, R q1
b Y, L
q2

ww X X, R
Y w
Y, R
B B, R

Y Y, R

You might also like