0% found this document useful (0 votes)
16 views8 pages

Understanding Deterministic Finite Automata

CS 476

Uploaded by

berkozkanjp
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)
16 views8 pages

Understanding Deterministic Finite Automata

CS 476

Uploaded by

berkozkanjp
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

CS 476 – 1 - Finite Automata

1 Course topics:
1. Finite automata / regular expressions
2. Context-free grammars
3. Turing Machines
4. Decidability / undecidability
5. NP-Completeness

2 Finite Automata
Automata: Plural of “automaton” (= machine)

A Finite State Machine is dened with:


• Finite set of states
• Finite set of inputs
• Transition function
• A special start state
Examples:

TV:

start off on
switch off

switch on
turn off
turn on

switch off

standby

PC:

standby
switch off
switch on
stand by

switch off
switch on
start off on

hibernate

switch on

switch off hibernate


Finite Automaton is a Finite State Machine with some “accept state”.
M (q1 is the accept state):

1 0

q0
0 q1
start

input string w = 0100 is accepted by M . M also accepts 0, 10, 110, 010, . . ., i.e. all inputs that ends
with 0.

2.1 Background Review


Some notations for sets A and B:

• A × B: the cartesian product of A and B.


eg. A = {a, b}, B = {x, y}, then A × B = {(a, x), (a, y), (b, x), (b, y)}

• Ak for integer k: A × A × . . . A× (k times)

• 2A : the power set of A.


eg. A = {a, b}; 2A = {∅, {a}, {b}, {a, b}}

• |A|: number of elements in A (cardinality of A).

Some denitions:

• alphabet: a nite set of symbols.


eg. Σ1 = {0, 1}, Σ2 = {a, b, c, . . . , z}

• string: a nite sequence of symbols; a.k.a. “word”.


eg. w1 = 0100, w2 = abcbd

• language: a set of strings over an alphabet.


eg. L1 = {01, 10, 001}, L2 = {w ∈ {0, 1}∗ : w ends with 0}

2.2 Deterministic Finite Automata


Denition: A deterministic nite automaton (DFA) is a 5-tuple (Q, Σ, δ, q0 , F ) where:

• Q is a nite set of states.

• Σ is a nite alphabet.

• δ : Q × Σ → Q is the transition function.

• q0 ∈ Q is the start state.

• F ⊆ Q is the set of accept states.

2
Transition diagram representation:

1 0

q0
0 q1
start

Transition table representation:

Q/Σ 0 1
→ q0 q1 q0
∗q1 q1 q0
Denition: A DFA M is said to accept an input string if its computation ends at an accept state.
eg. M accepts 0100.
Denition: The language of a DFA M , L(M ), is the set of all input strings accepted by M .
eg. L(M ) = {w|w ends with 0}
Examples:

• L : {w|w begins with 0}

q1 0,1
0

start q0
1

q2 0,1

• L : {w|w begins with 0 and ends with 1}

0
1
q1 q3 1
0
0
start q0
1

q2 0,1

3
• L : {w|w begins and ends with 0}

0
1
q1 q3 1
0
0
start q0
1

q2 0,1

• L : {w|w has even number of 1s}

0 0

q0
1 q1
start

• L : {w|w has odd number of 1s}

0 0

q0
1 q1
start

• L : {w|w ends with 1 or w = }

1 0

q0
0 q1
start

• L : {w|w contains 01 as a substring}

1 0

q0
0 q1
1 q2
start 0,1

4
• L : {w|w contains 010 as a substring}

1 0

q0
0 q1
1 q2
0 q3
start 0,1

• L : {w|n0 (w) is even and n1 (w) is even}

start n0 even, n1 even n0 odd, n1 even

1 1 1 1

n0 even, n1 odd n0 odd, n1 odd

• L : {w|n0 (w) ≡ n1 (w) mod 2}


Same as above, but n0 odd, n1 odd is also an accept state.

• L : {w|n0 (w) = n1 (w)}


Cannot be accepted by a DFA.

Denition: A language is regular if it is accepted by some DFA.


eg. L1 = {w|w ends with 0}
L2 = {w|w contains an even number of 0s}
...
Example:

Theorem 2.1 The language of the DFA M below is L = {w|w ∈ {0, 1}∗ and w does not have two consecutive 1s}.
M:
0 0,1
1

1
start A B C

