0% found this document useful (0 votes)
8 views56 pages

02_finite_automata

The document discusses finite automata, focusing on deterministic finite acceptors (DFAs) and nondeterministic finite acceptors (NFAs), including their definitions, properties, and examples. It explains the equivalence between DFAs and NFAs, stating that both types of automata can accept the same languages, thus demonstrating their equal power. The document also covers concepts such as transition functions, language acceptance, and the significance of nondeterminism in computational models.

Uploaded by

ghmpersonal
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)
8 views56 pages

02_finite_automata

The document discusses finite automata, focusing on deterministic finite acceptors (DFAs) and nondeterministic finite acceptors (NFAs), including their definitions, properties, and examples. It explains the equivalence between DFAs and NFAs, stating that both types of automata can accept the same languages, thus demonstrating their equal power. The document also covers concepts such as transition functions, language acceptance, and the significance of nondeterminism in computational models.

Uploaded by

ghmpersonal
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/ 56

Finite Automata

1
Topics

• What is the deterministic finite accepter?


• Its connection w/ regular language.
• What is the non-deterministic finite accepter?
• Discuss the equivalence between the two accepters.

2
Deterministic Finite Accepters

3
Deterministic Finite Accepters
Definition 2.1

• A Deterministic Finite Accepter (DFA) is defined by the quintuple


• M = (Q, Σ, δ, q0, F)
• where
• Q is a finite set of internal states,
• Σ is a finite set of symbols called the input alphabet,
• δ : Q × Σ → Q is a total function called the transition function,
• q0 ∈ Q is the initial state,
• F ⊆ Q is a set of final states.
4
Deterministic Finite Accepters
Example 2.1
Figure 2.1 Transition Graph
• The graph represents the dfa
• M = ({q0, q1, q2}, {0,1}, δ, q0, {q1}),
• where δ is given by Initial Vertex
Final Vertices
• δ(q0,0) = q0, δ(q0,1) = q1,
0101?
• δ(q1,0) = q0, δ(q1,1) = q2,
00111?
• δ(q2,0) = q2, δ(q2,1) = q1. 00011?

5
Deterministic Finite Accepters
Extended Transition Function

• δ* : Q × Σ* → Q.
• Transition is processed on strings, rather than a single symbol.
• e.g.)
• If δ(q0, a) = q1, δ(q1, b) = q2, then δ*(q0, ab) = q2.
• We can define it recursively.
• δ*(q, λ) = q, δ*(q, wa) = δ(δ*(q, w), a),
• ∀q, q ∈ Q, w ∈ Σ*, a ∈ Σ.
6
Languages and DFAs
Definition 2.2

• The language accepted by a dfa M = (Q, Σ, δ, q0, F) is the set of all strings
on Σ accepted by M.

• L(M) = {w ∈ Σ* : δ*(q0, w) ∈ F}.


• Nonacceptance
c
• L(M) = {w ∈ Σ* : δ*(q0, w) ∉ F}.
• Is this string in this language? = Does this string put the DFA in a finial state?

7
Languages and DFAs Figure 2.2

Example 2.2

• Figure 2.2 show the dfa accepts the following language. Trap State
n
• L = {a b : n ≥ 0}.
• M = ({q0, q1, q2}, {a, b}, δ, q0, {q1}), where δ is given by
• δ(q0, a) = q0, δ(q0, b) = q1,
• δ(q1, a) = q2, δ(q1, b) = q2,
• δ(q2, a) = q2, δ(q2, b) = q2. ← Why do we need these?
8
Languages and DFAs
Theorem 2.1

• Let M = (Q, Σ, δ, q0, F) be a DFA, and let GM be its associated transition


graph.
+
• Then for every qi, qj ∈ Q and w ∈ Σ ,
• δ*(qi, w) = qj iff. there is in GM a walk with label w from qi to qj.
• A walk with label w : suppose w = w1w2⋯wn.
• Then the walk is a sequence of edges labeled w1, w2, ⋯, wn.

9
Languages and DFAs
Theorem 2.1

• Proof.
• Assume that the claim is true for all strings v with | v | ≤ n. (1)
• Consider then any w of length n + 1 can be written as
• w = va.
• Suppose that δ*(qi, v) = qk.
• Since | v | = n and (1), there must be a walk in GM labeled v from qi to qk. (2)

