2. Terminologies
ā¢ Alphabet
ā¢ Finite, non empty set of symbols
ā¢ Basic elements of a language
ā¢ Denoted by ā
ā¢ String
ā¢ Finite sequence of symbols chosen from some alphabets
ā¢ Empty string
ā¢ Length of the string
ā¢ Power of an alphabet
ā¢ Language
ā¢ Set of all strings which are chosen from ā*
2
3. Example
ā¢ English
ā¢ Alphabet ā [a-z]
ā¢ String ā{hi,hello,ā¦}
ā¢ Binary number
ā¢ Alphabet ā [0,1]
ā¢ String ā{0,1,00,01,10,11ā¦}
ā¢ Hexadecimal
ā¢ Alphabet ā[0-9][a-e]
ā¢ String ā[0,1,1A3,ā¦]
3
4. Finite Automata
ā¢ Finite automata are used to recognize patterns.
ā¢ It takes the string of symbol as input and changes its state
accordingly. When the desired symbol is found, then the
transition occurs.
ā¢ At the time of transition, the automata can either move to the
next state or stay in the same state.
ā¢ Finite automata have two states, Accept state or Reject state.
When the input string is processed successfully, and the
automata reached its final state, then it will accept.
4
5. ā¢ Input Tape
ā¢ It is a linear tape having some number of cells. Each input symbol is
placed in each cell.
ā¢ Finite control
ā¢ It decides the next state on receiving particular input from input
tape.
ā¢ Tape reader
ā¢ It reads the cells one by one from left to right, and at a time only
one input symbol is read.
5
6. ā¢ A finite automaton consists of:
ā¢ a finite set S of N states
ā¢ a special start state
ā¢ a set of final (or accepting) states
ā¢ a set of transitions T from one state to another, labelled with
chars in C
6
7. ā¢ Execution of FA on an input sequence as follows:
ā¢ Begin in the start state
ā¢ If the next input char matches the label on a transition from the
current state to a new state, go to that new state
ā¢ Continue making transitions on each input char
ā¢ If no move is possible, then stop
ā¢ If in accepting state, then accept
7
8. Deterministic Finite Automata
ā¢ Deterministic refers to the uniqueness of the computation.
ā¢ On each input there is one and only one state to which the
automaton can transition from its current state
ā¢ DFA does not accept the null move.
8
9. Formal Definition of DFA
ā¢ A deterministic ļ¬nite automaton (DFA) is a 5-tuple
(Q,Ī£,Ī“,q0,F),where
ā¢ Q is a ļ¬nite set called the states,
ā¢ Ī£ is a ļ¬nite set called the alphabet,
ā¢ Ī“:QĆĪ£āQ is the transition function,
ā¢ q0 ā Q is the start state, and
ā¢ F ā Q is the set of accepting states.
9
10. Transition Table
ā¢ A transition table is a tabular representation of the transition
function that takes two arguments and returns a state.
ā¢ The column contains the state in which the automaton will be
on the input represented by that column.
ā¢ The row corresponds to the state the finite control unit can be
in.
ā¢ The entry for one row corresponding to state q and the
column corresponds to input a is the state Ī“(q, a).
10
11. Transition Diagram
ā¢ Transition graph can be interpreted as a flowchart for an
algorithm recognizing a language.
ā¢ A transition graph consists of three things:
ā¢ A finite set of states, at least one of which is designated the start
state and some of which are designated as final states.
ā¢ An alphabet Ī£ of possible input symbols from which the input
strings are formed.
ā¢ A finite set of transitions that show the change of state from the
given state on a given input.
11
12. Example DFA
12
states A b
ļ q0 q1 q2
q1 q1 q3
q2 q2 q3
*q3 q3 q3
A=({q0,q1,q2,q3},{a,b}Ī“,q0,{q3})
Ī“ is given by
Ī“(q0,a)=q1
Ī“(q0,b)=q2
Ī“(q1,a)=q1
Ī“(q2,b)=q2
Ī“(q1,b)=q3
Ī“(q2,a)=q3
Ī“(q3,a)=q3
Ī“(q3,b)=q3
13. ā¢ Design a DFA with ā = {0, 1} accepts those string which starts
with 1 and ends with 0.
ā¢ Design a DFA with ā = {0, 1} accepts the only input 101.
13
14. ā¢ Design a DFA with ā = {0, 1} accepts the strings with an even
number of 0's end by single 1.
14
15. Extended transition function Ī“
ā¢ The DFA define a language: the set of all strings that result in a
sequence of state transitions from the start state to an accepting
state
ā¢ Extended Transition Function
ā¢ Describes what happens when we start in any state and follow any
sequence of inputs
ā¢ If Ī“ is our transition function, then the extended transition function is
denoted by Ī“
ā¢ The extended transition function is a function that takes a state q and
a string w and returns a state p (the state that the automaton
reaches when starting in state q and processing the sequence of
inputs w)
ā¢ Let w=va then
Ī“(q, va) = Ī“(Ī“ (q, v), a). 15
16. Language accepted by DFA
ā¢ The language of a DFA A = (Q, Ī£, Ī“, q0, F), denoted L(A) is
defined by
L(A) = { w | Ī“(q0, w) is in F }
ā¢ The language of A is the set of strings w that take the start
state q0 to one of the accepting states
ā¢ If L is a L(A) from some DFA, then L is a regular language
16
17. Nondeterministic Finite
Automata
ā¢ An NFA is like a DFA, except that it can be in several states at
once.
ā¢ This can be seen as the ability to guess something about the
input.
ā¢ Useful for searching texts
17
18. Formal Definition of NFA
ā¢ A nondeterministic ļ¬nite automaton (NFA) is a 5-tuple
(Q,Ī£,Ī“,q0,F),where
ā¢ Q is a ļ¬nite set called the states,
ā¢ Ī£ is a ļ¬nite set called the alphabet,
ā¢ Ī“:QĆĪ£āP(Q) is the transition function,
ā¢ q0 ā Q is the start state, and
ā¢ F ā Q is the set of accepting states.
18
19. Extended transition function Ī“
ā¢ The extended transition function is a function that takes a
state q and a string w and returns a set of states P (The set of
possible state that the automaton reaches when starting in
state q and processing the sequence of inputs w)
ā¢ Let w=va then
Ī“ š0, š£š = Ī“(
šā²ā Ī“ š0,š£
šā²,a)
19
22. ā¢ Design an NFA with ā = {0, 1} in which double '1' is followed by
double '0'.
ā¢ Design an NFA with ā = {0, 1} accepts all string in which the
third symbol from the right end is always 0.
22
23. Epsilon Nondeterministic Finite
Automata
ā¢ Formal Definition
A Īµ-NFA is a quintuple A=(Q,Ī£,Ī“,q0,F) where
ā¢ Q is a set of states
ā¢ Ī£ is the alphabet of input symbols
ā¢ Īµ is never a member of Ī£. Ī£Īµ is defined to be (Ī£ āŖ Īµ)
ā¢ Ī“: Q Ć Ī£Īµ ā P(Q) is the transition function
ā¢ q0 ā Q is the initial state
ā¢ F ā Q is the set of final states
23
25. Īµ- closure
ā¢ Epsilon means present state can goto other state without any
input. This can happen only if the present state have epsilon
transition to other state.
ā¢ Epsilon closure is finding all the states which can be reached
from the present state on one or more epsilon transitions.
Īµ- closure (0)={0,1,2}
Īµ- closure(1)={1,2}
Īµ- closure(2)={2}
25
32. ā¢ Every DFA is NFA but not vice versa.
ā¢ Both NFA and DFA have same power and each NFA can be
translated into a DFA.
ā¢ There can be multiple final states in both DFA and NFA.
ā¢ NFA is more of a theoretical concept.
ā¢ DFA is used in Lexical Analysis in Compiler.
ā¢ Every NFA is Īµ-NFA but not vice-versa
32
33. Conversion of NFA to DFA
ā¢ Subset Construction Method
1. Create state table from the given NFA.
2. Create a blank state table under possible input alphabets for the
equivalent DFA.
3. Mark the start state of the DFA by q0 (Same as the NFA).
4. Find out the combination of States {Q0, Q1,... , Qn} for each
possible input alphabet.
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.
6. The states which contain any of the final states of the NFA are
the final states of the equivalent DFA.
33
39. Now we will obtain Ī“' transition for state q0.
Ī“'([q0], 0) = [q0]
Ī“'([q0], 1) = [q1]
The Ī“' transition for state q1 is obtained as:
Ī“'([q1], 0) = [q1, q2] (new state generated)
Ī“'([q1], 1) = [q1]
39
40. Now we will obtain Ī“' transition on [q1, q2].
Ī“'([q1, q2], 0) = Ī“(q1, 0) āŖ Ī“(q2, 0)
= {q1, q2} āŖ {q2}
= [q1, q2]
Ī“'([q1, q2], 1) = Ī“(q1, 1) āŖ Ī“(q2, 1)
= {q1} āŖ {q1, q2}
= {q1, q2}
= [q1, q2]
The state [q1, q2] is the final state as well because
it contains a final state q2. 40
41. State 0 1
ā[q0] [q0] [q1]
[q1] [q1, q2] [q1]
*[q1, q2] [q1, q2] [q1, q2]
The transition table for the constructed DFA will
be:
41
42. Conversion of Īµ-NFA to DFA
ā¢ Modified subset construction
1. Find the Īµ-closure for the starting state of Īµ - NFA as a starting
state of DFA.
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.
3. If a new state is found, take it as current state and repeat step
2.
4. Repeat Step 2 and Step 3 until there is no new state present in
the transition table of DFA.
5. Mark the states of DFA as a final state which contains the final
state of Īµ-NFA. 42
43. Example
ā¢ Let us obtain Īµ-closure of each state.
Īµ-closure {q0} = {q0, q1, q2}
Īµ-closure {q1} = {q1}
Īµ-closure {q2} = {q2}
Īµ-closure {q3} = {q3}
Īµ-closure {q4} = {q4}
43
44. ā¢ let Īµ-closure {q0} = {q0, q1, q2} be state A
Ī“'(A, 0) = Īµ-closure {Ī“((q0, q1, q2), 0) }
= Īµ-closure {Ī“(q0, 0) āŖ Ī“(q1, 0) āŖ Ī“(q2, 0) }
= Īµ-closure {q3}
= {q3} call it as state B.
Ī“'(A, 1) = Īµ-closure {Ī“((q0, q1, q2), 1) }
= Īµ-closure {Ī“((q0, 1) āŖ Ī“(q1, 1) āŖ Ī“(q2, 1)}
= Īµ-closure {q3}
= {q3} = B.
44