0% found this document useful (0 votes)
11 views15 pages

Flat 1

Formal Language and automata theory

Uploaded by

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

Flat 1

Formal Language and automata theory

Uploaded by

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

MES ENGINEERING COLLEGE 1 FLAT-MODULE I

MODULE 1- FINITE AUTOMATA

Syllabus:-
Family of formal languages - Finite automata – Type 3 formalism - Deterministic finite automata (DFA) –
Language acceptance - Non-deterministic finite automata (NFA) – Finite automata with epsilon transitions
– Applications - Finite automata with output - NFA to DFA conversions - Equivalence theorem between
DFA and NFA - Minimization of DFA.

1. Family of formal languages


2. Finite automata– Type 3 formalism
3. Deterministic finite automata (DFA)
4. Language acceptance
5. Non-deterministic finite automata (NFA)
6. Finite automata with epsilon transitions
7. Applications
8. Finite automata with output
9. NFA to DFA conversions
10. Equivalence theorem between DFA and NFA
11. Minimization of DFA.

1. Family of formal languages

In automata theory, a formal language is a set of strings of symbols drawn from a finite alphabet. A
formal language can be specified either by a set of rules (such as regular expressions or a context-free
grammar) that generates the language, or by a formal machine that accepts (recognizes) the language.

2. Finite automata– Type 3 formalism


According to Chomsky hierarchy, grammar is divided into 4 types as follows:
1.Type 0 is known as unrestricted grammar.
2.Type 1 is known as context-sensitive grammar.
3.Type 2 is known as a context-free grammar.
4.Type 3 Regular Grammar.

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 2 FLAT-MODULE I

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.

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 ε)

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.
 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
λ.

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 3 FLAT-MODULE I

 Representation − ∑+ = ∑1 ∪ ∑2 ∪ ∑3 ∪…….
 ∑+ = ∑* − { λ }
 Example − If ∑ = { a, b } , ∑+ = { a, b, aa, ab, ba, bb,………..}

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 }

3.DFA
Finite Automaton can be classified into two types −
• Deterministic Finite Automaton (DFA)
• Non-deterministic Finite Automaton (NDFA / NFA)
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.

Things to remember in a DFA


 Every state should have a transition for each symbol in the alphabet.
 A single start state will be there in all DFAs.
 Zero or more final states are allowed.

Formal Definition of a DFA

A DFA 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.
• δ is the transition function where δ: Q × ∑ → Q
• 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).

Graphical Representation of a DFA


A DFA is represented by digraphs called state diagram.

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 4 FLAT-MODULE I

• 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.

4. Language acceptance
Let a deterministic finite automaton be →
• Q = {a, b, c},
• ∑ = {0, 1},
• q0 = {a},
• F = {c},
and Transition function δ as shown by the following table −

PRESENT STATE NEXT STATE FOR NEXT STATE FOR


INPUT 0 INPUT 1
->a a b
b c a
*c b c

Its graphical representation would be as follows −

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 5 FLAT-MODULE I

5. Non-deterministic Finite Automata


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.

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)
• 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).

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.
Example Let a non-deterministic finite automaton be →
• Q = {a, b, c}
• ∑ = {0, 1}
• q0 = {a}
• F = {c}

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 6 FLAT-MODULE I

The transition function δ as shown below −


PRESENT STATE NEXT STATE FOR NEXT STATE FOR
INPUT 0 INPUT 1
->a a,b b
b c a,c
*c b,c c
Its graphical representation would be as follows −

The following table lists the differences between DFA and NDFA

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 7 FLAT-MODULE I

6.Finite Automata with Null Moves (NFA-ε)


ε closure of a set
By reading ε from a state , which all states can be reached
εClosure of (q0) = {q0,q1,q2}
εClosure of (q1) = {q1,q2}
εClosure of (q2) = {q2}