10
Languages and DFAs
Theorem 2.1

• If δ*(qi, w) = qj, then M must have a transition δ(qk, a) = qj.


• This means that GM has an edge (qk, qj) w/ label a.
• Therefore, we can extend the walk in (2) with this edge,
• obtaining a walk in GM labeled va = w from qi to qj.
• The result is true for n = 1 (single edges), we can claim by induction that,
+
• for every w ∈ Σ , δ*(qi, w) = qj implies that there is a walk in GM from qi to qj
labeled w, and vice versa.
11
Languages and DFAs Figure 2.2

Table notation for transitions

• Figure 2.3 is equivalent to Figure


2.2.

• Row labels are current states. Figure 2.3

• Column labels represent the


current input symbols.

• Then each cell shows the next


state for the current state and
the input symbol.

12
Finding DFA
Example 2.4

• Find a dfa that accepts all the strings on {0, 1}, except those containing the
substring 001.

• To detect 001, checking the current input symbol is not enough.


• e.g.) 01 is OK when it comes after 1, but not OK with 0, which makes 001.
• We can choose internal state names, so we will employ more memorable
names to keep track of strings.

13
Figure 2.5

Finding DFA
Example 2.4

• Each internal state name indicates how close a substring so far to 001.
• At first, it starts with λ, and as long as the input symbol is 1, it stays there.
• Once 0 is processed, it moves to 0.
• The next 0 makes it move to the next state 00.
• Then it moves to 001 with a consecutive 1.
• For any other input symbols, it moves to other internal states accordingly.
• Note that 001 is a trap state, and all other states are final states.
14
Regular Languages
Definition 2.3

• A language L is called regular, if and only if there exists some deterministic


finite accepter M such that

• L = L(M).
• If we consider all possible finite automata, we get a set of languages
accepted by them.

• Such a set of languages is called a family.


• We will discuss about the structure and properties of such language families.

15
Regular Languages
Example 2.5

• Show that the language Figure 2.6

• L = {awa : w ∈ {a, b}*} is regular.


• By Definition 2.3, all we have to do is finding a
dfa which accepts the language.

• The first symbol must be a.


• The last symbol must be a too.
• If an input symbol is not acceptable, it leads
the dfa to a trap state.
16
Regular Languages
Example 2.6

2
• Let L be the language in Example 2.5. Show that L is regular.
2
• L = {aw1aaw2a : w1, w2 ∈ {a, b}*}
Figure 2.7

17
Non-deterministic Finite
Accepters

18
Nondeterministic Finite Automata
Definition 2.4

• A Nondeterministic Finite Accepter (NFA) is defined by the quintuple


• M = (Q, Σ, δ, q0, F)
• where Q, Σ, q0, F are defined as for DFA, but
Q
• δ : Q × (Σ ∪ {λ}) → 2 .
• Mainly the nondeterministic property comes from the transition function.

19
Nondeterministic Finite Automata
Definition 2.4

Q
• δ : Q × (Σ ∪ {λ}) → 2 .
Q
• What’s 2 ?
Q
• Q = {q0, q1}, then 2 = {Ø, {q0}, {q1}, {q0, q1}}.
• There are three major differences between DFAs and NFAs.
• Diff.1: The next state can be represented as a set of internal states.
• δ(q1, a) = {q0, q1}

20
Nondeterministic Finite Automata
Definition 2.4

Q
• δ : Q × (Σ ∪ {λ}) → 2 .
• Diff. 2: an NFA also allows to have λ as its argument, which means that it can
change states w/o consuming input symbol.

• In DFA, when a transition happens, it always moves to the right on the input
string.

• Now an NFA can stay at the same location on the input string while changing its
states.

• Diff. 3: It’s possible that δ(qi, a) is empty, which means that there is no transition for
a certain situation.
21
Nondeterministic Finite Automata
Example 2.7

Figure 2.8

22
Nondeterministic Finite Automata
Example 2.8
Figure 2.9
• q1 has two transitions for input 0.
• There exists a λ-transition for q0.
• δ(q0,0), δ(q2,0), δ(q2,1) are not defined.
• δ(q2,0) = Ø.
• The automaton accepts λ, 1010, 101010, …, but not 110 and 10100.
• How about 10? - We can choose an appropriate edge to accept it.
23
The Extended Transition Function
Definition 2.5

