Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit 1: Finite State Machines

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 52

Unit 1

Finite State Machines


Some basic concepts

1)Symbol:
Symbol is a character.
Ex: a,b,c,……..z
0,1,2,…….9
+,-,%,…………special characters
2) Alphabet:

• An alphabet is a finite,non empty set of symbol.


• It is denoted by ∑
• ex: ∑ ={0,1} set of binary alphabets
∑ = {a,b,…..z} set of all lowercase letters
∑ = {+,&,%,…….}
3) String:
A string is a finite set of sequence of symbols choosen from some
alphabets
ex: 011100110 is a string from binary alphabet ∑ ={0,1}
aabbaacab is a string from alphabet ∑={a,b,c}

Symbol Alphabet String or word


a,1,0 {0,1} 01101001
{ a,b,….} abbcd
Formal and natural languages

Natural language Formal language


Symbol : basic building blocks a,b,……….z {0,1}
which can be any character {a,b}
Alphabet : finite non empty set of {a,b,……..z} ∑ = {0,1}
symbols
String : finite sequence of symbols Boy 000 100
buuaaay

Language: set of strings


Operations
The different operations performed on strings are explained below −
1) Concatenation.
2) Substring.
3) Kleene star operation.
4) Reversal.
1) Concatenation:
• Concatenation is nothing but combining the two strings one after
another
• Example:
Let’s consider two strings -
X= computer
Y= science
The concatenation (X, Y) of two strings is −
X.Y = computerscience

• Concatenation of empty string with other string gives string itself.


For example, X. ε = ε.X = X
2) Substring:
• If ‘w’ is a string then ‘v’ is substring of ‘w’ if there exists string x and y
such that w=xvy
‘x’ is called ‘prefix’ and y is called the suffix of w

• Example
Let’s consider w=’Theory’ is defined with prefix, x=’The’ and suffix ,
y=’ry’.
The substring is v=’o’, because, w=xvy and Theory= Thevry
Therefore, v=o
3) Kleene star operation :
• Let ‘w’ be a string. w’ is a set of strings obtained by applying any
number of concatenations of w with itself, including empty string.
• Example
a*= { ε,a,aa,aaa,………}
4)Reversal:
• If ‘w’ is a string, then wR is the reversal of the string in backwards.
• Rules
The rules for the reversal operation are as follows −
x=(xR)R
(xz)R= zR.xR

Example
A string x is defined as x= tutorial then (xR)R is tutorial. This is because,
X= tutorial
(x)R= lairotut
(xR)R= tutorial
Deterministic Finite Automata
• DFA refers to deterministic finite automata. Deterministic refers to the
uniqueness of the computation.
• The finite automata are called deterministic finite automata if the
machine is read an input string one symbol at a time.
• 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.
• DFA can contain multiple final states. It is used in Lexical Analysis in
Compiler.
In the following diagram, we can see that from state q0 for input a,
there is only one path which is going to q1. Similarly, from q0, there is
only one path for input b going to q2.
A DFA is a collection of 5-tuples same as we described in the definition
of FA.
1)Q: finite set of states  
2)∑: finite set of the input symbol  
3)q0: initial state   
4)F: final state  
5)δ: Transition function  
Example 1:
Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and
ends with 0.
Solution:
The FA will have a start state q0 from which only the edge with input 1
will go to the next state.
Example 2:
Design a FA with ∑ = {0, 1} accepts the only input 101.
Solution:
Example 3:
Design FA with ∑ = {0, 1} accepts even number of 0's and even number of 1's.
Solution:
This FA will consider four different stages for input 0 and input 1. The stages could
be:
Example 4:
Design FA with ∑ = {0, 1} accepts the set of all strings with three consecutive 0's.
Solution:
The strings that will be generated for this particular languages are 000, 0001, 1000,
10001, .... in which 0 always appears in a clump of 3. The transition graph is as
follows:
NFA (Non-Deterministic finite automata)
• NFA stands for non-deterministic finite automata. It is easy to
construct an NFA than DFA for a given regular language.

