You are on page 1of 24

Theory of Automata

Dr. Fouzia Jabeen


Recommended Books
1. Theory of Automata and Computation by
Dr. M.Skindar

2. Introduction to Automata Theory, Languages and


Computations by
John E. Hopcroft
Rajeev Motwani
Jeffrey Dullman
Finite Automata
Some Applications
Software for designing and checking the behavior of
digital circuits
Lexical analyzer of a typical compiler
Software for scanning large bodies of text (e.g., web
pages) for pattern finding
Software for verifying systems of all types that have a
finite number of states (e.g., stock market transaction,
communication/network protocol)

3
Finite Automaton (FA)
Informally, a state diagram that comprehensively captures
all possible states and transitions that a machine can take
while responding to a stream or sequence of input symbols
Recognizer for “Regular Languages”

Deterministic Finite Automata (DFA)


 The machine can exist in only one state at any given time
Non-deterministic Finite Automata (NFA)
 The machine can exist in multiple states at the same time

4
Deterministic Finite Automata - Definition
A Deterministic Finite Automaton (DFA) consists
of:
Q ==> a finite set of states
∑ ==> a finite set of input symbols (alphabet)
q ==> a start state
0
F ==> set of accepting states
δ ==> a transition function, which is a mapping
between Q x ∑ ==> Q
A DFA is defined by the 5-tuple:
{Q, ∑ , q ,F, δ }
0

5
Example #1
Build a DFA for the following language:
 L = {w | w is a binary string that contains 01 as a substring}
Steps for building a DFA to recognize L:
 ∑ = {0,1}
 Decide on the states: Q
 Designate start state and final state(s)
 δ: Decide on the transitions:
“Final” states == same as “accepting states”
Other states == same as “non-accepting states”

6
DFA for strings containing 01

• What makes this DFA deterministic? • Q = {q0,q1,q2}

1 0,1 • ∑ = {0,1}
0
• start state = q0
start 0 1
q0 q1 q2 • F = {q2}
Accepting • Transition table
state symbols
0 1
q0 q1 q0
states

q1 q1 q2
*q2 q2 q2

7
What does a DFA do on reading an input
string?
Input: a word w in ∑*
Question: Is w acceptable by the DFA?
Steps:
Start at the “start state” q
0
For every input symbol in the sequence w do
 Compute the next state from the current state, given the current
input symbol in w and the transition function
If after all symbols in w are consumed, the current state
is one of the accepting states (F) then accept w;
Otherwise, reject w.

8
Finite Automata : Examples action
On/Off switch
state

Modeling recognition of the word “then”

Start state Transition Intermediate Final state


state

9
Languages & Grammars
 Languages: “A language is a
Or “words” collection of sentences of finite
length all constructed from a
finite alphabet of symbols”
 Grammars: “A grammar can
be regarded as a device that
enumerates the sentences of a
language” - nothing more,
nothing less

 N. Chomsky, Information and


Control, Vol 2, 1959

Image source: Nowak et al. Nature, vol 417, 2002


10
Kleene Star Closure
 Given Σ, then the Kleene Star Closure of the alphabet Σ,
denoted by Σ*, is the collection of all strings defined over Σ,
including Λ.
 It is to be noted that Kleene Star Closure can be defined over
any set of strings. For example
 If Σ = {x}
 Then Σ* = {Λ, x, xx, xxx, xxxx, ….}
 If Σ = {0,1}
 Then Σ* = {Λ, 0, 1, 00, 01, 10, 11, ….}
 If Σ = {aaB, c}
 Then Σ* = {Λ, aaB, c, aaBaaB, aaBc, caaB, cc, ….}
 Question, Finite or infinite length lang generated by KSC ?
