State-Transition Diagrams: Identifiers & Language Recognition with DFAs & NFAs, Study notes of Construction

State-transition diagrams, which describe deterministic finite automata (DFAs) and nondeterministic finite automata (NFAs). DFAs are used to specify sets of identifiers, while NFAs can recognize more complex languages. examples, definitions, and explanations of how to construct state diagrams for various languages. Students in a CISC223 course during the Winter 2014 semester would find this material useful for understanding state diagrams and their applications.

Typology: Study notes

2021/2022

Uploaded on 09/27/2022

kimball
kimball 🇬🇧

5

(3)

220 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
State-transition diagrams
This material is from Chapter 8 in the textbook.
Example. An identifier can be defined as a string of letters and digits that begins with a
letter.
Token letter stands for any of the symbols a, . . . , z, A, . . . , Z.
Token digit stands for 0, 1, . . . , 9.
The set of identifiers is specified by the state-transition diagram in Figure 1.
letter
letter, digit
Figure 1: A state-diagram for specifying identifiers.
Example. We design a “sequential lock” as described below. The lock has 1-bit sequential
input. Initially, the lock is closed. If the lock is closed it will open when the last three input
bits are “1”, “0”, “1”, and then remains open.
In other words, the state-transition diagram should accept exactly all strings that contain
substring 101. The state-transition diagram will be constructed in class.
What is a regular expression that denotes the same language?
A state diagram describes a deterministic finite automaton (DFA), a machine that
at any given time is in one of finitely many states, and whose state changes according to a
predetermined way in response to a sequence of input symbols.
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download State-Transition Diagrams: Identifiers & Language Recognition with DFAs & NFAs and more Study notes Construction in PDF only on Docsity!

State-transition diagrams

This material is from Chapter 8 in the textbook.

Example. An identifier can be defined as a string of letters and digits that begins with a letter.

  • Token letter stands for any of the symbols a,... , z, A,... , Z.
  • Token digit stands for 0, 1,... , 9.

The set of identifiers is specified by the state-transition diagram in Figure 1.

letter

letter, digit

Figure 1: A state-diagram for specifying identifiers.

Example. We design a “sequential lock” as described below. The lock has 1-bit sequential input. Initially, the lock is closed. If the lock is closed it will open when the last three input bits are “1”, “0”, “1”, and then remains open. In other words, the state-transition diagram should accept exactly all strings that contain substring 101. The state-transition diagram will be constructed in class. What is a regular expression that denotes the same language?

A state diagram describes a deterministic finite automaton (DFA), a machine that at any given time is in one of finitely many states, and whose state changes according to a predetermined way in response to a sequence of input symbols.

A formal definition is given below. Definition. A DFA is defined as a tuple

M = (Q, Σ, δ, s, F )

where the components are as follows:

  • Q is the finite nonempty set of states
  • Σ is the input alphabet
  • δ : Q × Σ −→ Q is the transition function
  • s ∈ Q is the starting state
  • F ⊆ Q is the set of accepting states A finite state automaton (DFA) is conveniently specified using a state diagram, especially when the set of states is small.

Example. Consider the state diagram in Figure 2.

1

(^01)

0

1

0

1

q 1 q 2

q 4 q 3

0

Figure 2: A state-transition diagram. In a formal notation this automaton can be specified as M = (Q, Σ, δ, s, F )

Example. Construct a state diagram for recognizing comments that may go over several lines: /* ......*/

Nondeterminism

  • The state diagrams that we have considered up to now were deterministic: for any state and input symbol pair there can be at most one outgoing transition.
  • A nondeterministic state diagram allows the following type of situations:

b

b

Figure 3: Nondeterministic transitions.

When dealing with nondeterministic state diagrams it is important to remember that now a given string may label more than one path beginning from the starting state and we have to be careful how the acceptance of a string is defined: Nondeterministic acceptance: a string is accepted if it appears on any path from the starting state to an accepting state.

Why nondeterminism?

  • Often it is much easier to construct a nondeterministic state diagram than a determin- istic one.
  • A nondeterministic state diagram can be much smaller than the smallest possible deterministic state diagram that recognizes the same language.
  • On the other hand, it is not immediately clear how we can implement nondetermin- istic state diagrams since program behavior is deterministic (or, at least, it should be deterministic). Fortunately, there is a way to convert a nondeterministic state diagram into an equivalent deterministic one, and the conversion can even be automated.

Example. Consider the following nondeterministic state diagram with input alphabet { 0 , 1 }:

Figure 4: A nondeterministic state diagram.

  • Where does the nondeterminism appear in the state diagram of Figure 4?
  • What is the language recognized by the state diagram of Figure 4?
  • How would you construct an equivalent DFA?

Nondeterministic state diagrams are also called nondeterministic finite automata, NFA.

Example. Let Σ = { 0 , 1 } and define

S 1 = Σ∗01Σ∗ S 2 = {w ∈ Σ∗^ | w has an even number of 1’s } The following state diagram recognizes S 1 ∪ S 2 :









*

HHH HHH Hj

State diagram for S 1

State diagram for S 2

Figure 6: A state diagram for S 1 ∪ S 2.

A state diagram with ε-transitions is called an ε-NFA. Given an ε-NFA M we can construct an equivalent NFA without ε-transitions as follows (see page 183 in the textbook):

  1. Make a copy M′^ of M where the ε-transitions have been removed. Remove states that have only ε-transitions coming in, however, the starting state is not removed.
  2. Add transitions to M′^ as follows: whenever M has a chain of ε-transitions followed by a “real” transition on x ∈ Σ, see Figure 7: ε ε ε ε x (^) p q - - - - - 

 

 

 

 



Figure 7: A chain of ε-transitions followed by a “real” transition.

we add to M′^ a transition from state q to state p that is labeled by x. Note that here q and p may be any states. For example, the above construction step is used also in the case where q = p.

  1. If M has a chain of ε-transitions from a state r to an accepting state, then r is made to be an accepting state of M′.

Example. How does the construction work with the state diagram:



 

 

 



  • ε - 0 -

Figure 8: An ε-NFA.

Example. The below state diagram (Figure 9) recognizes unsigned decimal numbers:

digit

digit

  •  -  - 

 

 

 

 

 

 



& %

6

?

  ?

 

Figure 9: An ε-NFA for unsigned decimal numbers.

We construct an equivalent nondeterministic state diagram without ε-transitions (in class).

Note: By combining the above two transformations, that is, the elimination of ε-transitions and the subset construction, we can always convert a state diagram with ε-transitions to a deterministic state diagram.