• The finite automata are called NFA when there exist many paths for
specific input from the current state to the next state.

• Every NFA is not DFA, but each NFA can be translated into DFA.

• NFA is defined in the same way as DFA but with the following two
exceptions, it contains multiple next states, and it contains ε transition.
A NFA is a collection of 5-tuples same as we described in the
definition of FA.
1)Q: finite set of states  
2)∑: finite set of the input symbol  
3)q0: initial state   
4)F: final state  
5)δ: Transition function  
Example 1:
NFA with ∑ = {0, 1} accepts all strings with 01.
Solution:

Present State Next state for Next State of


Input 0 Input 1
→q0 q1 ε
q1 ε q2
*q2 q2 q2
Example 2:
NFA with ∑ = {0, 1} and accept all string of length atleast 2.

Present State Next state for Next State of


Input 0 Input 1
→q0 q1 q1
q1 q2 q2
*q2 ε ε
Conversion of NFA to DFA
a,b
b

δ a b
a
q0 q1
q0 {q0,q1} q0

q1 q2 q1
a

q2 q3 q3
a,b
q3 q2 q3 - q2
b
b
δ a b b
a
q0 [q0,q1] q0 q0 q0,q1

[q0,q1] [q0,q1,q2] [q0,q1]


a
[q0,q1,q2] [q0,q1,q2,q3] [q0,q1,q3]
b
[q0,q1,q2,q3] [q0,q1,q2,q3]
[q0,q1,q2,q3] q0,q1,q3 q0,q1,q2
[q0,q1,q3] [q0,q1,q2] [q0,q1,q2] a,b

a
a,b

q0,q1,q2,q3
Conversion of epsilon NFA to NFA

1)Find all edges starting from S2


2)Duplicate all edges to S1 without changing edge labels
3)If S1 is initial state,make S2 initial
4) If S2 is final state,make S1 final
ε ε 0 1
q0 q1 q4 q5 q6

1
0 0 1

q2 q3

q3
FINITE AUTOMATA

FINITE AUTOMATA WITH OUTPUT


FINITE AUTOMATA WITHOUT OUTPUT

Mealy Machine Moore Machine DFA NFA

NFA with ϵ

Prof. Saima Zareen Ansari 26


FINITE AUTOMATA WITH OUTPUT

Moore Machine Mealy Machine

λ 0Q =Δ λ 0Q * Ʃ = Δ

Mealy and Moore machine consist of SIX TUPLE:


(Q, Ʃ, δ, qo, Δ, λ)
Q= Set of State
Ʃ= Set of Alphabet
δ= Transition
q0= Initial State
Δ= Set of Output alphabet (Output Symbol)
λ= Output Mapping Function
Prof. Saima Zareen Ansari 27
Conversion of Mealy Machine to Moore Machine
1. Find out different output generated with qί in the next state column of Mealy
Machine.
2. Then split qί into different states depending upon output generated with it.
For example: If output generated by qί is ‘1’ in the first next state column &
‘0’ in the second next state column, then split q1 into q10 & q11.
Follow the above steps for all the states.
3. Now copy all the present states & next states in Moore machine format and
output of the next state are common.

Prof. Saima Zareen Ansari 48


Conversion of Mealy to Moore Machine
Q*Ʃ=Δ : Q=Δ

Prof. Saima Zareen Ansari 49


Conversion of Moore Machine to Mealy Machine
1. Draw the Mealy machine table.
2. Copy all the Present state & Next state column of the states into the table.
3. For output column of the Next state, check Present state & its output generated
in the Moore Machine table.
For example: If output generated by state Qί is ‘m’, copy this output into the
output column of Mealy machine table wherever Qί is present in the next state.

Prof. Saima Zareen Ansari 50


Conversion of Moore to Mealy Machine
Q=Δ : Q*Ʃ=Δ

Prof. Saima Zareen Ansari 51


Construction of Moore & Melay Machine

Prof. Saima Zareen Ansari 52

You might also like