0% found this document useful (0 votes)
36 views48 pages

Slide#02 Week # 04, 05 TAFL

Uploaded by

bfdfag
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)
36 views48 pages

Slide#02 Week # 04, 05 TAFL

Uploaded by

bfdfag
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/ 48

BS COURSE

THEORY OF AUTOMATA AND FORMAL LANGUAGES.


CT-364

THEORY OF AUTOMATA & FORMAL


LANGUAGES
Slide # : 04-5 week
Muhammad Abbas
1
FORMAL DEFINITION OF FA

Finite Automata(FA) is the simplest machine to


recognize patterns.

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

• The above figure shows the following features of automata:


– Input
– Output
– States of automata
– State relation
– Output relation
9/29/2024 4
FORMAL DEFINITION OF FA

A finite automaton is a collection of 5-tuple (Q, ∑, δ, q0, F),


where:
Q: finite set of states
∑: finite set of the input symbol
q0: initial state
F: final state
δ: Transition function
9/29/2024 5
FORMAL DEFINITION OF FA (CONCEPT OF PROPER ABSTRACT MODEL OF FA)

Finite Automata Representation:


Input Tape: A linear tape divided into cells, with each cell
containing one input symbol.
Finite Control: Determines the next state based on the input
symbol received from the tape.
Tape Reader: Reads one cell at a time, moving left to right,
processing a single input symbol at each step.
9/29/2024 6
•FA isOF
TYPES characterized
AUTOMATA: into two types:
• DFA (deterministic finite automata)
• NFA (non-deterministic finite automata)

9/29/2024 7
FORMAL DEFINITION OF FA

Formal specification of machine is { Q, ∑, q, F, δ }.

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}

• Regular expression for the given language = ab(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-03: The required DFA is-


9/29/2024 17
PROBLEM-03:
• Draw a DFA for the language accepting strings starting with
‘101’ over input alphabets ∑ = {0, 1}

• Regular expression for the given language = 101(0 + 1)*


• Step-01:
• All strings of the language starts with substring “101”.
• So, length of substring = 3.
• Thus, Minimum number of states required in the DFA = 3 + 2 = 5.
• It suggests that minimized DFA will have 5 states.
9/29/2024 18
PROBLEM-03:

• Step-02: We will construct DFA for the following strings-


• 101
• 1011
• 10110
• 101101

• Step-03: The required DFA is-


9/29/2024 19
PROBLEM-04:
• Draw a DFA for the language accepting strings starting with ‘a’ over input
alphabets ∑ = {a, b}

• R.E for the given language = a(a + b)*

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

• DFA with ∑ = {0, 1} accepts all starting with 0.


• In the above diagram, we can see that on given 0 as input to DFA in
state q0 the DFA changes state to q1 and always go to final state q1
on starting input 0. It can accept 00, 01, 000, 001....etc. It can't accept
any string which starts with 1, because it will never go to final state on a
string starting with 1.
9/29/2024 22
EXAMPLE 6:

• DFA with ∑ = {0, 1} accepts all ending with 0.


• In the above diagram, we can see that on given 0 as input to DFA in state
q0, the DFA changes state to q1. It can accept any string which ends with
0 like 00, 10, 110, 100....etc. It can't accept any string which ends with 1,
because it will never go to the final state q1 on 1 input, so the string
ending with 1, will not be accepted or will be rejected.

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:

• q0: state of even number of 0's and even number of 1's.


• q1: state of odd number of 0's and even number of 1's.
• q2: state of odd number of 0's and odd number of 1's.
• q3: state of even number of 0's and odd number of 1's.

9/29/2024 26
EXAMPLE 10:
(POSSIBILITY OF ONE TRANSITION STATE IS MISSING FROM STATE Q2)

• Design FA with ∑ = {0, 1} accepts the set of all strings


with three consecutive 0’s. In which 0 always appears in
a clump of 3.

• The strings that will be generated for this particular


languages are 000, 0001, 1000, 10001, .... The transition
graph is as above.
9/29/2024 27
EXAMPLE 11:
• Design a DFA L(M) = {w | w ε {0, 1}*} and W is a
string that does not contain consecutive 1’s.
• When three consecutive 1's occur the DFA will be:

• Here two consecutive 1's or single 1 is acceptable, hence.

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

• Solution : The regular expression for odd number of


a is b*ab*(ab*ab*)*.
9/29/2024 32
NON-DETERMINISTIC
FINITE AUTOMATA

9/29/2024 39
WHAT IS NFA?

•The term non-deterministic in NFA means that the


NFA can exist in, or can make the transition to,
many different states at the same point of time
for given inputs.

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.

6. There can be multiple final states in both DFA and NFA.

7. NFA is more of a theoretical concept.


8. DFA is used in Lexical Analysis in Compiler. 9/29/2024 43
NONDETERMINISTIC FINITE AUTOMATA(NFA), (CONTINUE…)

• NFA is defined by the five tuple = (Q, ∑, δ, q0, F)

• 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

• But if we reach on a state where machine can’t move further to


its final state, then this state is called dead state. Dead state is
also known as dummy state.

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-

In Non-Deterministic Finite Automata,

–The result of a transition function may be empty.


–In such a case, automata gets stopped forcefully after
entering that configuration.
–This type of configuration is known as dead configuration.
–The string gets rejected after entering the dead configuration.

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:

1. Example: DFA with ∑ = {0, 1} accepts all strings starting with 1.


2. Solution: The finite automata 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 q0 on receiving 0, the machine changes
its state to q2, which is the dead state. From q1 on receiving input 0, 1 the
machine changes its state to q1, which is the final state.

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:

• NFA with ∑ = {0, 1} accepts all strings start with 01.


• Solution:

9/29/2024 53
EXAMPLE 2:

• NFA with ∑ = {0, 1} and accept all string of length


atleast 2.
• Solution:

9/29/2024 54
EXAMPLE 3:

• Design an NFA with ∑ = {0, 1} accepts all string


ending with 01.

• Solution:

9/29/2024 55
EXAMPLE 4:
• Design an NFA with ∑ = {0, 1} in which double '1' is followed by double '0’.

• Nowbefore double 1, there can be any string of 0 and 1. Similarly, after


double 0, there can be any string of 0 and 1.
• Hence the NFA becomes:

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-

• Equivalent DFA for the language L(M) is-

• Both the above automata accepts the same language L(M).


• Thus, both are equal in power. 9/29/2024 61
THANK YOU
END 🔚 OF 4-5TH WEEK LECTURES

9/29/2024 63

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy