New FLAT NOTES
New FLAT NOTES
of
S.                                                                     Teaching
        Date                   Topics To Be Covered            Periods          Remarks
No.                                                                      Aid
                                                              Required
                                                UNIT-I
      24/12/18
1.        &       Introduction to Finite Automata                  2     BB
      27/12/18
2.    29/12/18    Structural Representations                       1     BB
3.    31/12/18    Automata and Complexity                          1     BB
4.      2/1/19    the Central Concepts of Automata Theory          1     BB
      3/1/2019
5.                Alphabets, Strings, Languages, Problems          2     BB
      & 5/1/19
6.    7/1/2019    Deterministic Finite Automata                    2     BB
      & 8/1/19
7.    9/1/19 &    Nondeterministic Finite Automata                 2     BB
       10/1/19
8.                an application: Text Search                      1     BB
       12/1/19
      16/1/19 &
9.                Finite Automata with Epsilon-Transitions.        2     BB
       17/1/19
                         Total Periods Required               14
                                                UNIT-II
10    19/1/19 &   Regular Expressions                              2     BB
       21/1/19
11    22/1/19 &   Finite Automata and Regular Expressions          2     BB
       23/1/19
12
                  Applications of Regular Expressions              1     BB
       24/1/19
13     28/1/19    Algebraic Laws for Regular Expressions           1     BB
14
                  Properties of Regular Languages                  1     BB
       29/1/19
15     30/1/19    Pumping Lemma for Regular Languages              1     BB
16     31/1/19    Applications of the Pumping Lemma                1     BB
17
                  Closure Properties of Regular Languages          1     BB
       2/2/19
18
                  Decision Properties of Regular Languages         1     BB
       4/2/19
19     5/2/19     Equivalence of Automata                           1    BB
20     6/2/19     Minimization of Automata                          1    BB
                     Total periods Required                        13
                                                UNIT-III
21                Context-Free Grammars                           1   BB
       7/2/19
22     9/2/19     Definition of Context-Free Grammars             1   BB
23                Derivations Using a Grammar                     1   BB
       11/2/19
24     12/2/19    Leftmost and Rightmost Derivations              1   BB
25     13/2/19    the Language of a Grammar                       1   BB
26     14/2/19    Sentential Forms                                1   BB
27     16/2/19    Parse Tress                                     1   BB
28     21/2/19    Applications of Context-Free Grammars           1   BB
29     23/2/19    Ambiguity in Grammars and Languages             1   BB
30.    25/2/19    Push Down Automata                              1   BB
31.    26/2/19    Definition of the Pushdown Automaton            1   BB
32.    27/2/19    the Languages of a PDA                          1   BB
      28/2/2019
33.               Equivalence of PDA's and CFG's                  2   BB
      & 2/3/19
34.     5/3/19    Deterministic Pushdown Automata                 1   BB
                      Total periods Required                          15
                                               UNIT-IV
35      6/3/19    Normal Forms for Context- Free Grammars         1   BB
36      7/3/19    the Pumping Lemma for Context-Free Languages    1   BB
37     11/3/19    Closure Properties of Context-Free Languages    1   BB
38     12/3/19    Decision Properties of CFL's                    1   BB
      13/3/19 &   Complexity of Converting among CFG's and
39                                                                2   BB
       14/3/19    PDA's
      16/3/19 &   Running time of conversions to Chomsky Normal
40                                                                2   BB
       18/3/19    Form
41     19/3/19    Introduction to Turing Machines                 1   BB
42     20/3/19    Problems That Computers Cannot Solve            1   BB
43     23/3/19    The Turing Machine                              1   BB
44     25/3/19    Programming Techniques for Turing Machines      1   BB
45     26/3/19    Extensions to the basic Turing machine          1   BB
46     27/3/19    Restricted Turing Machines                      1   BB
47     28/3/19    Turing Machines and Computers                   1   BB
                      Total periods Required                          15
                                               UNIT-V
48.   30/3/19 &   Undecidability                                  2   BB
        1/4/19
       2/4/2019
49.               A Language that is Not Recursively Enumerable   2   BB
       & 3/4/19
50.     4/4/19    An Undecidable Problem That is RE               1   BB
 51.     8/4/19    Undecidable Problems about Turing Machines        1       BB
 52.     9/4/19    Post's Correspondence Problem                     1       BB
 53.    10/4/19    Other Undecidable Problems                        1       BB
 54.    11/4/19    Intractable Problems                              1       BB
 55.    13/4/19    The Classes P and NP                              1       BB
       15/4/19 &
 56.               An NP-Complete Problem                            2       BB
        16/4/19
                      Total periods Required                                 12
Academic Year:2018-19
                                                                  No.of
S.                                                                       Teaching
          Date                  Topics To Be Covered             Periods          Remarks
No.                                                                        Aid
                                                                Required
                                                 UNIT-I
       24/12/18
 1.       &        Introduction to Finite Automata                   2       BB
       27/12/18
 2.    28/12/18    Structural Representations                        1       BB
 3.    29/12/18    Automata and Complexity                           1       BB
 4.    31/12/18    the Central Concepts of Automata Theory           1       BB
       3/1/2019
 5.                Alphabets, Strings, Languages, Problems           2       BB
       & 4/1/19
 6.    5/1/2019    Deterministic Finite Automata                     2       BB
       & 7/1/19
 7.    8/1/19 &    Nondeterministic Finite Automata                  2       BB
        10/1/19
 8.                an application: Text Search                       1       BB
        11/1/19
       12/1/19 &
 9.                Finite Automata with Epsilon-Transitions.         2       BB
        17/1/19
                          Total Periods Required                14
                                                 UNIT-II