5
Proof We have two sets S and T :
• S = “the language of M ”
• T = “the set of strings of 0s and 1s with no consecutive 1s”
To prove S = T , we need to prove both S ⊆ T and T ⊆ S. That is:
• if w ∈ S, then w ∈ T .
• if w ∈ T , then w ∈ S.
Inductive hypothesis for Part 1 (S ⊆ T ):
1. If δ(A, w) = A, then w has no consecutive 1s and does not end in 1.
2. If δ(A, w) = B, then w has no consecutive 1s and ends in a single 1.
Basis: |w| = 0; i.e. w = 
• (1) holds since  has no 1s at all.
• (2) holds vacuously, since δ(A, ) is not B.
Induction:
• Assume (1) and (2) are true for strings shorter than w, where |w| ≥ 1.
• Because w 6= , we can write w = xa, where a is the last symbol of w, and x is the string that
precedes.
• IH holds for x.
• Need to prove (1) and (2) for w = xa.
• (1) for w is: If δ(A, w) = A, then w has no consecutive 1s and does not end in 1.
• Since δ(A, w) = A, δ(A, x) must be A or B, and a must be 0 (look at the DFA).
• By the IH, x has no 11s.
• Thus, w has no 11s and does not end in 1.
• Now, prove (2) for w = xa: If δ(A, w) = B, then w has no 11s and ends in 1.
• Since δ(A, w) = B, δ(A, x) must be A, and a must be 1 (look at the DFA).
• By the IH, x has no 11s and does not end in 1.
• Thus, w has no 11s and ends in 1.
Inductive hypothesis for Part 2 (T ⊆ S):
• if w has no 11s, then w is accepted by M .
• Contrapositive: If w is not accepted by M , then w has 11.
Using the contrapositive:
• Because there is a unique transition from every state on every input symbol, each w gets the DFA to
exactly one state.
• The only way w is not accepted is if it gets to C.
• The only way to get to C (formally: δ(A, w) = C) is if w = x1y, x gets to B, and y is the tail of w
that follows what gets to C for the rst time.
• If δ(A, x) = B then surely x = z1 for some z.
• Thus, w = z11y and has 11.

6
2.3 Nonregular Languages
Some languages are nonregular.

• L1 = {0n 1n } is nonregular since DFAs cannot count.

• L2 = {w|w ∈ {(, )}∗ and w is balanced.}. Balanced parentheses are those sequences of parentheses
that can appear in an arithmetic expression. E.g.: (), ()(), (()), (()()) . . .

You can use CFGs to represent L1 and L2 above.

2.4 Regular Languages


They appear in many contexts and have many useful properties. Examples:
L3 = {w|w ∈ {0, 1}∗ and w, viewed as a binary integer is divisible by 23}
DFA M3 to recognize L3 :

• 23 states, named 0, 1, . . . , 22 that correspond to the 23 remainders of an integer divided by 23.

• Start and only nal state is 0.

• If string w represents integer i, then assume δ(0, w) = i mod 23.

• Then w0 represents integer 2i, so we want δ(i mod 23, 0) = (2i) mod 23.

• Similarly: w1 represents 2i + 1, so we want δ(i mod 23, 1) = (2i + 1) mod 23.

• Example: δ(15, 0) = 30 mod 23 = 7; δ(11, 1) = 23 mod 23 = 0.

Example 2:
L4 = {w|w ∈ {0, 1}∗ and w, viewed as the reverse of a binary integer is divisible by 23}

• 01110100 is in L4 , because its reverse, 00101110 is 46 in binary.

• Hard to construct the DFA.

• But there is a theorem that says the reverse of a regular language is also regular.

7
2.5 Implementation of DFA
enum STATES {A, B , C} s t a t e ;
int i ;
char w [ ] ; / / f r o m t h e u s e r
s t a t e = A; / / A i s s t a r t s t a t e
f o r ( i = 0 ; i < s t r l e n (w ) ; i ++){
switch ( s t a t e ){
case A:
i f (w[ i ]== ’ 0 ’ ) s t a t e =A ;
e l s e s t a t e =B ;
break ;
0 0,1 case B:
i f (w[ i ]== ’ 0 ’ ) s t a t e =A ;
1 e l s e s t a t e =C ;
1
start A B C break ;
case C:
0
s t a t e =C ;
break ;
}
}
i f ( s t a t e == A | | s t a t e == B) {
p r i n t f ( ” accepted .\ n” ) ;
}
else{
p r i n t f ( ” r e j e c t e d .\ n” ) ;
}

Recall L3 = {w|w ∈ {0, 1}∗ and w, viewed as a binary integer is divisible by 23}
if (w)2 = (i)10 ; then:
δ(0, w) = i mod 23. Thus
Q = {0, 1, . . . , 22}, q0 = {0} and F = {0}.
Note that (w0)2 = (2i)10 and (w1)2 = (2i + 1)10 .

δ(0, w) = i mod 23.


δ(0, w0) = 2i mod 23.
δ(0, w0) = δ(δ(0, w), 0) = δ(i mod 23, 0) = 2i mod 23.