• For an NFA, the extended transition function is defined so that


• δ*(qi, w) contains qj if and only if there is a walk in the transition graph
from qi to qj labeled w.

• This holds for all qi, qj ∈ Q, and w ∈ Σ*.


• It’s very similar to the extended transition function for DFAs.
• The definition is not quite formal, but enough to explain the concept.

24
The Extended Transition Function
Example 2.9 Figure 2.10

• Figure 2.10 represents an NFA.


• Note that there are λ-transitions and undefined transitions.
• Finding δ*(q1, a) and δ*(q2, λ) - a is a string of length 1.
• δ*(q1, a) = {q0, q1, q2}.
• δ*(q2, λ) = {q0, q2}.
• How about δ*(q2, aa) = {q0, q1, q2}?
25
The Length of a Walk for a String

• Given a string w, how long can a walk labeled w be?


• If there is any walk labeled w between two vertices vi and vj,
• then there must be some walk labeled w of length no more than
Λ + (1 + Λ) | w | .
• where Λ is the number of λ-edges in the graph.
• Proof: If there is any walk labeled w between two vertices vi and vj, then its
length n cannot be less than | w | .
26
The Length of a Walk for a String

• If n > | w | , then the walk must contain λ-transitions.


• We can consider the situation that λ-transitions are separated by each symbol of w.
Λ Λ Λ Λ
• w = a1a2…an = λ a1λ a2…λ anλ
• Note that we can remove λ-cycles without affecting the labels of the walk.
• So the number of λ-transitions is at most ( | w | + 1) × Λ, and we need to add | w |
for actual edges to cover w.

• ( | w | + 1) × Λ + | w | = Λ + (1 + Λ) | w | .

27
Find a Walk for a String

• With the previous observation, we can consider a method to compute


δ*(qi, w).

• We can list up all walks of length at most Λ + (1 + Λ) | w | starts at qi.


• Then simply select walks from them which are labeled | w | .
• The terminating vertices - the final vertices at the end of the walks - are the
elements of the set δ*(qi, w).

28
Languages and NFAs
Definition 2.6

• The language L accepted by an nfa M = (Q, Σ, δ, q0, F) is defined as the set


of all strings accepted in the above sense.

• Formally,
• L(M) = {w ∈ Σ* : δ*(q0, w) ∩ F ≠ Ø}.
• L consists of all strings w for which there is a walk labeled w from the initial
vertex to one of the final vertices.

29
Languages and NFAs
Example 2.10
Figure 2.9

• What is the language accepted by the automaton in Figure 2.9?


• The only final state is q0.
• It’s easy to see that it can be only reached after repeating 10.
n
• L = {(10) : n ≥ 0}.
• What happens when w = 110 is given?
• Dead configuration - current situation is undefined.
• δ*(q0,110) = Ø
30
Why Nondeterminism?

• Digital computers are completely deterministic.


• Their state at any time is uniquely predictable from the input and initial
state.

• May not be entirely true for quantum computers.


• Nondeterministic machines can serve as models of search-and-backtrack
algorithms.

• It can simulate multiple choices at the current state.

31
Why Nondeterminism?

• Nondeterminism is sometimes helpful in solving problems easily.


• Uniquely decided next state can work as constraints.
• Nondeterminism avoids such inconvenience quite naturally.
• It’s an effective mechanism for complicated language description.
• e.g.) S → aSb | λ.
• Certain theoretical results are more easily explained with NFAs than DFAs.

32
Equivalence of DFA and NFA

33
Equivalence of Automata
Definition 2.7

• Two finite accepters, M1 and M2, are said to be equivalent if


• L(M1) = L(M2),
• that is, if they both accept the same language.

34
Equivalence of Automata
Example 2.11 Figure 2.11

• The dfa shown in Figure 2.11 is


equivalent to the nfa in Figure 2.9,

• since they both accept the


language
n
• {(10) : n ≥ 0}.
• q2 is a trap state in both accepters.
• Note that the labels of the edges Figure 2.9
from q0 and q2 are different.

35
Which is More Powerful?

• An automaton is more powerful than other automata if it can achieve


something that cannot be done by the others.