10    18/1/19 &   Regular Expressions                            2    BB
       19/1/19
11    21/1/19 &   Finite Automata and Regular Expressions        2    BB
       22/1/19
12
                  Applications of Regular Expressions            1    BB
       24/1/19
13     25/1/19    Algebraic Laws for Regular Expressions         1    BB
14
                  Properties of Regular Languages                1    BB
       28/1/19
15     29/1/19    Pumping Lemma for Regular Languages            1    BB
16     31/1/19    Applications of the Pumping Lemma              1    BB
17
                  Closure Properties of Regular Languages        1    BB
       1/2/19
18
                  Decision Properties of Regular Languages       1    BB
       2/2/19
19     4/2/19     Equivalence of Automata                         1   BB
20     5/2/19     Minimization of Automata                        1   BB
                     Total periods Required                      13
                                              UNIT-III
21                Context-Free Grammars                          1    BB
       7/2/19
22     8/2/19     Definition of Context-Free Grammars            1    BB
23                Derivations Using a Grammar                    1    BB
        9/2/19
24     11/2/19    Leftmost and Rightmost Derivations             1    BB
25     12/2/19    the Language of a Grammar                      1    BB
26     14/2/19    Sentential Forms                               1    BB
27     15/2/19    Parse Tress                                    1    BB
28     16/2/19    Applications of Context-Free Grammars          1    BB
29     21/2/19    Ambiguity in Grammars and Languages            1    BB
30.    22/2/19    Push Down Automata                             1    BB
31.    23/2/19    Definition of the Pushdown Automaton           1    BB
32.    25/2/19    the Languages of a PDA                         1    BB
      26/2/2019
33.               Equivalence of PDA's and CFG's                 2    BB
      & 28/2/19
34.     1/3/19    Deterministic Pushdown Automata                1    BB
                      Total periods Required                          15
                                              UNIT-IV
35     2/3/19     Normal Forms for Context- Free Grammars        1    BB
36     5/3/19     the Pumping Lemma for Context-Free Languages   1    BB
37     7/3/19     Closure Properties of Context-Free Languages   1    BB
38      8/3/19    Decision Properties of CFL's                    1       BB
      11/3/19 &   Complexity of Converting among CFG's and
39                                                                2       BB
       12/3/19    PDA's
      14/3/19 &   Running time of conversions to Chomsky Normal
40                                                                2       BB
       15/3/19    Form
41     16/3/19    Introduction to Turing Machines                 1       BB
42     18/3/19    Problems That Computers Cannot Solve            1       BB
43     19/3/19    The Turing Machine                              1       BB
44     22/3/19    Programming Techniques for Turing Machines      1       BB
45     23/3/19    Extensions to the basic Turing machine          1       BB
46     25/3/19    Restricted Turing Machines                      1       BB
47     26/3/19    Turing Machines and Computers                   1       BB
                      Total periods Required                              15
                                               UNIT-V
48.   28/3/19 &   Undecidability                                  2       BB
       29/3/19
      30/3/2019
49.               A Language that is Not Recursively Enumerable   2       BB
       & 1/4/19
50.     2/4/19    An Undecidable Problem That is RE               1       BB
51.     4/4/19    Undecidable Problems about Turing Machines      1       BB
52.     8/4/19    Post's Correspondence Problem                   1       BB
53.     9/4/19    Other Undecidable Problems                      1       BB
54.    11/4/19    Intractable Problems                            1       BB
55.    12/4/19    The Classes P and NP                            1       BB
      13/4/2019
56.               An NP-Complete Problem                          2       BB
      & 15/4/19
                     Total periods Required                               12
This unit provides the knowledge to understand what is automata, what is the need of studying
automata as one of the core subject, its real-time applications, how it is represented with states
and inputs and their diagrammatical representation , and also provides knowledge about
alphabet, string, language, regular expression and its operations , representation of deterministic
finite automata (DFA) and nondeterministic finite automata(NFA) and their tuples with some
practical problems and their applications
CONTENTS:
Automata* enables the scientists to understand how machines compute the functions and solve
problems. The main motivation behind developing Automata Theory was to develop methods to
describe and analyse the dynamic behavior of discrete systems.
Automata is originated from the word “Automaton” which is closely related to “Automation”.
The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting".
An automaton (Automata in plural) is an abstract self-propelled computing device which follows
a predetermined sequence of operations automatically.
Automata theory is the study of abstract machines and automata, as well as the computational
problems that can be solved using them. It is a theory in theoretical computer
science and discrete mathematics (a subject of study in both mathematics and computer science).
The word automata (the plural of automaton) come from the Greek word αὐτόματα, which
means "self-acting".
Automata theory, body of physical and logical principles underlying the operation of any
electromechanical device (an automaton) that converts information from one form into another
according to a definite procedure. Real or hypothetical automata of varying complexity have
become indispensable tools for the investigation and implementation of systems that have
structures amenable to mathematical analysis.
An automaton with a finite number of states is called a Finite Automaton (FA) or Finite State
Machine (FSM).
Examples of Automata:
      Vending Machine
      Traffic Lights
      Video Games
      Text Parsing
      Regular Expression Matching
      Speech Recognition.
      Washing Maching ..etc
Symbol:
    Symbol is the smallest building block, which can be any alphabet, letter or any picture.
