Module 1 FLAT
Module 1 FLAT
2
Syllabus – Course Content
Module -1 Teaching Hours: 08
INTRODUCTION TO THE THEORY OF COMPUTATION AND FINITE
AUTOMATA:
Three basic concepts, Some Applications, Deterministic Finite Accepters,
Nondeterministic Finite Accepters, Equivalence of Deterministic and
Nondeterministic Finite Accepters, Reduction of the Number of States in
Finite Automata.
Text Book 1: Chapter 1:1.2 - 1.3, Chapter 2: 2.1 - 2.4
Module -2 Teaching Hours: 07
REGULAR LANGUAGES, REGULAR GRAMMARS AND PROPERTIES OF
REGULAR LANGUAGES:
Regular Expressions, Connection between Regular Expressions and
Regular Languages, Regular Grammars, Closure Properties of Regular
Languages, Identifying Non-regular Languages.
Text Book 1: Chapter 3: 3.1 -3.3, Chapter 4: 4.1, 4.3
3
Module – 3 Teaching Hours 07
CONTEXT-FREE LANGUAGES AND SIMPLIFICATION OF
CONTEXT-FREE GRAMMARS AND NORMAL FORMS:
Context-Free grammars, Parsing and Ambiguity, Context-
Free Grammars and programming languages, Methods for
Transforming Grammars, Two important Normal Forms.
Text Book 1: Chapter 5: 5.1 -5.3, Chapter 6: 6.1 – 6.2
Module-4 Teaching Hours 06
PUSHDOWN AUTOMATA AND PROPERTIES OF
CONTEXT-FREE LANGUAGES:
Nondeterministic Pushdown Automata, Pushdown
Automata and Context–Free Languages, Deterministic
Pushdown Automata and Deterministic Context-Free
Languages, Two Pumping Lemmas, Closure properties and
Decision Algorithms for Context-Free Languages.
Text Book 1: Chapter 7: 7.1 – 7.3, Chapter 8: 8.1 -8.2
4
Module-5 Teaching Hours 08
TURING MACHINES AND OTHER MODELS OF TURING
MACHINES:
The Standard Turing Machine, Nondeterministic Turing
Machines, Linear Bounded Automata.
A HIERARCHY OF FORMAL LANGUAGES & AUTOMATA
Recursive and Recursively Enumerable Languages,
Unrestricted grammars, Context-Sensitive Grammars and
Languages, The Chomsky Hierarchy.
Text Book 1: Chapter 9: 9.1, Chapter 10:10.3, 10.5, Chapter
11: 11.1-11.4
5
Learning Resources
TEXTBOOK
1. Peter Linz, An Introduction to Formal Languages and Automat, (6e), Jones &
Bartlett Learning, 2016.
Reference Books
6
Outline Unit I
FINITE AUTOMATA
FA DFA
Reduction
Conversion
7
Major Topics
Finite Automata
1. Formal definition and examples
2. Design of FA
3. Definition of DFA and NFA
4. Equivalence of NFAs and DFAs
8
Major Topics (..contd)
Context-Free grammars
1. Formal definition and examples
2. Design of context-free grammars
3. Ambiguity
4. Chomsky normal form
5. Non-context-free languages definition and examples
6. Pumping lemma for CFLs
Pushdown Automata
1. Definition and examples
2. Converting a CFG to a PDA
Turing machines
1. Formal definition and examples
Decidability
1. Decidability and undecidability
2. The Church-Turing Thesis
3. Undecidability of the Halting problem
9
Applications of Automata Theory
10
Applications of Different Automata
11
Applications of Different Automata
12
Applications of Different Automata
13
Applications of Different Automata
14
Theory of Automata
15
Automata
➢ The term "Automata" is derived from the Greek word "αὐτόματα" which
means "self-acting".
16
Introduction to Formal Languages
Alphabet - Σ
An alphabet, Σ is any finite set of symbols.
Examples: ASCII, Unicode, {0,1} (binary
alphabet ), {a,b,c}.
Strings – s, w
The set of strings over an alphabet Σ is the set of
lists, each element of which is a member of Σ.
Strings shown with no commas, e.g., abc.
Σ* denotes this set of strings.
ε stands for the empty string (string of length 0).
17
Introduction to Formal Languages(..contd)
Example of Strings
{0,1}* = {ε, 0, 1, 00, 01, 10, 11, 000, 001, . . . }
• A language is a subset of Σ* for some alphabet
Σ.
• Example: The set of strings of 0’s and 1’s with no
two consecutive 1’s.
• L = {ε, 0, 1, 00, 01, 10, 000, 001, 010, 100, 101,
0000, 0001, 0010, 0100, 0101, 1000, 1001,
1010, . . . }
18
Introduction to Formal Languages(..contd)
Empty string:
Every alphabet ∑ has a special string called empty string which means the
string with zero occurrences of symbols.
19
Introduction to Formal Languages(..contd)
Length of a string:
The finite occurrence of input symbols form ∑
present the length of a string. If s denotes the
string over alphabet ∑ then length of a string is
represented by |S|.
20
Introduction to Formal Languages(..contd)
Power of an alphabet:
If ∑ is an alphabet, we can express the set of all strings
of a certain length form that alphabet by using an
exponential notation. We denoted it ∑n to be the set of
strings of length n, each of whose symbols is in given
input alphabet ∑.
21
Introduction to Formal Languages(..contd)
It is defined as the set of all possible strings of all possible lengths on alphabet ∑
including ‘ε’ (empty string).
22
Introduction to Formal Languages(..contd)
23
Introduction to Formal Languages(..contd)
Concatenation of strings:
Concatenation of strings is the technique to merging the symbols of strings
together.
Then AB denotes the concatenation of A and B, that is, the string formed by
making a copy of A and following it by a copy of B.
For example: Let A = 11001 and B = 010. Then the concatenation of strings as
follows;
AB={11001010},
and
BA = {01011001}.
24
Introduction to Chomskian Hiearchy
25
Introduction
26
Introduction to Finite Automata
27
Introduction to Finite Automata (..contd)
28
Introduction to Finite Automata (..contd)
29
Introduction to Finite Automata (..contd)
30
Representation of Finite Automata
31
Representation of Finite Automata
Transition Table
Final states
starred Columns =
0 1 input symbols
* A A B
Arrow for B A C
*
start state C C C
Rows = states
32
Types of Finite Automata
•In DFA, there is only one path for specific input from the current
state to the next state.
•DFA does not accept the null move, i.e., the DFA cannot change state
without any input character.
35
DFA Example 1
Solution
36
DFA Example2
Solution
37
DFA Example 3
Solution
38
DFA Example 4
0 0,1
1 1
A B C
Start 0
39
DFA Example 5
Solution
40
Extended Transition Function
41
Extended Transition Function
• Convention:
• … w, x, y, x are strings.
• a, b, c,… are single symbols.
• Extended δ is computed for state q and inputs
a1a2…an by following a path in the transition
graph, starting at q and selecting the arcs with
labels a1, a2,…,an in turn.
42
Extended Transition Function(..contd)
δ(δ(A,1),1) = δ(B,1) = C
43
Delta-hat 𝛿መ
44
FA Examples
0 0,1
1 1
A B C
Start 0
45
1. Construct Deterministic Finite Automata (DFA) for accepting all the
strings ending with ‘0’ over the alphabet ∑={0,1}. Show the transition
functions and transition table.
2. Construct Deterministic Finite Automata (DFA) for accepting all the
strings start with ‘1’ and ends with ‘0’ over the alphabet ∑={0,1}. Show
the transition functions and transition table.
3. Construct Deterministic Finite Automata (DFA) for accepting all the
strings those do not contain two consecutive ones over the alphabet
∑={0,1}. Show the transition functions and transition table.
4. Construct Deterministic Finite Automata (DFA) for accepting all the
strings contain even number of 1’s and even number of 0’s over the
alphabet ∑={0,1}. Show the transition functions and transition table.
5. Construct DFA for the following: To accept the strings always end with
’00’
47
NFA (..contd)
48
NFA
49
NFA Example
50
NFA Example
Transition Table:
Present State Next state for Input 0 Next State of Input 1
→q0 q1 q1
q1 q2 q2
*q2 ε ε
51
NFA Example Chess Board
• States = squares.
• Inputs = r (move to an adjacent red square) and
b (move to an adjacent black square).
• Start state, final state are in opposite corners.
52
NFA Example Chess Board (contd)
1 2 3
r b
1 2,4 5
2 4,6 1,3,5
4 5 6
3 2,6 5
4 2,8 1,5,7
7 8 9
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
r b b 7 4,8 5
1 2 1 5 8 4,6 5,7,9
4 3 1 * 9 6,8 5
5 3
7 7
9 Accept, since final state reached 53
Language of an NFA
54
Regular Language
55
Non Regular Language
L1 = {0n1n | n ≥ 1}
• Note: ai is conventional for i a’s.
• Thus, 04 = 0000, e.g.
• Read: “The set of strings consisting of n 0’s
followed by n 1’s, such that n is at least 1.
• Thus, L1 = {01, 0011, 000111,…}
56
NFA vs DFA
DFA: For every state q in S and every character in , one and only one transition of
the following form occurs:
q q’
NFA: For every state q in S and every character in {e}, one (or both) of the
following will happen:
•No transition: q q’ occurs
•One or more transitions: q q’ occurs
p
…
57
Equivalence of NFA and DFA
Definition. Two automata A and A’ are equivalent if they recognize the
same language.
Subset Construction
58
Subset Construction
r b
r b
1 2,4 5 {1} {2,4} {5}
2 4,6 1,3,5 {2,4}
3 2,6 5 {5}
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
* 9 6,8 5 Alert: What we’re doing here is
the lazy form of DFA construction,
where we only construct a state
if we are forced to.
59
Subset Construction (..contd)
r b
r b
1 2,4 5 {1} {2,4} {5}
2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5}
4 2,8 1,5,7 {2,4,6,8}
5 2,4,6,8 1,3,7,9 {1,3,5,7}
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
* 9 6,8 5
60
Subset Construction (..contd)
r b
r b
1 2,4 5 {1} {2,4} {5}
2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7 {2,4,6,8}
5 2,4,6,8 1,3,7,9 {1,3,5,7}
6 2,8 3,5,9 * {1,3,7,9}
7 4,8 5
8 4,6 5,7,9
* 9 6,8 5
61
Subset Construction (..contd)
r b
r b
1 2,4 5 {1} {2,4} {5}
2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7 {2,4,6,8} {2,4,6,8} {1,3,5,7,9}
5 2,4,6,8 1,3,7,9 {1,3,5,7}
6 2,8 3,5,9 * {1,3,7,9}
7 4,8 5 * {1,3,5,7,9}
8 4,6 5,7,9
* 9 6,8 5
62
Subset Construction (..contd)
r b
r b
1 2,4 5 {1} {2,4} {5}
2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7 {2,4,6,8} {2,4,6,8} {1,3,5,7,9}
5 2,4,6,8 1,3,7,9 {1,3,5,7} {2,4,6,8} {1,3,5,7,9}
6 2,8 3,5,9 * {1,3,7,9}
7 4,8 5 * {1,3,5,7,9}
8 4,6 5,7,9
* 9 6,8 5
63
Subset Construction (..contd)
r b
r b
1 2,4 5 {1} {2,4} {5}
2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7 {2,4,6,8} {2,4,6,8} {1,3,5,7,9}
5 2,4,6,8 1,3,7,9 {1,3,5,7} {2,4,6,8} {1,3,5,7,9}
6 2,8 3,5,9 * {1,3,7,9} {2,4,6,8} {5}
7 4,8 5 * {1,3,5,7,9}
8 4,6 5,7,9
* 9 6,8 5
64
Subset Construction (..contd)
r b
r b
1 2,4 5 {1} {2,4} {5}
2 4,6 1,3,5 {2,4} {2,4,6,8} {1,3,5,7}
3 2,6 5 {5} {2,4,6,8} {1,3,7,9}
4 2,8 1,5,7 {2,4,6,8} {2,4,6,8} {1,3,5,7,9}
5 2,4,6,8 1,3,7,9 {1,3,5,7} {2,4,6,8} {1,3,5,7,9}
6 2,8 3,5,9 * {1,3,7,9} {2,4,6,8} {5}
7 4,8 5 * {1,3,5,7,9} {2,4,6,8} {1,3,5,7,9}
8 4,6 5,7,9
* 9 6,8 5
65
NFA’s With ε-Transitions
66
NFA’s With ε-Transitions - Example
ε 0 1 ε
A {E} {B} ∅
1 1 B ∅ {C} {D}
1 B C D C ∅ {D} ∅
D ∅ ∅ ∅
A ε ε 0
* E
F
{F} ∅ {B, C}
{D} ∅ ∅
0
E F
0
67
Extended Delta
ε
1 1
1 B C D
Example: Extended Delta
A ε ε 0
0 E F
˄ 0
• δ(A, ε) = CL(A) = {A}.
˄
• δ (A, 0) = CL({E}) = {B, C, D, E}.
• δ(A,
˄
01) = CL({C, D}) = {C, D}.
• Language of an ε-NFA is the set of strings w
such that (q0, w) contains a final state.
68
Example: ε-NFA-to-NFA
Interesting
closures: CL(B)
= {B,D}; CL(E)
= {B,C,D,E}
0 1 ε A
0 1
{E} {B}
A {E} {B} ∅ B ∅ {C}
B ∅ {C} {D} * C ∅ {D}
C ∅ {D} ∅ D ∅ ∅
D ∅ ∅ ∅
* E {F} {C, D}
* E {F} ∅ {B, C} F {D} ∅
F {D} ∅ ∅ *
Since closure of
ε-NFA E includes B and
Since closures of C; which have
B and E include transitions on 1
final state D. to C and D.
69
NFA with ε to DFA
Step 1: We will take the ε-closure for the starting state of NFA as a
starting state of DFA.
Step 2: Find the states for each input symbol that can be traversed from
the present. That means the union of transition value and their closures
for each state of NFA present in the current state of DFA.
Step 3: If we found a new state, take it as current state and repeat step
2.
Step 4: Repeat Step 2 and Step 3 until there is no new state present in
the transition table of DFA.
Step 5: Mark the states of DFA as a final state which contains the final
state of NFA.
70
NFA with ε into its equivalent DFA
Solution:
Let us obtain ε-closure of each state.
1.ε-closure {q0} = {q0, q1, q2}
2.ε-closure {q1} = {q1}
3.ε-closure {q2} = {q2}
4.ε-closure {q3} = {q3}
5.ε-closure {q4} = {q4}
71
ε NFA to DFA(..contd)
Hence
72
ε NFA to DFA(..contd)
Now,
73
Minimization of DFA
• The process of reducing a given DFA to its minimal
form is called as minimization of DFA.
• It contains the minimum number of states.
• The DFA in its minimal form is called as a Minimal
DFA.
74
Minimization of DFA
75
Minimization of DFA
Step 4: Find similar rows from T1 such that:
1. δ (q, a) = p
2. δ (r, a) = p
That means, find the two states which have the same value of a
and b and remove one of them.
77
Minimization of DFA
Solution:
Step 1: In the given DFA, q2 and q4 are the unreachable
states so remove them.
Step 2: Draw the transition table for the rest of the states.
78
Minimization of DFA
79
Minimization of DFA
2. Another set contains those rows, which starts from final states.
80
Minimization of DFA
Step 5: In set 2, row 1 and row 2 are similar
since q3 and q5 transit to the same state on 0
and 1. So skip q5 and then replace q5 by q3 in
the rest.
81
Minimization of DFA
82
Minimization of DFA
2.Mark all the pairs (Qa,Qb) such a that Qa is Final state and Qb is Non-
Final State.
3.If there is any unmarked pair (Qa,Qb) such a that δ(Qa,x) and δ(Qb,x) is
marked, then mark (Qa,Qb). Here x is a input symbol. Repeat this step
until no more marking can be made.
4.Combine all the unmarked pairs and make them a single state in the
minimized DFA.
83
Minimization of DFA
84