0% found this document useful (0 votes)
62 views33 pages

Finite Automata Theory Overview

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)
62 views33 pages

Finite Automata Theory Overview

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

Module I: Finite

Automata

04/02/2024 Department of Computer Science & Engineering, GIT 1


19ECS303: Formal Languages and Automata Theory

• Formal Languages and Automata Theory(FLAT) or Theory of Computation(TOC) is a


theoretical study of abstract machines/devices or mathematical models for solving
computational problems.

• This course will give the knowledge in fundamentals of Automata theory that can
recognize formal languages.

• This knowledge can further be applied widely in compiler construction, artificial


intelligence.

04/02/2024 Department of Computer Science & Engineering, GIT 2


Unit-I
Syllabus:
Finite Automata: Central concepts of strings, languages and automata theory,
Deterministic Finite Automata, Non-Deterministic Finite Automata, Finite Automata with
Epsilon Transitions, Finite Automata with Output.
Learning Outcomes:
After completion of this unit, the student will be able to
• illustrate the central concepts of automata theory.
• construct different finite state machines for modeling and solving computational
problems.
• illustrate the concepts in the design of Finite State Machines to recognize Regular
Languages.

04/02/2024 Department of Computer Science & Engineering, GIT 3


Central Concepts of Automata Theory

• Symbol is the smallest building block, which can be any alphabet, letter, or any picture.

Ex: Symbols are : a, b, c, ……, z, A, B,……,Z, 0, 1, …..9


• Alphabet is a finite set of input symbols. It is denoted by Σ(Sigma).

Ex: Σ = {0,1} is an alphabet of binary digits


Σ = {a,b,c} is one alphabet
Σ = {1,2,a,b,+} is one alphabet

• String is a finite sequence of symbols chosen from some alphabet. It is denoted by w.


• We can also call a sentence

04/02/2024 Department of Computer Science & Engineering, GIT 4


Central Concepts of Automata Theory

• Length of a string is the number of symbols in the string. It is denoted by |w|.

Ex: If w=abaa is a string then length is |w|=|abaa|=4.

Q? How many number of strings of length 2 can be generated over an alphabet Σ={a,b}.
Ans: The length of the string should be 2 i.e _ _ (2 spaces) so for each blank space
I have 2 combinations(Because Σ is with 2 symbols) So 2x2 = 22 = 4
Strings are: aa
ab
ba
bb

04/02/2024 Department of Computer Science & Engineering, GIT 5


Central Concepts of Automata Theory
Similarly, Number of strings of length n can be generated over the alphabet Σ={a,b} is:
Ans: The length of the string should be n i.e _ _ _ _ and so on n (n spaces)
so for each blank space I have 2 combinations(Because Σ={a,b} is with 2 symbols)
so 2x2x2x2 and so on n times = 2n
Conclusion:
 If number of symbols of Σ={a,b}is 2, then number of strings of length n that can be
generated over the alphabet Σ is 2n
 Suppose If number of symbols of Σ={a,b,c}is 3, then number of strings of length n that
can be generated over the alphabet Σ is 3n
 So from the above, if number of symbols of Σ is represented by |Σ|, then number of
strings of length n that can be generated over the alphabet Σ is |Σ|n

04/02/2024 Department of Computer Science & Engineering, GIT 6


Central Concepts of Automata Theory

• Powers of Σ (Powers of an alphabet): ΣK is nothing but set of all strings of length K,


over Σ.
Ex: If Σ={a,b}, then
• Σ1 is set of all strings over Σ of length ‘1’, i.e Σ 1 ={a,b} and total strings is: |Σ 1| = 2
• Σ2 is set of all strings over Σ of length ‘2’ i.e Σ2 => Σ.Σ (concatenation) => {aa, ab, ba,
bb} and total strings is: |Σ2| = 4

• Empty String consisting of zero symbols, it is denoted by ε(epsilon).


Σ0 is nothing but set of all strings over Σ of length ‘0’ i.e Σ0 ={ε} , ε is called epsilon, |
ε|=0, and total strings is: |Σ0| = 1

04/02/2024 Department of Computer Science & Engineering, GIT 7


Central Concepts of Automata Theory