Alphabet:
String
Empty String:
         Note – If the number of Σ’s is represented by |Σ|, then number of strings of length n,
         possible over Σ is |Σ|n.
Length of a String
Kleene Star
         Definition − The Kleene star, ∑*, is a unary operator on a set of symbols or strings, ∑,
          that gives the infinite set of all possible strings of all possible lengths over ∑including λ.
         Representation − ∑* = ∑0 ∪ ∑1 ∪ ∑2 ∪……. where ∑p is the set of all possible strings
          of length p.
         Example − If ∑ = {a, b}, ∑* = {λ, a, b, aa, ab, ba, bb,………..}
 Definition − The set ∑+ is the infinite set of all possible strings of all possible lengths
      Representation − ∑+ = ∑1 ∪ ∑2 ∪ ∑3 ∪…….
       over ∑ excluding λ.
       ∑+ = ∑* − { λ }
      Example − If ∑ = { a, b } , ∑+ = { a, b, aa, ab, ba, bb,………..}
Language:
Powers of ‘ Σ ‘ :
A finite automaton has a finite set of states with which it accepts or rejects strings.
A finite automaton (FA) is a simple idealized machine used to recognize patterns within input
taken from some character set (or alphabet) C. The job of an FA is to accept or reject an input
depending on whether the pattern defined by the FA occurs in the input.
        q0 is the initial state from where any input is processed (q0 ∈ Q).
       δ is the transition function.
Operating an FA:
An FA Accepts Strings:
In DFA, for each input symbol, one can determine the state to which the machine will move.
Hence, it is called Deterministic Automaton. As it has a finite number of states, the machine is
called Deterministic Finite Machine or Deterministic Finite Automaton.
Example
       Q = {a, b, c},
       ∑ = {0, 1},
       q0 = {a},
       F = {c}, and
Present State Next State for Input 0 Next State for Input 1
a a b
b c a
c b c
In NDFA, for a particular input symbol, the machine can move to any combination of the states
in the machine. In other words, the exact state to which the machine moves cannot be
determined. Hence, it is called Non-deterministic Automaton. As it has finite number of
states, the machine is called Non-deterministic Finite Machine or Non-deterministic Finite
Automaton.
Formal Definition of an NDFA
Example
Let a non-deterministic finite automaton be →
       Q = {a, b, c}
       ∑ = {0, 1}
       q0 = {a}
       F = {c}
Present State Next State for Input 0 Next State for Input 1
a a, b b
b c a, c
        c                     b, c                        c
Its graphical representation would be as follows −
DFA vs NDFA
The following table lists the differences between DFA and NDFA.
DFA NDFA
The transition from a state is to a single         The transition from a state can be to
particular next state for each input symbol.       multiple next states for each input
Hence it is called deterministic.                  symbol. Hence it is called non-
                                                   deterministic.
Empty string transitions are not seen in DFA. NDFA permits empty string transitions.
Acceptor (Recognizer)
An automaton that computes a Boolean function is called an acceptor. All the states of an
acceptor is either accepting or rejecting the inputs given to it.
Classifier:
A classifier has more than two final states and it gives a single output when it terminates.
Transducer:
An automaton that produces outputs based on current input and/or previous state is called
a transducer.
Transducers can be of two types –
       Mealy Machine − The output depends both on the current state and the current input.
       Moore Machine − The output depends only on the current state.
A string is accepted by a DFA/NDFA iff the DFA/NDFA starting at the initial state ends in an
accepting state (any of the final states) after reading the string wholly.
A string S is accepted by a DFA/NDFA (Q, ∑, δ, q0, F), iff δ*(q0, S) ∈ F
A string S′ is not accepted by a DFA/NDFA (Q, ∑, δ, q0, F), iff δ*(q0, S′) ∉ F
{S | S ∈ ∑* and δ*(q0, S) ∉ F}
The language L′ not accepted by DFA/NDFA (Complement of accepted language L) is
Example
Let us consider the DFA shown in Figure 1.3. From the DFA, the acceptable strings can be
derived.
Strings accepted by the above DFA: {0, 00, 11, 010, 101, ...........}
Strings not accepted by the above DFA: {1, 011, 111, ........}
Problem Statement
Let X = (Qx, ∑, δx, q0, Fx) be an NDFA which accepts the language L(X). We have to design an
equivalent DFA Y = (Qy, ∑, δy, q0, Fy) such that L(Y) = L(X). The following procedure
converts the NDFA to its equivalent DFA –
Algorithm:
Input − An NDFA
Output − An equivalent DFA
Step 1 − Create state table from the given NDFA.
Step 2 − Create a blank state table under possible input alphabets for the equivalent DFA.
Step 3 − Mark the start state of the DFA by q0 (Same as the NDFA).
Step 4 − Find out the combination of States {Q0, Q1,... , Qn} for each possible input alphabet.
Step 5 − Each time we generate a new DFA state under the input alphabet columns, we have to
apply step 4 again, otherwise go to step 6.
Step 6 − The states which contain any of the final states of the NDFA are the final states of the
equivalent DFA.
q δ(q,0) δ(q,1)
a {a,b,c,d,e} {d,e}
b {c} {e}
c ∅ {b}
d {e} ∅
 e                  ∅                    ∅
