+ All Categories
Home > Documents > CS504-Theory of Computation - University of...

CS504-Theory of Computation - University of...

Date post: 05-Mar-2021
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
42
CS504-Theory of Computation Lecture 2: Finite Automata and Regular Languages Waheed Noor Computer Science and Information Technology, University of Balochistan, Quetta, Pakistan Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 1 / 42
Transcript
Page 1: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

CS504-Theory of ComputationLecture 2: Finite Automata and Regular Languages

Waheed Noor

Computer Science and Information Technology,University of Balochistan,

Quetta, Pakistan

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 1 / 42

Page 2: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Outline

1 Finite Automata

2 Deterministic Finite Automaton

3 Configurations of DFA

4 Readings

5 Nondeterministic Finite Automaton

6 Equivalence of NFAs and DFAs

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 2 / 42

Page 3: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Outline

1 Finite Automata

2 Deterministic Finite Automaton

3 Configurations of DFA

4 Readings

5 Nondeterministic Finite Automaton

6 Equivalence of NFAs and DFAs

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 3 / 42

Page 4: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Finite Automata

This course is about the mathematical model of computers andalgorithms, so we start with a simple model of real computers withfixed and finite capacity, called finite automaton, also known finitestate machine.It has a central processing unit and it receives its input as a stringand output nothing but an indication that whether the input isacceptable or not.These simple models have rich utilizations such as in lexicalanalysis, string matching and searching.This study will enable you to understand much more complexmodels for computers with additional memory (unboundedmemory capacity) and their computational power.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 4 / 42

Page 5: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Understanding by an example I

Assume a computer to control a toll gate that is initially closed, andwhen a car arrives it opens only if the driver has paid 25 cents.

Also assume that there are only three types of coins, 5, 10 and 25.

Further assume that no excess change is returned.

When a car arrives at the gate and driver inserts a sequence of coins,the computer/machine has to decide whether or not to open the gate.

To make this decision, our machine will be in one of the followingstates.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 5 / 42

Page 6: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Understanding by an example II

q0, no money paid, q1, exactly 5 cents paid, q2, exactly 10 centspaid, q3, exactly 15 cents paid, q4, exactly 20 cents paid, q5, 25 ormore cents paid.

Now, when a car arrives at the toll gate, the gate is closed and themachine in the initial state, i.e., q0. For example, the driver presentsthe coins in the sequence of (10,5,5,10).

When the first coin is received by the machine, it will switch fromstate q0 to q2.Given the remaining sequence of coins (5,5,10), the machine willmake transitions from q2 to q3, q3 to q4, and q4 to q5, respectively.Since, the machine is now in state q5, the gate will be opened.We can represent this state configurations for our machine in theform of a directed graph called state diagram, as shown bellow.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 6 / 42

Page 7: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Understanding by an example III

Note, each state represents a node in the graph, and eachtransition is represented by an arrow from a node to another orsame node labeled with a symbol.Furthermore, the final/special/terminal state (i.e., q5) isrepresented by a node with two circles, which means as soon asmachine arrives at this state, the given input sequence isaccepted that in our case is to open the gate.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 7 / 42

Page 8: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Understanding by an example IV

We can observe that at any point of time, our machine needs toremember its current state, therefore it needs very limited andfixed (small) memory.

If the machine is in one of the final states after reading the input,then it actually accepts the input.

The set of input sequence (often strings), called a language, andthe automaton machine accepting this set is actually accepting thelanguage.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 8 / 42

Page 9: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Class Activity

Class ActivityConsider the following state diagram, and show whether the strings1101 and 010101010 are accepted or not. Also describe the machineand strings it is accepting.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 9 / 42

Page 10: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Outline

1 Finite Automata

2 Deterministic Finite Automaton

3 Configurations of DFA

4 Readings

5 Nondeterministic Finite Automaton

6 Equivalence of NFAs and DFAs

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 10 / 42

Page 11: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Deterministic Finite Automaton (DFA)

DefinitionA deterministic finite automaton is a quintuple (five-tuple)M = (Q,Σ, δ, s,F ), whereQ is finite set of states,Σ is finite set of symbols called alphabet,δ is a function Q × Σ→ Q, called transition function,s ∈ Q is the initial state, andF ⊆ Q is the set of final states.

The transition function, δ, of an automaton machine M describes whatM can do in one step.Thus if M is in state q, and reads the symbol a ∈ Σ then M switchesfrom q to δ(q,a) ∈ Q that is a uniquely determined state.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 11 / 42

Page 12: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Outline

1 Finite Automata

2 Deterministic Finite Automaton