• Are NFAs more powerful than DFAs?


• We can convert a DFA to an NFA.
• How about converting NFAs to DFAs?
• We employed non-determinism for NFAs, so some NFAs might not be
represented as DFAs.

• Is this argument true?


36
No, it's not!

• Actually, the classes of DFAs and NFAs are equally powerful.


• We support this argument by giving a way to convert any NFA to a DFA.
• Here is the trick.
• If an NFA has multiple next states after processing an input symbol, put them
as one state in a corresponding DFA.

• e.g.) if a set of possible state after reading w is {q0, ⋯, qk} in an NFA, then we
label the corresponding next state as "{q0, ⋯, qk}".

• There will be more states in the DFA, but still it is finite.


37
Conversion
Example 2.12 Figure 2.12

• Convert the NFA in Figure 2.12 to


an equivalent DFA.

• In the DFA, labels of states are sets


consist of states in the NFA.

• Note that we need to add all other


transitions unspecified in the NFA to
the DFA.

• Do they accept the same language?


• i.e., are they equivalent?
Figure 2.13

38
Equivalence of NFAs and DFAs
Theorem 2.2

• Let L be the language accepted by a nondeterministic finite accepter


MN = (QN, Σ, δN, q0, FN ).

• Then there exists a deterministic finite accepter MD = (QD, Σ, δD, {q0}, FD),
such that

• L = L(MD).

39
Equivalence of NFAs and DFAs
Theorem 2.2

• Proof: Given MN, we use the procedure NFA-to-DFA to construct the


transition graph GD for MD.

• Procedure: NFA-to-DFA
1. Create a graph GD with vertex {q0}. Identify this vertex as the initial
vertex.

2. Repeat the following steps until no more edges are missing.

40
Equivalence of NFAs and DFAs
Theorem 2.2

• Take any vertex {qi, qj, ⋯, qk} of GD that has no outgoing edge for some
a ∈ Σ.

• Compute δ*(q
N i
, a), δ*(q
N j
, a), ⋯, δ*(q
N k
, a) .

• If δ* (q
N i
, a) ∪ δ*(q
N j
, a) ∪ , ⋯ ∪ δ*(q
N k
, a) = {q ,
l mq , ⋯, qn} ,

• create a vertex for GD labeled {ql, qm, ⋯, qn} if it does not exist.
• Add to GD an edge from {qi, qj, ⋯, qk} to {ql, qm, ⋯, qn} and label it with a.

41
Equivalence of NFAs and DFAs
Theorem 2.2

3. Every state of GD whose label contains any qf ∈ FN is identified as a final


vertex.

4. If MN accepts λ, the vertex {q0} in GD is also made a final vertex.

• This procedure always terminates.


|QM|
• GD has at most 2 | Σ | edges.

42
Equivalence of NFAs and DFAs
Theorem 2.2

• The procedure also gives the correct DFA.


• (Inductive Assumption) Assume that for every v of length less than or equal to n
• the presence in GN of a walk labeled v from q0 to qi implies that,
• in GD, there is a walk labeled v from {q0} to Qi = {⋯, qi, ⋯}.
• Consider now any w = va and look at a walk in GN labeled w from q0 to ql.
• There must be a walk labeled v from q0 to qi and an edge (or edges) labeled a
from qi to ql.
43
Equivalence of NFAs and DFAs
Theorem 2.2

• By the inductive assumption, in GD there will be a walk labeled v from {q0} to


Qi.

• By construction, there will be an edge from Qi to some state whose label


contains ql.

• Thus, the inductive assumption holds for all strings of length n + 1.


• Since it is true for n = 1, it is true for all n.

44
Equivalence of NFAs and DFAs
Theorem 2.2

• Whenever δ* (q
N 0
, w) contains a final state qf, so does the label of δ* (q
D 0
, w) .

• When we reverse the argument, it shows that


• if the label of δ*
D
(q0 , w) contains qf, so must δ*
N
(q0 , w) .

45
Equivalence of NFAs and DFAs
Figure 2.14
Example 2.13

• Convert the NFA in Figure 2.14 into an


equivalent deterministic machine.

• Σ = {0,1}.
• We are drawing GD.
• Take any vertex from GD w/o having 0 or
1.

• Add an edge for 0 or 1, as well as a new


required vertex.