Using the above algorithm, we find its equivalent DFA. The state table of the DFA is shown in below.
q δ(q,0) δ(q,1)
[d,e] [e] ∅
[e] ∅ ∅
[c, e] ∅ [b]
[c] ∅ [b]
Input − DFA
Output − Minimized DFA
Step 1 − Draw a table for all pairs of states (Q i, Qj) not necessarily connected directly [All are
Step 2 − Consider every state pair (Q i, Qj) in the DFA where Qi∈ F and Qj ∉ F or vice versa
unmarked initially]
Example
Let us use Algorithm 2 to minimize the DFA shown below.
a b c d e f
  d
  e
a b c d e f
c ✔ ✔
d ✔ ✔
e ✔ ✔
f ✔ ✔ ✔
Step 3 − We will try to mark the state pairs, with green colored check mark, transitively. If we
input 1 to state ‘a’ and ‘f’, it will go to state ‘c’ and ‘f’ respectively. (c, f) is already marked,
hence we will mark pair (a, f). Now, we input 1 to state ‘b’ and ‘f’; it will go to state ‘d’ and ‘f’
respectively. (d, f) is already marked, hence we will mark pair (b, f).
a b c d e f
b
 c   ✔         ✔
d ✔ ✔
e ✔ ✔
f ✔ ✔ ✔ ✔ ✔
After step 3, we have got state combinations {a, b} {c, d} {c, e} {d, e} that are unmarked.
We can recombine {c, d} {c, e} {d, e} into {c, d, e}
Hence we got two combined states as − {a, b} and {c, d, e}
So the final minimized DFA will contain three states {f}, {a, b} and {c, d, e}
If X and Y are two states in a DFA, we can combine these two states into {X, Y} if they are not
distinguishable. Two states are distinguishable, if there is at least one string S, such that one of δ
(X, S) and δ (Y, S) is accepting and another is not accepting. Hence, a DFA is minimal if and
only if all the states are distinguishable.
Algorithm 3:
Step 1 − All the states Q are divided in two partitions − final states and non-final states and
are denoted by P0. All the states in a partition are 0th equivalent. Take a counter k and initialize
it with 0.
Step 2 − Increment k by 1. For each partition in P k, divide the states in Pk into two partitions if
they are k-distinguishable. Two states within this partition X and Y are k-distinguishable if
there is an input S such that δ(X, S) and δ(Y, S) are (k-1)-distinguishable.
Step 3 − If Pk ≠ Pk-1, repeat Step 2, otherwise go to Step 4.
Step 4 − Combine kth equivalent sets and make them the new states of the reduced DFA.
q δ(q,0) δ(q,1)
a b c
b a d
c e f
d e f
e e f
f f f
Hence, P1 = P2.
There are three states in the reduced DFA. The reduced DFA is as follows −
Q δ(q,0) δ(q,1)
        q0 − an initial state q0 ∈ Q
      F − a set of final state/states of Q (F⊆Q).
If in an NDFA, there is ϵ-move between vertex X to vertex Y, we can remove it using the
following steps −
Solution
Step 1 −
Here the ε transition is between q1 and q2, so let q1 is Xand qf is Y.
Here the outgoing edges from qf is to qf for inputs 0 and 1.
Step 2 −
Now we will Copy all these edges from q 1 without changing the edges from qf and get the
following FA −
Step 3 −
So the FA becomes −
Step 4 −
So the FA becomes −
Finite automata may have outputs corresponding to each transition. There are two types of finite
state machines that generate output −
       Mealy Machine
       Moore machine
Mealy Machine:
A Mealy Machine is an FSM whose output depends on the present state as well as the present
input.
        q0 is the initial state from where any input is processed (q0 ∈ Q).
       X is the output transition function where X: Q × ∑ → O
    
Next state
→a b x1 c x1
b b x2 d x3
c d x3 c x1
        d              d          x3           d           x2
The state diagram of the above Mealy Machine is −
Moore Machine:
Moore machine is an FSM whose outputs depend on only the present state.
        q0 is the initial state from where any input is processed (q0 ∈ Q).
       X is the output transition function where X: Q → O
    
                             Next State
Present state                                         Output
                    Input = 0       Input = 1
→a b c x2
b b d x1
        c                c                d             x2
       d                  d               d             x3
Output depends both upon the present state and            Output depends only upon the present
the present input                                         state.
Generally, it has fewer states than Moore                 Generally, it has more states than Mealy
Machine.                                                  Machine.
The value of the output function is a function of         The value of the output function is a
the transitions and the changes, when the input           function of the current state and the
logic on the present state is done.                       changes at the clock edges, whenever
                                                          state changes occur.
Mealy machines react faster to inputs. They               In Moore machines, more logic is
generally react in the same clock cycle.                  required to decode the outputs resulting
                                                          in more circuit delays. They generally
                                                          react one clock cycle later.
Step 2 − Copy all the Moore Machine transition states into this table format.
Step 3 − Check the present states and their corresponding outputs in the Moore Machine state
table; if for a state Qi output is m, copy it into the output columns of the Mealy Machine state
table wherever Qi appears in the next state.
→a d b 1
b a d 0
c c c 0
d b a 1
Step 1 & 2 −
Next State
→a d b
        b               a                       d
           c              c                        c
d b a
Step 3 −
Next State
=> a d 1 b 0
b a 1 d 1
c c 0 c 0
d b 0 a 1
Next State
→a d 0 b 1
b a 1 d 0
c c 1 c 0
d b 0 a 1
Here, states ‘a’ and‘d’ give only 1 and 0 outputs respectively, so we retain states ‘a’ and ‘d’. But
states ‘b’ and ‘c’ produce different outputs (1 and 0). So, we divide b into b0, b1 and c into c0, c1.
                        Next State
 Present State                             Output
                      a=0          a=1