3 Configurations of DFA

4 Readings

5 Nondeterministic Finite Automaton

6 Equivalence of NFAs and DFAs

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 12 / 42

Page 13: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Configurations of a DFA I

The configurations of a DFA M is any element of Q ×Σ∗ that representthe status of the machine at successive moments.Since, DFA reads the input string in a head (forward) manner, thereforethe configuration is determined by the current state and unread part ofthe input string.Example: From activity example, (q2,101).

DefinitionA binary relation between two configurations of M denoted by `Mholds if and only if the machine can pass from one to the other in asingle move.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 13 / 42

Page 14: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Configurations of a DFA II

FormallyIf (q,w) and (q′,w ′) are two configurations of M then (q,w) `M (q′,w ′)if and only if w = (aw ′) for some a ∈ Σ, and δ(q,a) = q′.

In other words, (q,w) yields (q′,w ′) in a single step.

In fact, `M is a function from Q × Σ+ to Q × Σ∗,

That is, for every configuration of M except of the form (q, ε), thereis uniquely determined next configuration.

Configuration of the form (q, ε) signifies that M has consumed allits input.

The reflexive, transitive closure of `M is denoted by `∗M such that(q,w) `∗M (q′,w ′).

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 14 / 42

Page 15: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Configurations of a DFA III

That is, (q,w) yields (q′,w ′) in some (possibly zero) steps.

A string w ∈ Σ∗ is accepted by M if and only if there is a state q ∈ Fsuch that (s,w) `∗M (q,e).A language is accepted by M, denoted by L(M), is the set of all stringsaccepted by M.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 15 / 42

Page 16: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Explanation by Example I

Let M = (Q,Σ, δ, s,F ) be a deterministic finite automaton, whereQ = {q0,q1}, Σ = {a,b}, s = q0, F = {q0}, and δ is tabulated below.

q ρ δ(q, ρ)

q0 a q0q0 b q1q1 a q1q1 b q0

Note: We can see that L(M) is set of all strings over {a,b}∗ that haveeven number of b‘s.Now, consider the input string aabba with initial configuration(q0,aabba), then

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 16 / 42

Page 17: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Explanation by Example II

(q0,aabba) `M (q0,abba)

`M (q0,bba)

`M (q1,ba)

`M (q0,a)

`M (q0, ε)