• Once it is done, mark all final states


containing vertices.

46
Distinguishable States
Definition 2.8

• Two states p and q of a DFA are called indistinguishable if


• ∀w, w ∈ Σ*,
• δ*(p, w) ∈ F implies δ*(q, w) ∈ F, and
• δ*(p, w) ∉ F implies δ*(q, w) ∉ F.
• If there exists some string w ∈ Σ* s.t.
• δ*(p, w) ∈ F and δ*(q, w) ∉ F, or vice versa,
• then the states p and q are said to be distinguishable by a string w.
47
Distinguishable States Figure 2.17

Example 2.14

• The two DFAs in Figure 2.17 (a)


and (b) are equivalent.

• State q5 is useless.
• States q1, q2 and q3, q4 are
indistinguishable.

• Figure 2.17 (b) combines those


states into one.

48
Reducing States
Mark Procedure

• A method to find pairs of distinguishable states.


1. Remove all inaccessible states.

2. Consider all pairs of states (p, q): if p ∈ F and q ∉ F, or vice versa, mark the pair as
distinguishable.
3. Repeat the following step until no previously unmarked pairs are marked.

• ∀(p, q) and ∀a, a ∈ Σ, compute δ(p, a) = pa and δ(q, a) = qa.


• If (pa, qa) is marked as distinguishable, mark (p, q) as distinguishable.
• It means that if two states goes to distinguishable states by the same symbol, also mark
them distinguishable.

49
Reducing States
Example 2.15
Figure 2.18

• Applying mark procedure can be


done as partitioning into
equivalence classes.

• Start with
• (a){q0, q1, q3} and (b){q2, q4}.
• (a) ➞ {q0}, {q1, q3}.
• (b) ➞ {q2}, {q4}.

50
Reducing States
Theorem 2.3

• The mark procedure, applied to any dfa M = (Q, Σ, δ, q0, F), terminates and
determines all pairs of distinguishable states.

• Obviously, the procedure terminates - Why?


• It’s also easy to see the marked states are distinguishable - Try to show it.
• Does it find all distinguishable pairs?
• Two states are distinguishable by a string of length n.
• Let n = 0 a basis and use proof by induction.
51
Reducing States
Reduce Procedure

• Once equivalence classes are found, we can use reduce procedure to


construct the minimal dfa.

M ̂ = ( Q ,̂ Σ, δ ,̂ q0 ,̂ F )̂ as follows.
• Given M = (Q, Σ, δ, q0, F), we can construct a reduced dfa

1. Use procedure mark to generate the equivalence classes, say {qi, qj, ⋯, qk}.

M .̂
2. For each set of such indistinguishable states, create a state labeled ij⋯k for

52
Reducing States
Reduce Procedure

3. For each transition rule of M of the form δ(qr, a) = qp,

• Find the sets to which qr and qp belong.


• If qr ∈ {qi, qj, ⋯, qk} and qp ∈ {ql, qm, ⋯, qn},
• add a rule ̂
δ (ij⋯k, a) = lm⋯n to δ .̂
4. The initial state q0 ̂ is that state of M ,̂ whose label includes the 0 (i.e., the class where
q0 belongs).
5. F ̂ is the set of all the states whose label contains i s.t. qi ∈ F.
53
Reducing States
Figure 2.18

Example 2.16

• Figure 2.19 shows the dfa


reduced from the dfa in Figure
2.18.

• Equivalence classes:
• {q0}, {q1, q3},{q2}, {q4}.
• Add new transition rules for new
states.

• Mark initial and final states.


54
Reducing States
Theorem 2.4

• Given any dfa M, application of the reduce procedure yields another dfa M̂
s.t.

• L(M) = L( M )̂ .

• Furthermore, M ̂ has the minimum number of states that accepts L(M).


• Check the text for the proof.
• How to show the two DFAs are equivalent.
• How to show that M ̂ is minimal.
55
Summary

• You need to know,


• what are DFAs and NFAs, and their connection with languages.
• You also need to understand the equivalence between DFAs and NFAs.
• After the lecture, please practice
• How to find a DFA or an NFA which accepts a specific language (and vice versa).
• How to show a given language is regular.
• The method to convert an NFA to an equivalent DFA.
• How to reduce the number of states in a DFA.
56

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