→a d b1 1
b0 a d 0
b1 a d 1
         c0             c1         C0            0
         c1             c1      C0         1
d b0 a 0
UNIT – II
This unit provides the knowledge to understand to understand Regular Expression its properties
and laws. It also provides pumping lemma for regular expressions with its applications.
        Regular Expressions,
        Finite Automata and Regular Expressions,
        Applications of Regular Expressions,
        Algebraic Laws for Regular Expressions,
        Properties of Regular Languages- Pumping Lemma for Regular Languages,
        Applications of the Pumping Lemma,
        Closure Properties of Regular Languages,
        Decision Properties of Regular Languages,
        Equivalence and Minimization of Automata.
Regular Expressions:
A Regular Expression can be recursively defined as follows −
    ε is a Regular Expression indicates the language containing an empty string. (L (ε) = {ε})
    φ is a Regular Expression denoting an empty language. (L (φ) = { })
    x is a Regular Expression where L = {x}
    If X is a Regular Expression denoting the language L(X)and Y is a Regular Expression
 If we apply any of the rules several times from 1 to 5, they are Regular Expressions.
Some RE Examples
    (a+b)*abb          Set of strings of a’s and b’s ending with the string
                       abb. So L = {abb, aabb, babb, aaabb, ababb,
                       …………..}
(aa + ab + ba + bb)*   String of a’s and b’s of even length can be obtained
                       by concatenating any combination of the strings aa,
                       ab, ba and bb including null, so L = {aa, ab, ba, bb,
                       aaab, aaba, …………..}
Any set that represents the value of the Regular Expression is called a Regular Set.
In order to find out a regular expression of a Finite Automaton, we use Arden’s Theorem along
with the properties of regular expressions.
Statement −
Let P and Q be two regular expressions.
If P does not contain null string, then R = Q + RP has a unique solution that is R = QP*
Proof − R = Q + (Q + RP)P [After putting the value R = Q + RP] = Q + QP + RPP
When we put the value of R recursively again and again, we get the following equation −
R = Q + QP + QP2 + QP3…..
R = Q (ε + P + P2 + P3 + …. )
R = QP* [As P* represents (ε + P + P2 + P3 + ….) ]
Hence, proved.
Method:
Step 1 − Create equations as the following form for all the states of the DFA having n states
with initial state q1.
q1 = q1R11 + q2R21 + … + qnRn1 + ε
q2 = q1R12 + q2R22 + … + qnRn2
…………………………
…………………………
…………………………
…………………………
qn = q1R1n + q2R2n + … + qnRnn
Rij represents the set of labels of edges from qi to qj, if no such edge exists, then Rij = ∅
Step 2 − Solve these equations to get the equation for the final state in terms of Rij
1. Problem
Solution −
Here the initial state is q1 and the final state is q2
Now we write down the equations −
q1 = q10 + ε
q2 = q11 + q20
q3 = q21 + q30 + q31
Now, we will solve these three equations −
q1 = ε0* [As, εR = R]
So, q1 = 0*
q2 = 0*1 + q20
So, q2 = 0*1(0)* [By Arden’s theorem]
Hence, the regular expression is 0*10*.
We can use Thompson's Construction to find out a Finite Automaton from a Regular
Expression. We will reduce the regular expression into smallest regular expressions and
converting these to NFA and finally to DFA.
Some basic RA expressions are the following −
Case 1 − For a regular expression ‘a’, we can construct the following FA −
Case 2 − For a regular expression ‘ab’, we can construct the following FA −
Method
Step 1 Construct an NFA with Null moves from the given regular expression.
Step 2 Remove Null transition from the NFA and convert it into its equivalent DFA.
Now we will remove the ε transitions. After we remove the ε transitions from the NDFA, we get
the following −
It is an NDFA corresponding to the RE − 1 (0 + 1)* 0. If you want to convert it into a DFA,
simply apply the method of converting NDFA to DFA discussed in Chapter 1.
Theorem
Let L be a regular language. Then there exists a constant ‘c’ such that for every string w in L −
|w| ≥ c
We can break w into three strings, w = xyz, such that −
       |y| > 0
       |xy| ≤ c
       For all k ≥ 0, the string xykz is also in L.
Solution −
       At first, we assume that L is regular and n is the number of states.
       Let w = anbn. Thus |w| = 2n ≥ n.
       By pumping lemma, let w = xyz, where |xy| ≤ n.
       Let x = ap, y = aq, and z = arbn, where p + q + r = n, p ≠ 0, q ≠ 0, r ≠ 0. Thus |y| ≠ 0.
       Let k = 2. Then xy2z = apa2qarbn.
       Number of as = (p + 2q + r) = (p + q + r) + q = n + q
       Hence, xy2z = an+q bn. Since q ≠ 0, xy2z is not of the form anbn.
       Thus, xy2z is not in L. Hence L is not regular.
UNIT – III
This unit provides the knowledge to understand Context-free Grammers, its types and Pushdown
Automata with Applications.
      P is a set of rules, P: N → (N ∪ T)*, i.e., the left-hand side of the production rule P does
     T is a set of terminals where N ∩ T = NULL.
    
      have any right context or left context.
     S is the start symbol.
Example
A derivation tree or parse tree is an ordered rooted tree that graphically represents the semantic
information a string derived from a context-free grammar.
Representation Technique
    Root vertex − Must be labeled by the start symbol.
      Vertex − Labeled by a non-terminal symbol.
      Leaves − Labeled by a terminal symbol or ε.