• Kleene Closure is set of all possible strings including epsilon(ε) over an alphabet Σ, it is
denoted by Σ*
Σ* is union of all lengths of strings = Σ 0 U Σ1 U Σ2 U Σ3 …….. Σn
Ex: If Σ={a,b}, then Σ* = {{ε} U {a,b} U {aa,ab,ba,bb} ……………}
i.e Σ* = {ε, a, b, aa, ab, ba, bb, aaa, aab, aba, ……………}
• Positive Kleene Closure is set of all possible strings excluding epsilon(ε) over an
alphabet Σ, it is denoted by Σ+
Ex: Σ+ = {a, b, aa, ab, ba, bb, aaa, aab, aba, ……………}

04/02/2024 Department of Computer Science & Engineering, GIT 8


Central Concepts of Automata Theory

• Language is a set of strings, chosen from some alphabet Σ. It is denoted by L. Or we


can say- A Language is a subset of Σ*.
• Σ* is anyways an infinite language but also a complete language.
• Σ* is the super set of all the languages i.e If L is a language, then L Σ*
Examples:
1. Set of all strings of length 2 that can be generated over the alphabet Σ ={a,b},
L1 = {aa, ab, ba, bb} // This is a “Finite Language”
2. Set of all strings which start with ‘a’ can be generated over the alphabet Σ ={a,b},
L2 = {a, aa, ab, aab, aba, aaa, ………………} //This is an “Infinite Language”
Note: Language which can be formed over Σ can be Finite Or Infinite.
04/02/2024 Department of Computer Science & Engineering, GIT 9
Central Concepts of Automata Theory

Question: L1={ } and L2={ε} are the valid languages or not.


1. L1={ } is empty set and is a valid language, it is called an empty language. It is
denoted by Φ(phi).
2. L2={ε} is the set consisting of empty string(epsilon) and is also a valid language, but it
is not an empty language, because it has one string i.e epsilon.

04/02/2024 Department of Computer Science & Engineering, GIT 10


Membership Problem(Finite Automata)

04/02/2024 Department of Computer Science & Engineering, GIT 11


04/02/2024 Department of Computer Science & Engineering, GIT 12
Finite Automata(Finite State Machine)
• Automaton (Plural: automata) is an “abstract computing machine/device” (simply
called a mathematical model), i.e something that works automatically or a self-
operating machine/device.

Ex: ATM, Cola-Machine, etc.

• Finite Automata (FA):


• Finite automata is a mathematical model which contains finite number of states
and transitions.
• Basically, it is the simplest machine of digital computer to recognize
patterns(languages).
• It is a recognizer for regular languages.
04/02/2024 Department of Computer Science & Engineering, GIT 13
Formal Definition of Finite Automata:
An automaton can be represented by a 5-tuples (Q, ∑, δ, q0 , F) and denoted by M.
Where:
1. Q is a finite set of states.
2. ∑ is a finite set of input symbols, called the alphabet. ∑ is called Sigma.
3. δ is the transition function. δ is called Delta. Transition Function is defined as:
• Transition Function takes a state and input symbol as arguments, then returns a state/states.
• Ex: δ(q,a) = p, where q and p are states, a is an input symbol.
• i.e if the FA is in state q, and input a is received, then the FA goes to state p.
4. q0 is the initial state/starting state from where any input is processed (q0 ∈ Q).
5. F is a set of final state/states (F ⊆ Q).

04/02/2024 Department of Computer Science & Engineering, GIT 14


Classification of Finite Automata:
Finite automata can be classified into two types:

1. Finite Automata without output: we have three categories.


o Deterministic Finite Automata (DFA).
o Non-Deterministic Finite Automata (NFA or NDFA).
o Non-Deterministic Finite Automata with epsilon moves (ε-NFA or ε-NDFA).

2. Finite Automata with output: we have two categories.


o Moore machine.
o Mealy machine.

• Finite Automata Notations:

The FA can be represented in two ways:


1. Transition Diagram
2. Transition Table
04/02/2024 Department of Computer Science & Engineering, GIT 15
Transition Diagram:

04/02/2024 Department of Computer Science & Engineering, GIT 16


Transition Diagram:

04/02/2024 Department of Computer Science & Engineering, GIT 17


Transition Table:

04/02/2024 Department of Computer Science & Engineering, GIT 18


Transition Table:

04/02/2024 Department of Computer Science & Engineering, GIT 19


