FA MSC 2
FA MSC 2
1
String /Alphabet /
Languages
2
Related Terminologies
Alphabet
Definition − An alphabet is any finite
set of symbols.
Example − ∑ = {a, b, c, d} is an
alphabet set where ‘a’, ‘b’, ‘c’, and ‘d’
are symbols.
3
String
Definition − A string is a finite
sequence of symbols taken from ∑.
Example − ‘cabcad’ is a valid string on
the alphabet set ∑ = {a, b, c, d}
Length of a String
Definition − It is the number of symbols
present in a string. (Denoted by |S|).
Examples −
If S = ‘cabcad’, |S|= 6
If |S|= 0, it is called an empty string
(Denoted by λ or ε) 4
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.
5
Example − If ∑ = {a, b}, ∑* = {λ, a, b,
aa, ab, ba, bb,………..}
Kleene Closure / Plus
Definition − The set ∑+ is the infinite set
of all possible strings of all possible
lengths over ∑ excluding λ.
Representation − ∑+ = ∑1 ∪ ∑2 ∪ ∑3
∪…….
∑+ = ∑* − { λ }
Example − If ∑ = { a, b } , ∑+ = { a, b, 6
Language
Definition − A language is a subset of ∑*
for some alphabet ∑. It can be finite or
infinite.
Example − If the language takes all
possible strings of length 2 over ∑ = {a,
b}, then L = { ab, aa, ba, bb }
7
Language
Definition − A language is a subset of ∑*
for some alphabet ∑. It can be finite or
infinite.
Example − If the language takes all
possible strings of length 2 over ∑ = {a,
b}, then L = { ab, aa, ba, bb }
8
n n
L {a b : n 0}
2 n n m m
L {a b a b : n, m 0}
9
Operations on Languages
The usual set operations
R R
Definition: L {w : w L}
n n
L {a b : n 0}
R n n
L {b a : n 0}
11
Concatenation
0 1 2
Definition: L* L L L
Example:
,
a, bb,
a, bb*
aa , abb, bba , bbbb,
aaa, aabb, abba, abbbb,
14
Positive Closure
1 2
Definition: L L L
L *
a, bb,
a, bb aa, abb, bba, bbbb,
aaa, aabb, abba, abbbb,
15
Finite Automata
16
Automata – definition
Input
String
Output
Finite String
Automaton
18
Finite Accepter
Input
String
Output
“Accept”
Finite or
Automaton “Reject”
19
Acceptors, Classifiers, and Transducers
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.
20
Classifier
21
Transducer
An automaton that produces outputs
based on current input and/or previous
state is called a transducer.
22
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.
23
Definition of an Automatom
et of final states
M Q, , , q0 , F
An automaton can be represented by a 5-tuple (Q, ∑, δ, q0, F), where −
Q is a finite set of states.
∑ is a finite set of symbols, called the alphabet of the automaton.
δ is the transition function.
q0 is the initial state from where any input is processed (q0 ∈ Q).
F is a set of final state/states of Q (F ⊆ Q).
24
An automaton with a finite number of states is
called a Finite Automaton (FA) or Finite
State Machine (FSM).
25
Transition Graph
abba-Finite Accepter a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
initial final
state state
transition
state “accept”
26
Initial Configuration
Input String
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
27
Reading the Input
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
28
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
29
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
30
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
31
a b b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Output: “accept”
32
Regular Expressions &
Finite State Machines
a b c
b
a
c
b
a Note the special double-circle
designation of an accepting state.
b c
a c
a
Discussion #1
Rejection
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
34
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
35
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
36
a b a
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
37
a b a
a, b
Output:
q5 “reject”
a, b
b a a b
q0 a q1 b q2 b q3 a q4
38
Another Example
a a b
a a, b
b a, b
q0 q1 q2
39
a a b
a a, b
b a, b
q0 q1 q2
40
a a b
a a, b
b a, b
q0 q1 q2
41
a a b
a a, b
b a, b
q0 q1 q2
42
a a b
a a, b
Output: “accept”
b a, b
q0 q1 q2
43
Rejection
b a b
a a, b
b a, b
q0 q1 q2
44
b a b
a a, b
b a, b
q0 q1 q2
45
b a b
a a, b
b a, b
q0 q1 q2
46
b a b
a a, b
b a, b
q0 q1 q2
47
b a b
a a, b
b a, b
q0 q1 q2
Output: “reject”
48
Formalities
Deterministic Finite Accepter (DFA)
M Q, , , q0 , F
Q : set of states
: input alphabet
: transition function
q0 : initial state
F : set of final states
49
Input Aplhabet
a, b
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
50
Set of States Q
Q q0 , q1, q2 , q3 , q4 , q5
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
51
Initial State q0
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
52
Set of Final States F
F q4
a, b
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
53
Transition Function
: Q Q
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
54
q0 , a q1
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
55
q0 , b q5
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
56
q2 , b q3
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
57
Transition Function
a b
q0 q1 q5
q1 q5
q5
q2
q2 q5 q3
q3 q4 q5 a, b
q4 q5 q5
q5 q5 q5 q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
58
Extended Transition Function *
* : Q * Q
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
59
* q0 , ab q2
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
60
* q0 , abba q4
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
61
* q0 , abbbaa q5
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
62
Observation: There is a walk fromq0 toq1
with label abbbaa
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
63
Languages Accepted by DFAs
Take DFA M
Definition:
The languageLM contains
all input strings accepted by
M
64
Example
LM abba M
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
accept
65
Another Example
LM , ab, abba M
a, b
q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4
M
Language accepted by :
68
More Examples
n
LM {a b : n 0}
a a, b
b a, b
q0 q1 q2
69
LM= { all substrings with prefix ab }
a, b
q0 a q1 b q2
b a accept
q3 a, b
70
LM = { all strings without
substring 001 }
1 0 0,1
1
0 1
0 00 001
0
71
Regular Languages
72
Example
The languageL awa : w a, b *
is regular:
a
b
b
q0 a q2 q3
b a
q4
a, b 73
A DFA is represented by diagram called
state diagram.
The vertices represent the states.
The arcs labeled with an input alphabet
show the transitions.
The initial state is denoted by an empty
single incoming arc.
The final state is indicated by double
circles.
74
Finite Automaton can be classified into
two types −
Deterministic Finite Automaton (DFA)
Non-deterministic Finite Automaton (NDFA
/ NFA)
75
Deterministic Finite Automaton
(DFA)
76
Graphical Representation of a DFA
A DFA is represented by digram called state diagram.
•The vertices represent the states.
•The arcs labeled with an input alphabet show the
transitions.
•The initial state is denoted by an empty single incoming arc.
•The final state is indicated by double circles.
Example
Let a deterministic finite automaton be →
•Q = {a, b, c},
•∑ = {0, 1},
•q0 = {a},
•F = {c}, and
77
Transition function δ as shown by the following table −
Present State Next State for input 0 Next State for input
1
a a b
b c a
c b c
78
Non-deterministic Finite
Automaton
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.
79
Formal Definition of an NDFA
An NDFA can be represented by a 5-tuple
(Q, ∑, δ, q0, F) where −
Q is a finite set of states.
∑ is a finite set of symbols called the
alphabets.
δ is the transition function where δ: Q × ∑
→ 2Q
(Here the power set of Q (2Q) has been
taken because in case of NDFA, from a
state, transition can occur to any
combination of Q states) 80
q0 is the initial state from where any
input is processed (q0 ∈ Q).
F is a set of final state/states of Q (F ⊆
Q).
81
Graphical Representation of an
NDFA:
(same as DFA)
An NDFA is represented by digraphs
called state diagram.
The vertices represent the states.
The arcs labeled with an input alphabet
show the transitions.
The initial state is denoted by an empty
single incoming arc.
The final state is indicated by double
circles.
82
Example
Let a non-deterministic finite automaton
be →
Q = {a, b, c}
∑ = {0, 1}
q0 = {a}
F = {c}
83
Transition function δ as shown by the following table −
Present State Next State for input 0 Next State for input
1
a a, b b
b c a, c
c b, c c, c
84
Distinction between DFA and NDFA
1. The transition from a state is to a
single particular next state for each
input symbol. Hence it is called
deterministic.
The transition from a state can be to
multiple next states for each input
symbol. Hence it is called non-
deterministic.
2. Empty string transitions are not seen in
DFA.
NDFA permits empty string transitions.
85
3. Backtracking is allowed in DFA
In NDFA, backtracking is not always
possible.
Requires more space
86
5. A string is accepted by a DFA, if it
transits to a final state.
A string is accepted by a NDFA, if at
least one of all possible transitions ends
in a final state.
87
Formal Definition of a Finite State
Machine & a Finite State Transducer
90
A Transition Table of a Mealy Machine
Next state
Present Input 0 Input a
state state output state output
→a b x1 c x1
b b x2 d x3
c d x3 c x1
d d x3 d x2
91
Moore Machine
A Moore machine output depends only on the
current state. It can be described by a 6 tuple
(Q, ∑, O, δ, X, q0) where −
Q is a finite set of states.
∑ is a finite set of symbols called the input
alphabet.
O is a finite set of symbols called the output
alphabet.
δ is the input transition function where δ: Q × ∑
→Q
X is the output transition function where X: Q →
O
92
q is the initial state from where any input is
A Transition diagram of a Moore
Machine
93
A Transition Table of a Moore Machine
Next state
Present state
→a b c x2
b b d x1
c c d x2
d d d x3
94
Machine.
1. In Mealy Machine, the output depends both
upon the present state and the present input
while in Moore Machine, the output depends
only upon the present state only.
2. Generally, Mealy has fewer states than
Moore Machine. Generally, it has more states
than Mealy Machine.
3. The value of the output function is a function
of the transitions and the changes, when the
input logic on the present state is done. While
in Moore, The value of the output function is a
function of the current state and the changes
at the clock edges, whenever state changes
occur. 95
4. Mealy machines react faster to inputs. They
generally react in the same clock cycle. In
Moore machines,
Logic is required to decode the outputs
resulting in more circuit delays. They
generally react one clock cycle later.
96
Defination of a grammar
97
Determine a grammar for the following
languages:
(i) {abcd}
(ii) {01001}
98
An ambiguous grammar generates more than one parse
tree for some string w in L(G).
A left-linear grammar is a context-free grammar in
which every production is restricted to one of
the following forms: A→Bw
A→w, where A and B are the non-terminals, and w is
in T *. That is, the non terminal symbol always appear
to the left of the terminal symbol.
Right linear grammar is a context-free grammar
in which every production is restricted to one of
the following forms:
A→wB
A→w, where A and B are the non-terminals, and
w is in T *. That is, the non terminal symbol
always appear to the right of the terminal
symbol.