If S → x1x2 …… xn is a production rule in a CFG, then the parse tree / derivation tree will be as
follows −
Top-down Approach −
     Starts with the starting symbol S
     Goes down to tree leaves using productions
Bottom-up Approach −
    Starts from tree leaves
    Proceeds upward to the root which is the starting symbol S
Example
Let a CFG {N,T,P,S} be
N = {S}, T = {a, b}, Starting symbol = S, P = S → SS | aSb | ε
One derivation from the above CFG is “abaabb”
S → SS → aSbS → abS → abaSb → abaaSbb → abaabb
Sentential Form and Partial Derivation Tree:
A partial derivation tree is a sub-tree of a derivation tree/parse tree such that either all of its
children are in the sub-tree or none of them are in the sub-tree.
Example
If in any CFG the productions are −
S → AB, A → aaA | ε, B → Bb| ε
the partial derivation tree can be the following −
If a partial derivation tree contains the root S, it is called a sentential form. The above sub-tree
is also in sentential form.
Problem: Check whether the grammar G with production rules − X → X+X | X*X |X| a              is
ambiguous or not.
Solution
Let’s find out the derivation tree for the string "a+a*a". It has two leftmost derivations.
Derivation 1 − X → X+X → a +X → a+ X*X → a+a*X → a+a*a
Parse tree 1 −
Derivation 2 − X → X*X → X+X*X → a+ X*X → a+a*X → a+a*a
Parse tree 2 −
Since there are two parse trees for a single string "a+a*a", the grammar G is ambiguous.
      Union
      Concatenation
      Kleene Star operation
Let L1 and L2 be two context free languages. Then L1 ∪ L2 is also context free.
Union:
Example
Example
Union of the languages L1 and L2, L = L1L2 = { anbncmdm }
The corresponding grammar G will have the additional production S → S1 S2
Kleene Star:
If L is a context free language, then L* is also context free.
Example:
Let L = { anbn , n ≥ 0}. Corresponding grammar G will have P: S → aAb| ε
Kleene Star L1 = { anbn }*
The corresponding grammar G1 will have additional productions S1 → SS1 | ε
CFG Simplification:
In a CFG, it may happen that all the production rules and symbols are not needed for the
derivation of strings. Besides, there may be some null productions and unit productions.
Elimination of these productions and symbols is called simplification of CFGs. Simplification
essentially comprises of the following steps −
       Reduction of CFG
       Removal of Unit Productions
       Removal of Null Productions
Reduction of CFG:
CFGs are reduced in two phases −
Phase 1 − Derivation of an equivalent grammar, G’, from the CFG, G, such that each variable
derives some terminal string.
Derivation Procedure −
Step 1 − Include all symbols, W1, that derive some terminal and initialize i=1.
Step 2 − Include all symbols, Wi+1, that derive Wi.
Step 3 − Increment i and repeat Step 2, until Wi+1 = Wi.
Step 4 − Include all production rules that have Wi in it.
Phase 2 − Derivation of an equivalent grammar, G”, from the CFG, G’, such that each symbol
appears in a sentential form.
Derivation Procedure −
Step 1 − Include the start symbol in Y1 and initialize i = 1.
Step 2 − Include all symbols, Yi+1, that can be derived from Yi and include all production rules
that have been applied.
Step 3 − Increment i and repeat Step 2, until Yi+1 = Yi.
Problem: Find a reduced grammar equivalent to the grammar G, having production rules,
P: S → AC | B, A → a, C → c | BC, E → aA | e
Solution
Phase 1 −
T = { a, c, e }
W1 = { A, C, E } from rules A → a, C → c and E → aA
W3 = { A, C, E, S } U ∅
W2 = { A, C, E } U { S } from rule S → AC
Phase 2 −
Y1 = { S }
Y2 = { S, A, C } from rule S → AC
Y3 = { S, A, C, a, c } from rules A → a and C → c
Y4 = { S, A, C, a, c }
Since Y3 = Y4, we can derive G” as −
G” = { { A, C, S }, { a, c }, P, {S}}
where P: S → AC, A → a, C → c
ε: A → .......… → ε
Removal Procedure
Step 1 − Find out nullable non-terminal variables which derive ε.
Step 3 − Combine the original productions with the result of step 2 and remove ε -
productions.
Solution −
There are two nullable variables − A and B
At first, we will remove B → ε.
After removing B → ε, the production set becomes −
S→ASA | aB | b | a, A ε B| b | &epsilon, B → b
Now we will remove A → ε.
After removing A → ε, the production set becomes −
S→ASA | aB | b | a | SA | AS | S, A → B| b, B → b
This is the final production set without null transition.
Lemma:
Problem: Find out whether the language L = {xnynzn | n ≥ 1} is context free or not.
Solution:
Let L is context free. Then, L must satisfy pumping lemma.
At first, choose a number n of the pumping lemma. Then, take z as 0n1n2n.
Break z into uvwxy, where
|vwx| ≤ n and vx ≠ ε.
Hence vwx cannot involve both 0s and 2s, since the last 0 and the first 2 are at least (n+1)
positions apart. There are two cases −
Case 1 − vwx has no 2s. Then vx has only 0s and 1s. Then uwy, which would have to be in L,
has n 2s, but fewer than n 0s or 1s.
Case 2 − vwx has no 0s.
Here contradiction occurs.
Hence, L is not a context-free language.
      an input tape,
      a control unit, and
      a stack with infinite size.
