This is an old revision of the document!
Deterministic finite automata
1. Writing DFAs
1.1. Write a DFA which accepts the language $ L=\{w \in \{0,1\}^* \text{ | w contains an odd number of 1s} \} $ Hint:
- in a DFA, delta is total!
1.2 Define a DFA which accepts arithmetic expressions. Consider the following definition for arithmetic expressions:
<expr> ::= <var> | <expr> + <expr> | <expr> * <expr> <var> ::= STRING
Hint:
- how would you define the alphabet for the DFA?
- can <expr> be the empty string?
2. Implementing DFAs
Consider the following encoding of a DFA:
<number_of_states> <list_of_final_states> <state> <symbol> <state>
Example:
4 2 3 0 a 1 1 b 2 2 a 0
2.1. Write a function which takes a DFA encoding as above and returns a DFA representation. Define a class “DFA”.
2.2. Add a method accept which takes a word and returns true if it is accepted by the DFA
2.3. Add a method step with takes a DFA configuration and returns the “next-step” configuration of the DFA. How is a configuration defined?
2.4(*) Write a method which:
- takes a list of DFAs
a1, a2, …, an
- takes a string
s
. We know the string consists of a sequence of words, each accepted by some dfa in the list. - returns a list of pairs
(w1,x1), …(wi,xi) … (wn,xn)
such that