Similarly :
δ(0, w1) = (2i + 1) mod 23.
δ(0, w1) = δ(δ(0, w), 1) = δ(i mod 23, 0) = (2i + 1) mod 23.
DFA (partial):

0
1 0

1 0
start 0 1 2 3 4 5 22

For implementation, see


[Link]

Common questions

Powered by AI

In a deterministic finite automaton (DFA), the language acceptance behavior is defined by its transition mechanics leading to an accept state. Specifically, for the language L = {w|w ends with 0}, the DFA transitions through its states according to the input symbols and reaches an accept state if the last symbol processed is 0. This means the DFA's final state, after reading the entire input string, must be one of the designated accept states if the string ends with 0. This transition behavior allows the DFA to effectively decide the string's membership in L based on its ending character .

A DFA faces the challenge of recognizing the language L = {0^n1^n} because it would need to count and compare the number of 0s and 1s, maintaining this count across potentially unlimited input lengths while remembering the sequence. This kind of counting requires unbounded memory, which is not feasible with a DFA's fixed finite states. The significance of L = {0^n1^n} as an example of a nonregular language lies in its requirement for context-sensitive information, highlighting the limitations of DFAs and emphasizing the need for more powerful computational models like pushdown automata .

Deterministic finite automata (DFA) are closely related to regular languages, as a language is considered regular if it can be recognized by some DFA. This connection arises from the DFA's ability to process strings over a finite alphabet and determine their acceptance based on the DFA's transition function. For example, a DFA can recognize a language consisting of strings that end with 0, as it transitions through different states based on input symbols, ultimately reaching an accept state if the string conforms to the constraints of the language .

A deterministic finite automaton (DFA) cannot accept the language L = {w|n0(w) = n1(w)} because this language requires counting and comparing potentially unbounded numbers of 0s and 1s. DFAs have a finite number of states and cannot maintain count of the occurrences of symbols to determine equality over a potentially infinite input length. This limitation implies that the language is nonregular, necessitating more powerful computational models, such as context-free grammars, to accept such languages .

The transition function of a deterministic finite automaton (DFA) is defined as a mapping δ: Q × Σ → Q, where Q is the set of states, Σ is the input alphabet, and δ determines the next state from the current state and input symbol. The role of the transition function is to detail how the DFA transitions from one state to another based on the input it processes. It is a deterministic mapping, meaning for every state and input symbol, there is exactly one next state .

The power set 2A plays a crucial role in finite automata, particularly in the subset construction method used when converting non-deterministic finite automata (NFA) to deterministic finite automata (DFA). In this context, the power set represents all possible combinations of NFA states, which is essential for simulating every potential state transition in a DFA. This approach ensures that every possible state transition path in the NFA is accounted for in the DFA, allowing the DFA to recognize the same language as the NFA .

The closure properties of regular languages imply that applying certain operations to regular languages results in another regular language. The example of the reverse of a regular language being regular demonstrates this: if a language L is regular, then its reverse, denoted as L^R, is also regular. This is shown by the fact that the reverse of a binary integer that is divisible by 23 (as in L = {w|w, viewed as a binary integer, is divisible by 23}) is also regular. Constructing a DFA for the reversed language is challenging, yet a theorem confirms the regularity of L^R based on the original regular language L .

An inductive approach to show that a DFA M recognizing the language L = {w|w does not have two consecutive 1s} uses two parts: S ⊆ T and T ⊆ S. The inductive hypothesis for S ⊆ T asserts that if δ(A, w) = A, then w has no consecutive 1s and does not end in 1; if δ(A, w) = B, then w has no consecutive 1s and ends in 1. Base case: for the empty string w = ε, these conditions hold as no 1s exist. Induction: assume true for shorter strings. For w = xa, the statement is proven by analyzing whether a is 0 or 1 and checking the transitions ensuring no consecutive 1s are formed. For T ⊆ S, using the contrapositive proves that if w is not accepted by M, it has 11. This approach solidifies the claim through all possibilities of string generation and machine transitions .

Finite automata can be used to model real-world systems like electronic devices by depicting states and transitions between them in response to inputs. A specific example is a TV modeled as a finite state machine with states such as 'off,' 'on,' and 'standby,' and transitions like 'switch on' and 'switch off.' These transitions change the TV's state based on user input, similar to how a DFA processes input symbols to transition through states. The finite automaton's structure allows for formal verification of responses to inputs, ensuring reliable operation .

In finite automata, specifically deterministic finite automata (DFA), an accept state is one of the finite states designated as such where the automaton's computation can terminate after processing an input string. The role of an accept state is to determine whether an input string belongs to the language recognized by the automaton. If the automaton ends in an accept state after processing the entire string, the string is accepted as part of the language. For example, in a DFA where the language consists of strings ending with 0, the computation ends at an accept state when this condition is met, confirming the string's membership in the language .

You might also like