The following diagram shows a transition in a PDA from a state q 1 to state q2, labeled as a,b →
c–
This means at state q1, if we encounter an input string ‘a’ and top symbol of the stack is ‘b’,
then we pop ‘b’, push ‘c’ on top of the stack and move to state q2.
Turnstile Notation
The "turnstile" notation is used for connecting pairs of ID's that represent one or many moves of
a PDA. The process of transition is denoted by the turnstile symbol "⊢".
Consider a PDA (Q, ∑, S, δ, q0, I, F). A transition can be mathematically represented by the
following turnstile notation −
(p, aw, Tβ) ⊢ (q, w, αb)
This implies that while taking a transition from state p to state q, the input symbol ‘a’ is
consumed, and the top of the stack ‘T’is replaced by a new string ‘α’.
Note − If we want zero or more moves of a PDA, we have to use the symbol (⊢*) for it.
Initially we put a special symbol ‘$’ into the empty stack. At state q2, the w is being read. In
state q3, each 0 or 1 is popped when it matches the input. If any other input is given, the PDA
will go to a dead state. When we reach that special symbol ‘$’, we go to the accepting state q4.
Step 2 − For every w, x, y, z ∈ Q, add the production rule Xwx→ XwyXyx in grammar G.
m) contains (x, ε), add the production rule Xwx → a Xyzb in grammar G.
       Top-Down Parser − Top-down parsing starts from the top with the start-symbol and
        derives a string using a parse tree.
       Bottom-Up Parser − Bottom-up parsing starts from the bottom with the string and
        comes to the start symbol using a parse tree.
       Pop the non-terminal on the left hand side of the production at the top of the stack and
        push its right-hand side string.
 If the top symbol of the stack matches with the input symbol being read, pop it.
 If the input string is fully read and the stack is empty, go to the final state ‘F’.
Example: Design a top-down parser for the expression "x+y*z" for the grammar G with the
following production rules −
P: S → S+X | X, X → X*Y | Y, Y → (S) | id
Solution:
For bottom-up parsing, a PDA has the following four types of transitions −
    Push the current input symbol into the stack.
    Replace the right-hand side of a production at the top of the stack with its left-hand side.
    If the top of the stack element matches with the current input symbol, pop it.
    If the input string is fully read and only if the start symbol ‘S’ remains in the stack, pop it
       and go to the final state ‘F’.
Example: Design a top-down parser for the expression "x+y*z" for the grammar G with the
following production rules −
 P: S → S+X | X, X → X*Y | Y, Y → (S) | id
Solution:
 ⊢(y*z, +SI) ⊢ (*z, y+SI) ⊢ (*z, Y+SI) ⊢ (*z, X+SI) ⊢ (z, *X+SI)
 ⊢ (ε, z*X+SI) ⊢ (ε, Y*X+SI) ⊢ (ε, X+SI) ⊢ (ε, SI)
UNIT – IV
This unit provides the knowledge about Normal Forms and Turning Machines with Applications.
      A→a
      A → BC
      S→ε
Step 1 − If the start symbol S occurs on some right side, create a new start symbol S’ and a new
production S’→ S.
Step 2 − Remove Null productions. (Using the Null production removal algorithm discussed
earlier)
Step 3 − Remove unit productions. (Using the Unit production removal algorithm discussed
earlier)
Step 4 − Replace each production A → B1…Bn where n > 2with A → B1C where C → B2 …
Bn. Repeat this step for all productions having two or more symbols in the right side.
Step 5 − If the right side of any production is in the form A → aB where a is a terminal and A,
B are non-terminal, then the production is replaced by A → XB and X → a. Repeat this step for
every production which is in the form A → aB.
B → ∈ and A → ∈
(2) Now we will remove the null productions −
S0→S, S→ ASA | aB | a, A → B | S | ∈, B → b
After removing B → ε, the production set becomes −
Step 1 − If the start symbol S occurs on some right side, create a new start symbol S’ and a new
production S’ → S.
Step 2 − Remove Null productions. (Using the Null production removal algorithm discussed
earlier)
Step 3 − Remove unit productions. (Using the Unit production removal algorithm discussed
earlier)
Step 4 − Remove all direct and indirect left-recursion.
Step 5 − Do proper substitutions of productions to convert it into the proper form of GNF.
Definition
A Turing Machine (TM) is a mathematical model which consists of an infinite length tape
divided into cells on which input is given. It consists of a head which reads the input tape. A
state register stores the state of the Turing machine. After reading an input symbol, it is replaced
with another symbol, its internal state is changed, and it moves from one cell to the right or left.
If the TM reaches the final state, the input string is accepted, otherwise rejected.
δ is given by –
Here the transition 1Rq1 implies that the write symbol is 1, the tape moves right, and the next
state is q1. Similarly, the transition 1Lq2 implies that the write symbol is 1, the tape moves left,
and the next state is q2.
The basic guidelines of designing a Turing machine have been explained below with the help of
a couple of examples.
Example 1
Design a TM to recognize all strings consisting of an odd number of α’s.
Solution
α BRq2 BRq1
Example 2
Design a Turing Machine that reads a string representing a binary number and erases all leading
0’s in the string. However, if the string comprises of only 0’s, it keeps one 0.
Solution
Let us assume that the input string is terminated by a blank symbol, B, at each end of the string.
The Turing Machine, M, can be constructed by the following moves −
     Let q0 be the initial state.
     If M is in q0, on reading 0, it moves right, enters the state q1 and erases 0. On reading 1,
        it enters the state q2 and moves right.
     If M is in q1, on reading 0, it moves right and erases 0, i.e., it replaces 0’s by B’s. On
        reaching the leftmost 1, it enters q2 and moves right. If it reaches B, i.e., the string
        comprises of only 0’s, it moves left and enters the state q3.
     If M is in q2, on reading either 0 or 1, it moves right. On reaching B, it moves left and
        enters the state q4. This validates that the string comprises only of 0’s and 1’s.
     If M is in q3, it replaces B by 0, moves left and reaches the final state qf.