Therefore, (q0,aabba) `∗M (q0, ε) and hence aabba is accepted by M.And we say, M acceptsL(M) = {w ∈ Σ∗ : w contains even number of b‘s }.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 17 / 42

Page 18: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Explanation by Example III

Information: It is always useful to draw a state diagram (graphrepresentation of transition function) to identity the set of stringsdenoted by DFA.

Figure : State diagram of M described in the above example.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 18 / 42

Page 19: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

LanguageWe can now define language formally with the help following definitions

Language: Formal DefinitionLet M = (Q,Σ, δ, s,F ) be a DFA and let w = w1w2 · · ·wn be a stringover alphabet Σ. Define the sequence q0,q1, · · · ,qn of states such that

q0 = sqi + 1 = δ(qi ,wi+1) for i = 0,1, · · · ,n − 1.If qn ∈ F , then M accepts w .If qn /∈ F , then M rejects w .

DefinitionLet M = (Q,Σ, δ, s,F ) be a DFA, the language L(M) accepted by M isdefined to be set of all strings that are accepted by M:

L(M) = {w : w is a string over Σand M accepts w}.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 19 / 42

Page 20: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Class WorkDesign DFA M that accept following languages over alphabetΣ = {a,b}.

ExampleL(M) = {w ∈ Σ∗ : w does not contain three consecutive b‘s}.

ExampleL(M) = {w ∈ Σ∗ : each a ∈ w is immediately preceded by a b}.

ExampleL(M) = {w ∈ Σ∗ : w neither has aa or bb as a substring}.

ExampleL(M) = {w ∈ Σ∗ :w contains odd number of a‘s and even number of b‘s}.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 20 / 42

Page 21: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

DFA from a State Diagram

Design DFA M and describe language L(M) accepted by followingstate diagram

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 21 / 42

Page 22: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Outline

1 Finite Automata

2 Deterministic Finite Automaton

3 Configurations of DFA

4 Readings

5 Nondeterministic Finite Automaton

6 Equivalence of NFAs and DFAs

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 22 / 42

Page 23: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Readings

Read and understand with examples the concept of finite statetransducer and two-tape finite automaton.

You should also write and submit a one or two page report about thesetopics.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 23 / 42

Page 24: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Outline

1 Finite Automata

2 Deterministic Finite Automaton

3 Configurations of DFA

4 Readings

5 Nondeterministic Finite Automaton

6 Equivalence of NFAs and DFAs

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 24 / 42

Page 25: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Nondeterministic Finite Automaton (NFA) I

NondeterminismThe ability to change the states that are only partially determined bythe current state and the input symbol. That is, the transition may nowresult in possibly more than one next states given the current state andthe input symbol.

By this we mean, the choice can not be determined by ourautomaton model, however the choice is not unlimited either; onlynext legal states can be chosen.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 25 / 42

Page 26: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Nondeterministic Finite Automaton (NFA) II

Explanation by Example1. Lets design a state diagram of a DFA accepting languageL = {w ∈ Σ∗ : w contains ab or aba}.2. Then lets design a state diagram of a NFA accepting the samelanguage as above.3. Now design a state diagram of a DFA and NFA accepting languageL = {w ∈ Σ∗ : w contains 1 at the third position from right }.

NFA is a useful notational generalization of finite automata.

NFA can also greatly simplify the description of these automata.

NFA also allow states with some inputs there may be no possiblemove.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 26 / 42

Page 27: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Nondeterministic Finite Automaton (NFA) III

In NFA, we may have transition on empty string ε.

Furthermore, every NFA is equivalent to a DFA (Note: Which we will see

shortly).

Therefore, we can get advantage from the powerful notation ofNFA and yet can get back to the DFA.

NFA is easy for designers while DFA is easy to implement.

A NFA may have multiple configurations for an input string wwhere some may be ending in a non-final state, some in final stateor some represent the hang status when the automaton can notconsume all input.

The hang status occurs when no possible move is possible whilereading the input.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 27 / 42

Page 28: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Nondeterministic Finite Automaton (NFA) IV

A string w is acceptable by a NFA if there is at least a singleconfiguration that ends in one of the final states while consumingthe complete input string w .

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 28 / 42

Page 29: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Formal Definition

DefinitionA nondeterministic finite automaton is a quintuple (five-tuple)M = (Q,Σ,∆, s,F ), whereQ is finite set of states,Σ is finite set of symbols called alphabet,∆ is the transition relation that is a subset of Q × (Σ ∪ ε)×Q,s ∈ Q is the initial state, andF ⊆ Q is the set of final states.

The transition relation ∆ is set of triples (q,u,p) called transitionof M stating M is in state q and the next input symbol is u, andthen M moves into state pM may follow any transition of the form (q,u,p) or (q, ε,p).

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 29 / 42

Page 30: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Configurations of NFA

Formally, computations from NFA are similar to those for DFA.Configuration of M is, again, an element of Q × Σ∗, i.e (q,w).The relation `M between configuration is defined as:(q,w) `M (q′,w ′) if and only if w = (uw ′) for some u ∈ Σ ∪ {ε}and (q,u,q′) ∈ ∆.`M need not to be a function, since for some (q,w) there may beseveral (q′,w ′) pairs or not at all.Similarly, `∗M is reflexive and transitive closure of `M .A string w ∈ Σ∗ is accepted by M if and only if there is a stateq ∈ F such that (s,w) `∗M (q,e).Finally, a language L(M) is accepted by M if the set of all it’sstrings accepted by M.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 30 / 42

Page 31: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Example

ExampleConstruct a NFA M for language L(M) = {w : w contains bb or bab }.

Now consider the input string bababab and check if it is accepted byour NFA.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 31 / 42

Page 32: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

A More Complex Example

ExampleLet Σ = {a1,a2, · · · ,an}, containing n symbols, where n ≥ 2, andconsider the following languageL = {w : there is a symbol ai ∈ Σ not appearing in w}.

That is L contains all strings in Σ∗ that fail to contain occurrences of allsymbols in Σ, e.g., if n = 3, then ε,a1,a2,a1a1a3 ∈ L but a2,a1,a3 /∈ L.

Let M = {Q,Σ,∆, s,F}, whereQ = {s,q1,q2, · · · ,qn} contains n + 1 states and all acceptingstates F = Q,∆ will have two kinds of transition, initial transitions of the form(s, ε,pi) for all i ,1 ≤ i ≤ n,and main transitions are all triples of the (qi ,aj ,qi), where i 6= j .

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 32 / 42

Page 33: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Discussion

When a NFA starts reading input, it guesses the transition andpasses to the next corresponding states.And ultimately it finds that its guess is correct, since one singlesuccessful computation is required for acceptance.Later we will see that a NFA can be converted into an equivalentDFA.Therefore, the class of languages accepted by DFA is a subset ofthe class of languages accepted by NFA that are in fact equal.The two finite automata M1 and M2 are equivalent if and ifL(M1) = L(M2).

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 33 / 42

Page 34: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Outline

1 Finite Automata

2 Deterministic Finite Automaton

3 Configurations of DFA

4 Readings

5 Nondeterministic Finite Automaton

6 Equivalence of NFAs and DFAs

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 34 / 42

Page 35: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Equivalence of DFAs and NFAs I

TheoremFor each nondeterministic finite automaton, there is an equivalentdeterministic finite automaton.

Before we start actual proof, consider the following example of NFAand think of the ways that may be helpful to construct an equivalentDFA.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 35 / 42

Page 36: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Equivalence of DFAs and NFAs II

Now, lets define a special set E(q) for any state q ∈ Q that contains allstates of M reachable by ε−moves.That is E(q) = {p ∈ Q : (q,e) `∗M (p,e)}.For our running example, E(q0) = {q0,q1,q2,q3} andE(q1) = {q1,q2,q3}.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 36 / 42