Acceptance of String and Language
Acceptance of String: Given a string ‘w’, we can determine whether the string ‘w’ is
accepted by the Finite Automata (DFA/NFA) or not.
• Starting from the initial state by scanning the characters in w, one by one from left
to right if we reach to final state after scanning the whole string, then we can say
the string ‘w’ is “accepted” by the FA(DFA/NFA), otherwise we can say the string ‘w’
is “rejected”.

Acceptance of Language (Set of Strings): Given a language ‘L’, we can determine whether
the language ‘L’ is accepted by the Finite Automata (DFA/NFA) or not.
• Language means set of strings. So, if every string in the language ‘L’ is accepted by
the FA(DFA/NFA), then we can say the language ‘L’ is “accepted” by the
FA(DFA/NFA).

04/02/2024 Department of Computer Science & Engineering, GIT 20


Deterministic Finite Automata(DFA)
Definition: It is a Finite Automata in which from every state on every input symbol
exactly one transition should exist.

DFA consists of 5-tuples M = (Q, ∑, δ, q0 , F), where:

1. Q is a finite set of states.


2. ∑ is a finite set of input symbols, called the alphabet. ∑ is called Sigma.
3. δ is the transition function. δ is called Delta.
Transition Function is defined as δ : Q x ∑  Q
4. q0 is the initial state/starting state from where any input is processed (q0 ∈ Q).
5. F is a set of final state/states (F ⊆ Q).

04/02/2024 Department of Computer Science & Engineering, GIT 21


Design a DFA
Example1: Design a DFA which accept set of all strings over an input alphabet
Σ={a,b}, that start with ‘a’.
Ans: The given language is set of all strings which start with ‘a’.
i.e L = {a, aa, ab, aaa, aab, aba, abb, aabb, aaabbba, …..}
Clearly the language is infinite because there is infinite number of
strings.
Transition Diagram: Where q0 is initial state, q1 is final state, and q2 is dead/trap state.

04/02/2024 Department of Computer Science & Engineering, GIT 22


Design a DFA which accept set of all strings over an input
alphabet Σ={a,b}, that start with ‘a’.

• The idea is very simple, follow the steps below and you will
understand.

1. We know that first input must be ‘a’ and from start state on ‘a’
we should accept so go to final state, so two states are
confirmed: start state and final state i.e q0 and q1.

2. Once we reach final state, we should accept everything that is


why we have a loop on ‘a’ and ‘b’ inputs.

3. And if the first input is something else than ‘a’ then string
should not be accepted. So from start state on ‘b’ we should
go to dead state or trap state, third state is confirmed i.e q2.

4. Once we reach q2, we don’t care whatever comes on state q2


as state q2 now will work as dead state.
04/02/2024 Department of Computer Science & Engineering, GIT 23
Design a DFA which accept set of all strings over an input
alphabet Σ={a,b}, that start with ‘a’.
• Acceptance: Lets take one input string w=abab, and check whether it is
accepted or not by the designed DFA.

1. Start from the initial state i.e q0

2. First input is ‘a’, so from state q0 on input ‘a’, we will go to state q1

3. Second input is b, so from present state q1 on input ‘b’, we will go to


state q1 itself

4. Third input is a, so from state q1 on input ‘a’, we will go to state q1 itself

5. Fourth input is b(string is completed), so from state q1 on input ‘b’, we


will go to state q1 itself(final state)

• After end of the string w=abab, we are at final state, so string is accepted.

04/02/2024 Department of Computer Science & Engineering, GIT 24


Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0.

Design a FA with ∑ = {0, 1} accepts the only input 101.

Design FA with ∑ = {0, 1} accepts the set of all strings with three consecutive 0’s.

Design FA with ∑ = {0, 1} accepts even number of 0's and even number of 1’s.

Construct a DFA with ∑ = {a, b} that accepts the only input “aaab”.
Construct DFA, which accept all the string over alphabets ∑ {0,1} where each
string contains “00”.
04/02/2024 Department of Computer Science & Engineering, GIT 25
Non-Deterministic Finite Automata(NFA)
• Definition: The term non-determinism means from a given state and on an input
symbol, the transition function δ may lead to a set of states which is subset of Q.

• i.e., A state have more than one transition on the same input symbol.

DFA consists of 5-tuples M = (Q, ∑, δ, q0 , F), where:

1. Q is a finite set of states.


2. ∑ is a finite set of input symbols, called the alphabet. ∑ is called Sigma.
3. δ is the transition function that is defined as 𝛿 : Q × ∑  2Q
4. q0 is the initial state/starting state from where any input is processed (q0 ∈ Q).
5. F is a set of final state/states (F ⊆ Q).