Hence,
M = {{q0, q1, q2, q3, q4, qf}, {0,1, B}, {1, B}, δ, q0, B, {qf}}
where δ is given by –
A Multi-tape Turing machine can be formally described as a 6-tuple (Q, X, B, δ, q0, F) where −
    Q is a finite set of states
    X is the tape alphabet
    B is the blank symbol
    δ is a relation on states and symbols where
       δ: Q × Xk → Q × (X × {Left_shift, Right_shift, No_shift })k
       where there is k number of tapes
    q0 is the initial state
    F is the set of final states
Note − Every Multi-tape Turing machine has an equivalent single-tape Turing machine.
A Multi-track Turing machine can be formally described as a 6-tuple (Q, X, ∑, δ, q0, F) where −
Note − For every single-track Turing Machine S, there is an equivalent multi-track Turing
Machine M such that L(S) = L(M).
An input is accepted if there is at least one node of the tree which is an accept configuration,
otherwise it is not accepted. If all branches of the computational tree halt on all inputs, the non-
deterministic Turing Machine is called a Decider and if for some input, all branches are
rejected, the input is also rejected.
It is a two-track tape −
     Upper track − It represents the cells to the right of the initial head position.
     Lower track − It represents the cells to the left of the initial head position in reverse
      order.
The infinite length input string is initially written on the tape in contiguous tape cells.
The machine starts from the initial state q0 and the head scans from the left end marker ‘End’. In
each step, it reads the symbol on the tape under its head. It writes a new symbol on that tape cell
and then it moves the head either into left or right one tape cell. A transition function determines
the actions to be taken.
It has two special states called accept state and reject state. If at any point of time it enters into
the accepted state, the input is accepted and if it enters into the reject state, the input is rejected
by the TM. In some cases, it continues to run infinitely without being accepted or rejected for
some certain input symbols.
Note − Turing machines with semi-infinite tape are equivalent to standard Turing machines.
A linear bounded automaton can be defined as an 8-tuple (Q, X, ∑, q0, ML, MR, δ, F) where −
A deterministic linear bounded automaton is always context-sensitive and the linear bounded
automaton with empty language is undecidable..
UNIT – V
This unit provides the knowledge about the decidability and undecidability of the problems.
Language Decidability:
A language is called Decidable or Recursive if there is a Turing machine which accepts and
halts on every input string w. Every decidable language is Turing-Acceptable.
A decision problem P is decidable if the language L of all yes instances to P is decidable.
For a decidable language, for each input string, the TM halts either at the accept or the reject
state as depicted in the following diagram –
Example 1: Find out whether the following problem is decidable or not − Is a number ‘m’ prime?
Solution
Prime numbers = {2, 3, 5, 7, 11, 13, …………..}
Divide the number ‘m’ by all the numbers between ‘2’ and ‘√m’ starting from ‘2’.
If any of these numbers produce a remainder zero, then it goes to the “Rejected state”, otherwise
it goes to the “Accepted state”. So, here the answer could be made by ‘Yes’ or ‘No’.
Hence, it is a decidable problem.
Undecidable Languages:
For an undecidable language, there is no Turing Machine which accepts the language and makes
a decision for every input string w (TM can make decision for some input string though). A
decision problem P is called “undecidable” if the language L of all yes instances to P is not
decidable. Undecidable languages are not recursive languages, but sometimes, they may be
recursively enumerable languages.
Example
      The halting problem of Turing machine
      The mortality problem
      The mortal matrix problem
      The Post correspondence problem, etc.
Proof − At first, we will assume that such a Turing machine exists to solve this problem and
then we will show it is contradicting itself. We will call this Turing machine as a Halting
machine that produces a ‘yes’ or ‘no’ in a finite amount of time. If the halting machine finishes
in a finite amount of time, the output comes as ‘yes’, otherwise as ‘no’. The following is the
block diagram of a Halting machine –
Rice Theorem:
Rice theorem states that any non-trivial semantic property of a language which is recognized by
a Turing machine is undecidable. A property, P, is the language of all Turing machines that
satisfy that property.
Formal Definition:
Since, P is non-trivial, at least one language satisfies P, i.e., L(M0) ∈ P , ∋ Turing Machine M0.
Let, w be an input in a particular instant and N is a Turing Machine which follows −
On input x
    Run M on w
    If M does not accept (or doesn't halt), then do not accept x (or do not halt)
A function that maps an instance ATM = {<M,w>| M accepts input w} to a N such that
       If M accepts w and N accepts the same language as M0, Then L(M) = L(M0) ∈ p
       If M does not accept w and N accepts φ, Then L(N) = φ∈ p
x1 x2 x3
M Abb aa aaa
N Bba aaa aa
Here,
x2x1x3 = ‘aaabbaaa’
and y2y1y3 = ‘aaabbaaa’
We can see that
x2x1x3 = y2y1y3
Hence, the solution is i = 2, j = 1, and k = 3.
Example 2: Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba, bab) have a Post
Correspondence Solution?
Solution
x1 x2 x3
M ab bab bbaaa
N a ba bab