Plus Operation(⁺)
Plus Operation is same as Kleene Star Closure except that it
does not generate Λ (null string), automatically.
Example :
If Σ = {0,1}
Then Σ⁺ = {0, 1, 00, 01, 10, 11, ….}
If Σ = {aab, c}
Then Σ ⁺ = {aab, c, aabaab, aabc, caab, cc, ….}
Recursive definition of Languages
The following three steps are used in recursive definition
Some basic words are specified in the language.
Rules for constructing more words are defined in the
language.
No strings except those constructed in above, are allowed
to be in the language.
Defining language of integer
Step 1: 1 is in INTEGER.
Step 2: If x is in INTEGER then x+1 and x-1 are also in
INTEGER.
Step 3: No strings except those constructed in above, are
allowed to be in INTEGER.
Defining language ending in same letter.
 Defining the language L, of strings beginning and ending
in same letters , defined over Σ={a, b} .
 Step 1: a and b are in L
 Step 2: (a)s(a) and (b)s(b) are also in L, where s belongs to Σ*
 Step 3: No strings except those constructed in above, are allowed to
be in L.
Defining L containing one a
 Defining the language L, of strings containing exactly one
a, defined over Σ={a, b}.
 Step 1: a is in L
 Step 2: s(aa)s is also in L, where s belongs to b*
 Step 3: No strings except those constructed in above, are allowed to
be in L.
Regular Expression
 As discussed earlier that a* generates Λ, a, aa, aaa, … and a ⁺
generates a, aa, aaa, aaaa, …,
 Therefore the language L1 = {Λ, a, aa, aaa, …} and L2 = {a,
aa, aaa, aaaa, …} can simply be expressed by a* and a⁺,
respectively.
 a* and a ⁺ are called the regular expressions (RE) for L1 and
L2 respectively.
 Note a ⁺, aa* and a*a generate L2.
Regular expression
 Step 1: Every letter of Σ including Λ is a regular expression.
 Step 2: If r1 and r2 are regular expressions then
 (r1)
 r1 r2
 r1 + r2 and
 r1* are also regular expressions.
 Step 3: Nothing else is a regular expression.
Regular Expressions
 Consider the language L={Λ, x, xx, xxx,…} of strings,
defined over Σ = {x}.
 We can write this language as the Kleene star closure of
alphabet Σ or L=Σ*={x}* .
 This language can also be expressed by the regular
expression x*.
 Similarly the language L={x, xx, xxx,…}, defined over Σ = {x},
can be expressed by the regular expression x⁺.
 Now consider another language L, consisting of all possible
strings, defined over Σ = {a, b}. This language can also be
expressed by the regular expression (a + b)*.
Regular Expressions
 Now consider another language L, of strings having exactly
one a, defined over Σ = {a, b}, then it’s regular expression
may be b*ab*.
 Now consider another language L, of even length, defined
over Σ = {a, b}, then it’s regular expression may be ((a+b)
(a+b))*.
 Now consider another language L, of odd length, defined
over Σ = {a, b}, then it’s regular expression may be (a+b)
((a+b)(a+b))* or ((a+b)(a+b))*(a+b).
Regular expression
 Consider the language, defined over Σ = {a , b} of words
having at least one a, may be expressed by a regular
expression (a+b)*a(a+b)*.

 Consider the language, defined over Σ = {a, b} of words


having at least one a and one b, may be expressed by a
regular expression (a+b)*a(a+b)*b(a+b)*+
(a+b)*b(a+b)*a(a+b)*.
Regular expression
Consider the language, defined over Σ ={a, b}, of
words starting with double a and ending in double
b then its regular expression may be aa(a+b)*bb

Consider the language, defined over Σ ={a, b} of


words starting with a and ending in b OR starting
with b and ending in a, then its regular expression
may be a(a+b)*b+b(a+b)*a.
Activity
 Consider the language, defined over Σ ={a, b}, of words
starting with a and ending with b.
 Consider the language, defined over Σ ={a, b}, of words
containing only a’s
Recommended Readings
Chapter 3 of book “Linz,P.(Latest ed.)..An
Introduction to Formal Languages and Automata.
Jones & Bartlett Publishers”.

https://www.tutorialspoint.com/automata_theory/reg
ular_expressions.htm

You might also like