Deterministic Finite Automata (cont’d) - York University Fall 2006 1 Deterministic Finite Automata...

4

Click here to load reader

Transcript of Deterministic Finite Automata (cont’d) - York University Fall 2006 1 Deterministic Finite Automata...

Page 1: Deterministic Finite Automata (cont’d) - York University Fall 2006 1 Deterministic Finite Automata (cont’d) • Definition: A deterministic finite automaton (DFA) M is a 5-tuple

CSE2001, Fall 2006 1

Deterministic Finite Automata (cont’d)

• Definition: A deterministic finite automaton (DFA) M is a 5-tuple (Q, Σ, δ, q0, F ),where

– Q is a finite set of states;

– Σ is an input alphabet;

– δ : Q × Σ 7→ Q is a transition function;

– q0 ∈ Q is the start state;

– F ⊆ Q is the set of accepting states.

Things to note:

– The domain of the transition function δ is Q×Σ. This means that δ maps everypossible state/symbol pair to a state.

– The set F of accepting states can be any subset of Q. In particular, F = ∅, andF = Q are perfectly legal. Also, there is no problem with q0 belonging to F .

.

• Definition: A computation of a DFA M = (Q, Σ, δ, q0, F ) on the input string w =w1 . . . wn ∈ Σ∗ is a sequence (r0, . . . , rn) of states in Q, defined in the following way:

– r0 = q0,

– ri = δ(ri−1, wi), for all i, 1 ≤ i ≤ n.

If w = ε, then a computation of M on w is just (q0).

Note that a computation of M on w is determined uniquely.

• Definition: Let M = (Q, Σ, δ, q0, F ) be a DFA, let w be a string over Σ, and let(r0, . . . , rn) be the computation of M on w. Then M is said to accept w if rn ∈ F ,otherwise M is said to reject w.

Page 2: Deterministic Finite Automata (cont’d) - York University Fall 2006 1 Deterministic Finite Automata (cont’d) • Definition: A deterministic finite automaton (DFA) M is a 5-tuple

CSE2001, Fall 2006 2

• Definition: A DFA M is said to recognize a language L, if L = {w | Maccepts w}.

• Definition: A language L over some alphabet Σ is called regular if there exists a DFAwhich recognizes L.

• A moment of reflection:

– We defined a class of languages, namely the regular languages, for which themembership question can be answered by a DFA – if L is regular, then there is aDFA M such that w ∈ L if and only if M accepts w.

– But, remember that languages were intended to represent decision problems.

– Thus, in effect, we defined a class of decision problems, in which every decisionproblem can be solved by an algorithm or any physical device that emulates thebehavior of a DFA.

Now, what are the features characteristic of DFAs ?

– One-pass, read-only input.

– Finite amount of working memory. How much exactly ?

So, the decision problems solvable by DFA-like algorithms/devices are relatively “easy”.Soon we will learn that there are much more difficult decision problems out there.

Page 3: Deterministic Finite Automata (cont’d) - York University Fall 2006 1 Deterministic Finite Automata (cont’d) • Definition: A deterministic finite automaton (DFA) M is a 5-tuple

CSE2001, Fall 2006 3

• How to design DFAs ? Practice ! Here’s a couple of ideas that may help:

– Think what would you do if you were a DFA.

– States should represent some meaningful information about the input that DFAhas seen so far.

– The trap state qi 0, 1

– When there is a need for a particular pattern (like 010) – construct the corre-sponding sequence of states. Whenever the intermediate pattern breaks, go back.

qi qi+1 qi+2 qi+3

1

0

0

1

1

0

– If ε is in the language – the initial state must be accepting.

– Make sure that every state has an outgoing transition for each symbol of thealphabet.

• Example: Construct a DFA for the language L of all binary strings of length divis-ible by 3, that start and end with 1, i.e. L = {w | |w| is divisible by 3, and w0 =1 and w|w| = 1}.

– Stage 1. L = {w | |w| is divisible by 3}.

q0 q1 q2

0, 1 0, 1

0, 1

– Stage 2. L = {w | |w| is divisible by 3, and w 6= ε}.

q0 q1 q2 q3

0, 1 0, 1 0, 1

0, 1

– Stage 3. L = {w | |w| is divisible by 3, and w 6= ε, and w1 = 1}.

q0 q1 q2

q4

q31 0, 1 0, 1

0

0, 1

Page 4: Deterministic Finite Automata (cont’d) - York University Fall 2006 1 Deterministic Finite Automata (cont’d) • Definition: A deterministic finite automaton (DFA) M is a 5-tuple

CSE2001, Fall 2006 4

– Stage 4. L = {w | |w| is divisible by 3, and w 6= ε, and w1 = 1, and w|w| = 1}.

q0 q1 q2

q4 q4

q31 0, 1 1

0

0, 1

0, 10

0, 1