Slide#02 Week # 04, 05 TAFL
Slide#02 Week # 04, 05 TAFL
9/29/2024 2
Finite Automata(FA)
FORMAL is FA
DEFINITION OF the simplest machine to
recognize patterns. It is used to characterize a
Regular Language, for example: /baa+!/.
9/29/2024 3
FORMAL DEFINITION OF FA
9/29/2024 7
FORMAL DEFINITION OF FA
9/29/2024 8
DETERMINISTIC FINITE AUTOMATA (DFA)
• Deterministic refers to the uniqueness of the computation. In the
DFA, the machine goes to one state only for a particular input
character. DFA does not accept the null move.
• DFA consists of 5 tuples {Q, ∑, q, F, δ}.
• Q : set of all states.
• ∑ : set of input symbols. ( Symbols which machine takes as input )
• q : Initial state. ( Starting state of a machine )
• F : set of final state.
• δ : Transition Function = δ: Q x ∑→Q 9/29/2024 9
DETERMINISTIC FINITE AUTOMATA (DFA)
• In a DFA, for a particular input character, the machine goes to one state
only. A transition function is defined on every state for every input symbol
and the null (or ε) move is not allowed,
• i.e., DFA cannot change state without any input character.
For example,
• DFA with ∑ = {0, 1} accepts all strings ending with 0.
• One important thing to note is, there can be many possibleDFAs for a
pattern. A DFA with minimum number of states is generally preferred.
9/29/2024 10
SOME NOTATIONS THAT ARE USED IN THE
TRANSITION DIAGRAM:
9/29/2024 13
PROBLEM-01: • Draw a DFA for the language accepting strings
starting with ‘ab’ over input alphabets ∑ = {a, b}
• Step-01:
• All strings of the language starts with substring “ab”.
• So, length of substring = 2.
• Thus, Minimum number of states required in the DFA = 2 + 2 = 4.
• It suggests that minimized DFA will have 4 states.
9/29/2024 16
PROBLEM-01:
• Step-02:
• We will construct DFA for the following strings-
• ab
• aba
• abab
• Step-01:
• All strings of the language starts with substring “a”.
• So, length of substring = 1.
• Thus, Minimum number of states required in the DFA = 1 + 2 = 3.
• It suggests that minimized DFA will have 3 states.
9/29/2024 20
PROBLEM-04:
• Step-02: We will construct DFA for the following strings-
•a
• aa
• aab
• aababb
• Step-03:
9/29/2024 21
EXAMPLE 5:
9/29/2024 23
EXAMPLE 7: (REQUIRED DEAD STATE)
• Design a FA with ∑ = {0, 1} accepts those string
which starts with 1 and ends with 0..
• In state q1, if we read 1, we will be in state q1, but if we read 0 at state q1,
we will reach to state q2 which is the final state. In state q2, if we read
either 0 or 1, we will go to q2 state or q1 state respectively. Note that if the
input ends with 0, it will be in the final state. 9/29/2024 24
EXAMPLE 8: (REQUIRED DEAD STATE)
• Design a FA with ∑ = {0, 1} accepts the only input 101...
• Inthe given solution, we can see that only input 101 will be
accepted. Hence, for input 101, there is no other path shown for
other input.
9/29/2024 25
• Design FA with ∑ = {0, 1} accepts even number of 0's and
EXAMPLE 9: even number of 1’s.
• Here q0 is a start state and the final state also. Note carefully
that a symmetry of 0's and 1's is maintained. We can
associate meanings to each state as:
9/29/2024 26
EXAMPLE 10:
(POSSIBILITY OF ONE TRANSITION STATE IS MISSING FROM STATE Q2)
• The stages q0, q1, q2 are the final states. The DFA will generate the strings that
do not contain consecutive 1's like 10, 110, 101,..... etc. 9/29/2024 28
EXAMPLE 12:
Designing Finite Automata from Regular Expression (Set 1)
• Even number of a’s : The regular expression for even number of a’s is (b|ab*ab*)*:
• The above automata will accept all strings which have even number of a’s. For zero a’s, it
will be in q0 which is final state. For one ‘a’, it will go from q0 to q1 and the string will not be
accepted. For two a’s at any positions, it will go from q0 to q1 for 1st ‘a’ and q1 to q0 for
second ‘a’. So, it will accept all strings with even number of a’s. 9/29/2024 29
EXAMPLE 13:
String with ‘ab’ as substring : The regular expression for
strings with ‘ab’ as substring is (a|b)*ab(a|b)*.
• Theabove automata will accept all string which have ‘ab’ as substring. The
automata will remain in initial state q0 for b’s. It will move to q1 after reading ‘a’
and remain in same state for all ‘a’ afterwards. Then it will move to q2 if ‘b’ is
read. That means, the string has read ‘ab’ as substring if it reaches 9/29/2024
q2. 30
EXAMPLE 14:
Binary numbers divisible by 3 : The regular expression for binary numbers
which are divisible by three is (0|1(01*0)*1)*.
• The examples of binary number divisible by 3 are 0, 011, 110, 1001, 1100, 1111, 10010 etc.
• The above automata will accept all binary numbers divisible by 3. For 1001, the
automata will go from q0 to q1, then q1 to q2, then q2 to q1 and finally q2 to q0,
hence accepted. For 0111, the automata will go from q0 to q0, then q0 to q1, then
q1 to q0 and finally q0 to q1, hence rejected.
9/29/2024 31
EXAMPLE 15:
What will be the minimum number of states for strings
with odd number of a’s?
9/29/2024 39
WHAT IS NFA?
9/29/2024 40
NON-DETERMINISTIC FINITE AUTOMATA
DFA
• In DFA, given the current state we know what the next state will be.
• It has only one unique next state
• It has no choices or randomness
• It is simple and easy to design.
NFA
• In NFA, given the current state there could be multiple next states.
• The next state may be chosen at random.
• All next state maybe chosen in parallel.
9/29/2024 41
SOME IMPORTANT POINTS ABOUT DFA AND NFA:
1. Both NFA and DFA have same power
2. Each NFA can be translated into a DFA ( ).
Every NFA can be converted into its equivalent DFA
3. For any regular language, both DFA and NFA can be constructed.
4. There exists an equivalent DFA corresponding to every NFA.
5. Every DFA is a NFA but every NFA is not a DFA.
• where-
• Q = finite set of states
• ∑ = non-empty finite set of symbols called as input alphabets
• δ : Q x ∑ → 2Q is a total function called as transition function
• q0 ∈ Q is the initial state
• F ⊆ Q is a set of final states
9/29/2024 44
DEAD STATE / TRAP STATE
• What is a dead state in automata?
• We need to start a machine (DFA) to read a string. If machine
reached successfully till its final string accepting state, then we
say that string is accepted by our machine
9/29/2024 45
DEAD STATE
• Note:
• Dead state may be required in DFA.
• Dead state is not required in NFA.
9/29/2024 46
DEAD CONFIGURATION OR TRAP STATE-
9/29/2024 47
NONDETERMINISTIC FINITE AUTOMATA(NFA)
In the transition function (δ:Qx∑→2Q), any input that includes null (or ε), NFA can
go to any number of states..
For example, in NFA, if any path for an input string leads to a final state, then
the input string accepted.
For example, in following NFA, there are multiple paths for input string “00”. Since,
one of the paths leads to a final state, “00” is accepted by following NFA.
9/29/2024 48
LET’S COMPARISON B/W DFA & NFA
HOW A DFA OPERATES:
3. The possible input strings that can be generated are 10, 11, 110, 101, 111...,
that means all string starts with 1.
9/29/2024 51
1.THERE
Example IS 2:A: DESCRIPTION OF HOW
NFA with ∑ = {0, 1} accepts Astarting
all strings NDFAwith 1.
2.OPERATES:
Solution: The NFA can be represented using a transition graph. In the above
diagram, the machine initially is in start state q0 then on receiving input 1 the
machine changes its state to q1. From q1 on receiving input 0, 1 the machine
changes its state to q1.
3. The possible input string that can be generated is 10, 11, 110, 101, 111...,
that means all string starts with 1.
9/29/2024 52
EXAMPLE 1:
9/29/2024 53
EXAMPLE 2:
9/29/2024 54
EXAMPLE 3:
• Solution:
9/29/2024 55
EXAMPLE 4:
• Design an NFA with ∑ = {0, 1} in which double '1' is followed by double '0’.
9/29/2024 56
Example Of Non-deterministic Finite Automata
Without Epsilon-
• The above NFA can be defined in form of five tuples as- Transition function δ
• { {A, B, C, D, E, F}, {a, b, c}, δ, A, {D, F} } is defined as-
•δ (A, a) = B
• where- •δ (A, a) = E
• {A, B, C, D, E, F} refers to the set of states
•δ (B, b) = C
• {a, b, c} refers to the set of input alphabets
• δ refers to the transition function •δ (C, c) = D
• A refers to the initial state •δ (E, b) = F
• {D, F} refers to the set of final states •δ (F, c) = E
9/29/2024 57
Example Of Non-deterministic Finite
Automata Without Epsilon-
Transition function δ is
defined as-
•δ (A, a) = B
•δ (A, a) = E
•δ (B, b) = C
•δ (C, c) = D
•δ (E, b) = F
•δ (F, c) = E 9/29/2024 58
Example Of Non-deterministic Finite Automata
With Epsilon-
• The above NFA can be defined in form of five tuples as-
• { {q0, q1, q2}, {a, b}, δ, q0, {q2 or q3} }
• where- Draw a Finite Automata which accept the
string “ab”.
• {q0, q1, q2} refers to the set of states
• {a, b} refers to the set of input alphabets
• δ refers to the transition function
• q0 refers to the initial state
• {q2 or q3} refers to the set of final states
9/29/2024 59
Equivalence Of DFA And NFA-
Consider A Language L(M) = { (10)n : N >= 0/ Epsilon }
• Equivalent NFA for the language L(M) is-
9/29/2024 63