0% found this document useful (0 votes)
10 views

FLAT Unit 1 Notes(Typed) (1)

Uploaded by

Uday Kiran
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

FLAT Unit 1 Notes(Typed) (1)

Uploaded by

Uday Kiran
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Formal Languages and Automata theory

Unit 1

1. INTRODUCTION
Alphabet: It is a finite set of symbols, represented by Σ.
Example: Σ={0,1}

String: It is a finite sequence of symbols. In general string is represented by 'w'.


Length of string w is denoted by |w|. Empty string is denoted by 'ε', Length of empty string is 0.
Example:
Strings over Σ={a,b} are
a, b, aa, ab, ba, bb, aaa, aab,….

Language: It is a set of strings of symbols from some alphabet.


Examples:
Binary Language:
All the set of strings over Σ={0,1} is called binary language.
Strings={0,1,00,01,10,11, ……}

Note: If Σ is alphabet ,then Σ* represents set of all possible strings over Σ.

2. FINITE AUTOMATA
Finite automata consists of finite set of states and a set of transitions from the state to state that
occur on input symbols chosen from an alphabet Σ.
One state q0 is initial state in which automation starts.
Some states are designated as final states.

Finite automata can be classified into two types based on transition function:
1. Deterministic Finite Automata (DFA)
2. Non-Deterministic Finite Automata (NFA)
2.1 Deterministic Finite Automata (DFA)
It can be defined as M= (Q,Σ,δ,q0,F),
where
Q-Finite set of states
Σ-Input alphabet
δ-Transition function
q0-Initial state
F-Set of final states(accepting states)

Transition function is defined as δ:(Q×Σ) to Q

Transition function on strings defined as : (Q×Σ*) to Q

The Language accepted by DFA is defined as


L(M) = {w / w∈ Σ* and (q0,w)∈F}

RULES:
1. (q,∈)=q. and
2. For all strings w and input symbols a,
(q,wa)=δ( (q,w),a).

Note: δ and are same in DFA.


2.2 Finite Automata Representation
The Finite Automata can also be represented using
1. Transition table
2. Transition diagram

1. Transition table
 In transition table the input symbols are represented as column headers and states are
represented as row headers.
 The initial state is preceded by an arrow symbol and final state is encircled.
 The table entries are transitions i.e. states.

2. Transition diagram

A directed graph called transition diagram is associated with finite automata as follows
 The vertices of the graph correspond to the states of the finite automata.
 If there is a transition from q to state p on input ‘a’ i.e. δ(q,a)=p then there is an arc
labelled 'a' from state q to state p.
 The initial state is represented as vertex preceded by an arrow labelled with start.
 The final states are represented as double circled vertices.
2.3 Design of DFA Examples

1. Design a DFA to accept a string with two consecutive 0’s over the alphabet {0,1} .

Solution:-

M=(Q, Σ,δ,q0,F)

Q={q0,q1,q2}—Set of states

∑={0,1}—Alphabet set

q0=Initial state

F={q2}---Final state

Language, L={0,1,10,11,100,101,110,111,1000,1001,1010,1011,1100,1101,1110,1111…}

2. Design a DFA to recognize binary numbers which are divisible by 3.

Solution:-

M=(Q, Σ,δ,q0,F)

Q={q0,q1,q2,q3}—Set of states

∑={0,1}—Alphabet set
q0=Initial state

F={q1}---Final state

Language, L={0,1,10,11,100,101,110,111,1000,1001,1010,1011,1100,1101,1110,1111…}

3. Design a DFA to recognize strings ending with 10 over the alphabet {0,1}.

Solution:-

M=(Q, Σ,δ,q0,F)

Q={q0,q1,q2}—Set of states

∑={0,1}—Alphabet set

q0=Initial state

F={q2}---Final state

Language, L={0,1,10,11,100,101,110,111,1000,1001,1010,1011,1100,1101,1110,1111…}
2.4 Non-Deterministic Finite Automata (NFA)

NFA allows zero, one or more transitions from a state from the same input symbol.
NFA can be defined as M= (Q,Σ,δ,q0,F),
where
Q-Finite set of states
Σ-Input alphabet
δ-Transition function
q0-Initial state
F-Set of final states(accepting states)