04/02/2024 Department of Computer Science & Engineering, GIT 26


Non-Deterministic Finite Automata(NFA)
Acceptance of String by NFA:
 In DFA, string is said to be accepted if finite control stops at a final state after
processing entire string.
 Since there is only one path, one can confirm for acceptance.
 In case of NFA, for a string ‘w’ there may be multiple paths exist for the given
string and some paths may lead to final state and some may not.
 If we find a path(at least one) which leads to a final state after processing entire
string then we can say the string ‘w’ is accepted by NFA.

04/02/2024 Department of Computer Science & Engineering, GIT 27


Design an NFA
Example1: Design an NFA which accept set of all strings over an input alphabet Σ={a,b}, that start
with ‘a’ and end with ‘b’.

Ans: The given language is set of all strings over an alphabet Σ={a,b}, that start with ‘a’ and end with ‘b’.
• i.e L = {ab, aab, abb, aaab, aabb, abab, abbb, aaabb, aababbab, ………...}

• Clearly the language is infinite because there is infinite number of strings.


• Transition Diagram: Where q0 is initial state, q1 is intermediate state, and q2 is final state.

04/02/2024 Department of Computer Science & Engineering, GIT 28


Design an NFA which accept set of all strings over an
input alphabet Σ={a,b}, that start with ‘a’ and end with ‘b’.

• The idea is very simple, follow the steps below and you will understand.

1. We know that first input must be ‘a’ and from start state q0 on ‘a’ we should not accept because we must
see last input ‘b’, so go to q1(intermediate state).

2. We know that last input must be ‘b’, so from q1 on ‘b’ we must accept so go to final state i.e q2.

3. We should accept everything in between first input ‘a’ and last input ‘b’, that is why we have a loop on ‘a’
and ‘b’ inputs at q1 state.

4. And if the first input is something else than ‘a’ we don’t care, so no transition on input ‘b’ from q0 state.
And also, we don’t care about transitions on inputs ‘a’ and ‘b’ from q2 state.
04/02/2024 Department of Computer Science & Engineering, GIT 29
Limitations of NFA

Limitations of NFA:

 It cannot be implemented because of non-deterministic in nature. i.e from the state on an input
symbol, there may be multiple transitions.
 To overcome this, it must be converted back to Deterministic FA which is implementable.

Note:

1: Every DFA is NFA but vice-versa is not true.


The above property is true because the δ of DFA is ⊆ δ of NFA
As δ : Q X Σ -> 2Q ⊇ Q X Σ -> Q

2: We do not have dead states in NFA.


3: NFA and DFA both are equivalent in [Link] is because "Every DFA is NFA" and "We can
convert NFA to DFA"

04/02/2024 Department of Computer Science & Engineering, GIT 30


ε-NFA (NFA with ε-moves)
 Transition from one state to another without reading any input symbol is known as ε-moves. i.e transition
function is 𝛿(q, ε)=q

 However, to distribute the complexity of the design or enhance understanding of the reader, the NFA can be
extended by including transitions on ‘ε’

 Formally NFA with ε-moves is a 5-tuple machine M=(Q,∑, 𝛿, q0, F), where
1. Q- finite no of states
2. ∑-finite no of input symbols
3. 𝛿-transition function Q × ∑ U { ε } → 2Q

• i.e., 𝛿( q , a ) consisting of a state p such that there is a transition labeled ‘a’ from q to p, where a is
either ε or input symbol
4. q0-initial state
5. F-final state
04/02/2024 Department of Computer Science & Engineering, GIT 31
Design ε-NFA
• Design a ε-NFA (NFA with ε-moves) which accept
set of all strings over an input alphabet Σ={0,1, 2},
that any number of 0’s followed by any number of
1’s followed by any number of 2’s.

• Ans: The given language is set of all strings over an


alphabet ={0,1, 2}, that any number of 0’s followed
by any number of 1’s followed by any number of 2’s.
• i.e L = { ε , 0, 1, 2, 00, 01, 02, 11, 12, 22, 011,
012, 0012, ……..000111122,…...}
• Clearly the language is infinite because there is
infinite number of strings.

04/02/2024 Department of Computer Science & Engineering, GIT 32


THANK YOU

Department of Computer Science & Engineering, GIT


04/02/2024 33

You might also like