A Finite Automaton with null moves (FA-ε) does transit not only after giving input from the alphabet set
but also without any input symbol. This transition without input is called a null move.
An NFA-ε is represented formally by a 5-tuple (Q, ∑, δ, q0, F), consisting of
• Q − a finite set of states
• ∑ − a finite set of input symbols
• δ − a transition function δ : Q × (∑ ∪ {ε}) → 2Q
• q0 − an initial state q0 ∈ Q
• F − a set of final state/states of Q (F⊆Q).

Finite automata with null moves:-

The above (FA-ε) accepts a string set − {0, 1, 01}

7. Applications
1. A Finite Automata is highly useful in designing Lexical Analyzers.
2. A Finite Automata is highly useful in designing text editors.
3. A Finite Automata is highly useful in designing spell checkers.
4. A Finite Automata is highly useful in designing Sequential Cicrcuit design (Transducer).

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 8 FLAT-MODULE I

8. Finite automata with output:- Moore and Mealy Machines

Finite automata may have outputs corresponding to each transition. There are two types of finite state
machines that generate output −
• Mealy Machine
• Moore machine

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, 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

• q0 is the initial state from where any input is processed (q0 ∈ Q).
The state table of a Mealy Machine is shown below

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 9 FLAT-MODULE I

The state diagram of the above Mealy Machine is −

Moore Machine
Moore machine is an FSM whose outputs depend on only the present state. A Moore machine can be
described bya 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
• q0 is the initial state from where any input is processed (q0 ∈ Q).
The state table of a Moore Machine is shown below
NEXT STATE
PRESENT INPUT 0 INPUT 1 Output
STATE

->a b C X2

B b D X1

C c D X2

D d D X3

The state diagram of the above Moore Machine is −

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 10 FLAT-MODULE
I

9. NFA to DFA conversions

Problem Statement
Let X = (Qx, ∑, δx, q0, Fx) be an NDFA which accepts the language L(X). We have to design an
equivalent DFA Y = (Qy, ∑, δy, q0, Fy) such that L(Y) = L(X). The following procedure converts the
NDFA to its equivalent DFA
− Algorithm Input − An NDFA
Output − An equivalent DFA
Step 1 − Create state table from the given NDFA.
Step 2 − Create a blank state table under possible input alphabets for the equivalent DFA.
Step 3 − Mark the start state of the DFA by q0 (Same as the NDFA).

Step 4 − Find out the combination of States {Q0, Q1,... , Qn} for each possible input alphabet.
Step 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.

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 11 FLAT-MODULE
I

Step 6 − The states which contain any of the final states of the NDFA are the final states of the equivalent
DFA. Example:- Let us consider the NDFA shown in the figure below

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 12 FLAT-MODULE
I

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 13 FLAT-MODULE
I

10. Equivalence theorem between DFA and NFA

11. Minimization of DFA.


DFA Minimization using Equivalence Theorem.
If X and Y are two states in a DFA, we can combine these two states into {X, Y} if they are not
distinguishable. Two states are distinguishable, if there is at least one string S, such that one of δ (X, S)
and δ (Y, S) is accepting and another is not accepting. Hence, a DFA is minimal if and only if all the states
are distinguishable.
Algorithm
Step 1 − All the states Q are divided in two partitions − final states and non-final states and are denoted
by P0. All the states in a partition are 0thequivalent. Take a counter k and initialize it with 0
Step 2 − Increment k by 1. For each partition in Pk, divide the states in Pkinto two partitions if they are k-
distinguishable. Two states within this partition X and Y are k-distinguishable if there is an input S such
that δ(X, S) and δ(Y, S) are (k-1)-distinguishable.
Step 3 − If Pk ≠ Pk-1, repeat Step 2, otherwise go to Step 4.
Step 4 − Combine kth equivalent sets and make them the new states of the reduced DFA.

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT


MES ENGINEERING COLLEGE 14 FLAT-MODULE
I

• P0 = {(c,d,e), (a,b,f)}
• P1 = {(c,d,e), (a,b),(f)}
• P2 = {(c,d,e), (a,b),(f)}
Hence, P1 = P2.There are three states in the reduced DFA.
The reduced DFA is as follows −

SOUMYA P V Downloaded from Ktunotes.in DEPT. OF IT

You might also like