Transition function is defined as δ: (Q×Σ) to 2Q

Transition function on strings defined as : (Q×Σ*) to 2 Q

The Language accepted by NFA is defined as


L(M) = {w / w∈ Σ* and (q0,w) contains a state in F}

RULES:
1. (q,∈)=q. and
2. For all strings w and input symbols a,
(q,wa)=δ( (q,w),a)

3. (P,w)= ⋃ (q, w)

where P is set of states, P⊂=Q.

Note: δ and are same in NFA.


2.5 Design of NFA Examples

1. Design a Non-Deterministic Finite Automata to accept the strings ending with 10.

Solution:-

Q = {q0,q1,q2}

Σ = {0,1}

q 0 = q0

F = {q2}

L = {10,010,110,0010,0110,1010,1110,….}

2. Design a Non-Deterministic Finite Automata to accept the strings with 0’s and 1’s such that
string contains two consecutive 0’s (or) two consecutive 1’s.

Solution:-

Q = {q0,q1,q2,q3,q4}

Σ = {0,1}

q0 = q0

F = {q2, q4}
3. Design a Non-Deterministic Finite Automata to accept the strings ending with 101.

Solution:-

Q = {q0,q1,q2,q3}

Σ = {0,1}

q0 = q0

F = {q3}
2.6 Equivalence between NFA and DFA

Theorem: If L is the language accepted by Non Deterministic Finite automata (NFA) then
there exist a DFA accepting same language L

Procedure to convert NFA to DFA

1. Let M= (Q,∑,δ,q0,F) be an NFA accepting some language L. We can construct a DFA


equivalent to NFA as follows

2. Let M'=(Q',∑,δ',q0',F') is a DFA where Q' is defined as Q'=2Qand all the elements of
power set are represented in square brackets which represents single state
3. Initial state q0'=[q0]
4. F' is the set of all states of Q' which are having the final state of given NFA
5. δ' is calculated using δ'([q],a)=δ(q ,a ), δ'([p , q], a)=δ(p , a) U δ(q , a)

Note: In NFA to DFA conversation we can also define the transition table as follows
1. Start with initial state and define the transition over input symbols.
2. Define the transitions for the states over the input symbols [The transitions not
defined yet] under the input symbol columns.
3. Repeat step 2 until there are no states for which the transitions are to be defined.

2.6.1 NFA to DFA Conversion Problems

1) Convert Following NFA into Equivalent DFA.


Solution:

Given NFA

M= (Q, ∑, δ, q0, F)

Q= {q0, q1}

∑= {0,1}

Q0=q0

F= {q1}

Constructing DFA

M’= (Q|, ∑, δ, q0|, F|)

Q|= {[Ø], [q0], [q1],[q0,q1]}

q0|= {q0}

F|= { [q1],[q0,q1]}

Input Symbols
State 0 1
[q0] [q0,q1] [q1]
[q1] [Ø] [q0,q1]
[q0,q1] [q0,q1] [q0,q1]
[Ø] [Ø] [Ø]
2) Convert Following NFA into Equivalent DFA.
M= {{p, q, r, s}, {0, 1}, δ, p, s}

δ 0 1
p {p, q} p
q r r
r s -
s s s

Sol: DFA:-

Q|={[Ø],[p],[q],[r],[s],[p,q],[q,r],[r,s],[p,s],[q,s],[p,r],[p,q,r],[q,r,s],[p,q,s],[p,r,s],[p,q,r,s]}

q0|= [p]

F|={[s],[r,s],[s,p],[q,s][q,r,s],[p,q,s],[p,r,s],[p,q,r,s] }

δ| 0 1
[p] [p,q] [p]
[p,q] [p,q,r] [p,r]
[p,r] [p,q,s] [p]
[p,q,r] [p,q,r,s] [p,r]
[p,q,s] [p,q,r,s] [p,r,s]
[p,r,s] [p,q,s] [p,s]
[p,s] [p,q,s] [p,s]
[p,q,r,s] [p,q,r,s] [p,r,s]
3) Convert the following NFA TO DFA?

δ 0 1
p [q,s] q
q r [q,r]
r s p
s - p

Solution:

DFA:

Q|={[Ø],[p],[q],[r],[s],[p,q],[q,r],[r,s],[p,s],[q,s],[p,r],[p,q,r],[q,r,s],[p,q,s],[p,r,s],[p,q,r,s]}

q0|= [p]

F|={ [q],[s],[q,r],[p,s],[r,s],[q,s],[p,q],[p,q,r],[q,r,s],[p,r,s],[p,q,s],[p,q,r,s]}

δ| 0 1
[p] [q,s] [q]
[q] [r] [q,r]
[q,s] [r] [p,q,r]
[r] [s] [p]
[q,r] [r,s] [p,q,r]
[p,q,r] [q,r,s] [p,q,r]
[s] [Ø] [p]
[q,r,s] [r,s] [p,q,r]
[r,s] [s] [p]
2.7 NFA- ε Transitions

M= (Q, Σ, δ, q0, F)

– Q is a set of states

– Σ is the alphabet of input symbols

– q0∈Q is the initial state

– F ⊆ Q is the set of final states

– δ: Q × Σ U { ε } to 2Q is the transition function

Transition function on strings

=Q X Σ* to 2Q

ε –closure(q) is the set of all states p such that there is a path from q to p labelled ‘ ε ’.

Rules-

1. (q, ε) =ε-closure(q)
2. (q, wa)=ε-closure(δ( (q,w),a))
3. (p, w)=Uq in p δ(q,a)
4. δ(p,a)=Uq in p δ(q,a)

 Language accepted NFA with ε-transition is


L(M)= {w/w ϵ Σ* and (q0,w) contains a state in F}
 Note-δ and δ` are not same in NFA with ε-transition

2.8 Design NFA- ε Transitions problems

1) Design a NFA with є transitions to accept the language containing any no of zeroes
followed by any no of ones followed by any no of twos.

M={Q, Σ,𝛿,q0,F}

Q={q0,q1,q2}
Σ ={0,1,2}

F={q2}

L={ ε,0,01,10,001,0001……..}
2.8 Equivalence between NFA with ɛ-Transition to NFA

Theorem: If ‘L’ is a Language accepted by NFA with ɛ transitions, then there exists NFA
without ɛ transition (NFA) accepting the same language L.

Procedure to convert NFA with ɛ transition to NFA

Let M=(Q,∑,δ, q0, F) be an NFA with ɛ transition accepting language ‘L’,

We construct NFA M|= (Q, ∑, δ|, q0, F|) equivalent to M with the following steps.

1. Find ɛ-closure of all states.


2. A δ| is defined as (q,a)= ɛ-closure of (δ( (q,ɛ),a)

where, ( q, ɛ) = ɛ-closure(q)

3. F| is defined as the set of all states whose ɛ-closure contains a final state in F.
3. Finite Automata with Output

1. Moore Machine
2. Melay Machine

1. Moore Machine- In this machine the output depends on the State.

Moore Machine M= (Q, ∑, Δ, δ, λ, q0)

Where, Q=Finite set of states

Σ=input alphabet

Δ=output alphabet

δ=transition function

λ=output function

q0=initial state

 The transition function δ is defined as Q X Σ to Q


 The output function λ is defined as λ: Q to Δ
 In general, λ(q) represents output associated with state q.
 The output response of Moore Machine for an input sequence a 1,a2,…..,an is
λ(q0),λ(q1),……λ(qn)
Where,q1,q2,…..,qn are states such that δ(qi-1,ai)=qi for 1<=i<=n

 The Moore machine gives the output λ(q0) for empty input ε.
2. Mealy Machine- In this machine the output depends on the transition.

Mealy Machine-> M=(Q, ∑, Δ, δ, λ, q0)

Where, Q=finite set of states

Σ=input alphabet

Δ=output alphabet

δ=transition function

λ=output function

q0=initial state

 The transition function δ is defined as Q X Σ to Q


 The output function λ is defined as Q X Σ to Δ
 In general λ(q,a) represents output for the transition from a state q over an input symbol
‘a’.
 The output response of Mealy Machine for an input sequence a 1,a2,…..,an is
λ(q0,a1),λ(q1,a2),……λ(qn-1,an)
Where, q0,q1,…..,qn are states such that δ(qi-1,ai)=qi for 1<=i<=n

 The Mealy machine gives the output ε for empty input ε.

You might also like