0% found this document useful (0 votes)
18 views100 pages

FA MSC 2

The document provides an introduction to key concepts in formal languages and automata theory, including definitions of alphabets, strings, languages, and operations on languages. It explains the Kleene star and closure, finite automata, and the roles of acceptors, classifiers, and transducers in automata. Additionally, it covers the structure of finite automata, transition functions, and examples of input processing and acceptance/rejection of strings.

Uploaded by

Safiyya Mustapha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views100 pages

FA MSC 2

The document provides an introduction to key concepts in formal languages and automata theory, including definitions of alphabets, strings, languages, and operations on languages. It explains the Kleene star and closure, finite automata, and the roles of acceptors, classifiers, and transducers in automata. Additionally, it covers the structure of finite automata, transition functions, and examples of input processing and acceptance/rejection of strings.

Uploaded by

Safiyya Mustapha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 100

FIRST LECTURE

MSc Computer Science


29TH zulhajji 1440

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

a, ab, aaaa bb, ab {a, ab, bb, aaaa}


a, ab, aaaa bb, ab {ab}
a, ab, aaaa  bb, ab a, aaaa
Complement: L  *  L

a, ba  , b, aa, ab, bb, aaa,


10
Reverse

R R
Definition: L {w : w  L}

Examples:ab, aab, babaR ba, baa, abab

n n
L {a b : n 0}

R n n
L {b a : n 0}
11
Concatenation

Definition: L1L2  xy : x  L1, y  L2 

Example:a, ab, bab, aa

ab, aaa, abb, abaa, bab, baaa


12
Another Operation
Definition: n
L LL L
n
3
a, b a, ba, ba, b 
aaa, aab, aba, abb, baa, bab, bba, bbb
Special case: L0 

a, bba, aaa0 


13
Star-Closure (Kleene *)

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

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.
17
Finite Automaton

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

A classifier has more than two final


states and it gives a single output when
it terminates.

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

 * q0 , abbbaa  q5


a, b

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 languageLM  contains
all input strings accepted by
M

LM  = { strings that drive


M to a final
state}

64
Example
LM  abba M

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

accept
65
Another Example
LM   , ab, abba M

a, b

q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4

accept accept accept


66
Formally

For a DFA M Q, ,  , q0 , F 

M
Language accepted by :

LM  w  * :  * q0 , w F 

alphabet transition initial final


function state states
67
Observation
M
Language accepted by :

LM  w  * :  * q0 , w F 

Language rejected byM :

LM  w  * :  * q0 , w F 

68
More Examples

n
LM  {a b : n 0}

a a, b

b a, b
q0 q1 q2

accept trap state

69
LM= { all substrings with prefix ab }
a, b

q0 a q1 b q2

b a accept

q3 a, b
70
LM = { all strings without
substring 001 }

1 0 0,1
1

 0 1
0 00 001

0
71
Regular Languages

A languageL is regular if there is


a DFA M such that L LM 

All regular languages form a language


family

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)

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.

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

Its graphical representation would be as follows


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

Its graphical representation would be as follows


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

4. Empty string transitions are not seen in


DFA.
NDFA permits empty string transitions.

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

A deterministic finite state machine is a quintuple (Σ,,Q ,q,0 δ,F), where:


• Σ is the input alphabet (a finite, non-empty set of symbols).
•Q is a finite, non-empty set of states.
•q is an initial state, an element of Q.
0

• δ is the state-transition function: δ : Q  Σ →Q.


• F is the set of final states, a (possibly empty) subset of Q

A finite state transducer is a 6-tuple (Σ,Γ,,Q ,q,0 δ,F) as above except:



Γ is the output alphabet (a finite, non-empty set of symbols).

δ is the state-transition function: δ : Q  Σ →Q  Γ.
Mealy Machine
A Mealy Machine is an FSM whose output depends
on the present state as well as the present input.
It can be described by a 6 tuple (Q, ∑, O, δ, X, q 0)
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
89
A Transition diagram of a Mealy
Machine

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

Input = 0 Input = 1 output

→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

A grammar is a 4-tuple G= (N,T,S,P)


Where
N is the non terminal
T is the terminal
S is the start symbol
P is the set of production

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.

You might also like