Page 37: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Equivalence of DFAs and NFAs III

Proof.Let M = {Q,Σ,∆, s,F} be a NFA and we shall construct a DFAM ′ = {Q′,Σ, δ′, s′,F ′} equivalent to M.Then Q′ = 2Q that is the power set of the set of states of M, s′ = E(s),

F ′ will consists of all those subset of Q that contain at least one finalstate of M, i.e., F ′ = {K ⊆ Q : K ∩ F 6= ∅},For each K ⊆ Q, and each symbol a ∈ Σ, define the transition functionδ′ as

δ′(K ,a) =⋃{E(p) : p ∈ Q and (q,a,p) ∈ ∆ for some q ∈ K}

That is, δ′(K ,a) is taken to be the set of all states of M to which M cango by reading input a ∈ Σ (and possibly following several ε−moves).Continue ...

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 37 / 42

Page 38: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Equivalence of DFAs and NFAs IV

Before we continue the proof to show the equivalence of M and M ′ letsapply these definitions to our running example.First of all we will define E(q) for each q ∈ Q, i.e.,E(q0) = {q0,q1,q2,q3}, E(q1) = {q1,q2,q3}, E(q2) = {q2},E(q3) = {q3} and E(q4) = {q3,q4}.Q′ = 25 = 32, but important to us are only those that are reachablefrom s′ by reading input string.s′ = E(s) = E(q0) = {q0,q1,q2,q3}.For transition δ′(s′,a), we have triples (q1,a,q0), (q1,a,q4) and(q3,a,q4) in ∆ for each q ∈ s′ ,therefore δ′(s′,a) = E(q0) ∪ E(q4) = {q0,q1,q2,q3,q4}Similarly, we can complete the transitions, and define F ′ then.Once we have M ′, we can draw its state diagram.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 38 / 42

Page 39: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Proof of Equivalence I

We now prove that M and M ′ are equivalent by showing that a stringw ∈ L(M) if and only if w ∈ L(M ′). To show this we need proof offollowing claim that will support the proof of actual theorem.

ClaimFor any string w ∈ Σ∗ and any states p,q ∈ Q, (q,w) `∗M (p,e) if andonly if (E(q),w) `∗M′ (P,e) for some set P containing p.

Assume the claim is true then the remaining of the proof for thetheorem will follow

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 39 / 42

Page 40: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Proof of Equivalence II

Proof (cont.)Assume a string w ∈ Σ∗, then, by definition, w ∈ L(M) if and only if(s,w) `∗M (f ,e) for f ∈ F if and only if (E(s),w) `∗M′ (Q,e) for some Qcontaining f (by the above claim); that is if and only if (s′,w) `∗M′ (Q,e)for some Q ∈ F ′.

This proof of the theorem is incomplete until we do not show the proofof the above claim.

5 Bonus PointsIf you can show the proof of the claim and convince the audience thatyou have understood the proof.

Hint: This claim can be proved by induction on |w |.

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 40 / 42

Page 41: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

Class Activity

Construct DFA equivalent to the NFA shown in Figure bellow.

What class of languages above finite automata will accept?

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 41 / 42

Page 42: CS504-Theory of Computation - University of Balochistancsit.uob.edu.pk/images/web/staff/lecture/doc-7.2015-10...2015/10/28  · CS504-Theory of Computation Lecture 2: Finite Automata

References I

Waheed Noor (CS&IT, UoB, Quetta) CS504-Theory of Computation September 2015 42 / 42


Recommended