CMP3008 LN2 FiniteAutomata
CMP3008 LN2 FiniteAutomata
Formal Languages
and Automata Theory
Lecture Notes 2
Finite Automata
Sources
https://eecs.wsu.edu/~ananth/CptS317/Lectures/index.htm
"Introduction to automata theory, languages and
computation" by JE Hopcroft, R Motwani and JD Ullman.
"An Introduction to Formal Languages and Automata Theory" by
Peter Linz
Content
• Deterministic finite automata (dfa)
• Formal Definition of dfa
• DFA Design Examples
• Regular Languages
• Regular Operations
2
Finite Automata (DFA)
• Informally, a state diagram that comprehensively captures all possible states and
transitions that a machine can take while responding to a stream or sequence of
input symbols
• Recognizer for “Regular Languages”
3
Deterministic Finite Automata (DFA)
• A Deterministic Finite Automaton (DFA) consists of:
• Q ==> a finite set of states
• ∑ ==> a finite set of input symbols (alphabet)
• q0 ==> a start state
• F ==> set of accepting states
• δ ==> a transition function, which is a mapping between Q x ∑ ==> Q
• A DFA is defined by the 5-tuple:
• {Q, ∑ , q0,F, δ }
4
Formal Definition of a Finite Automaton
Formal Definition of a Finite Automaton
Deterministic Finite Automata (DFA)
• Input: a word w in ∑*
• Question: Is w acceptable by the DFA?
• Steps:
• Start at the “start state” q0
• For every input symbol in the sequence w do
• Compute the next state from the current state, given the current input symbol in w and
the transition function
• If after all symbols in w are consumed, the current state is one of the
accepting states (F) then accept w;
• Otherwise, reject w.
7
Deterministic Finite Automata (DFA)
Can you describe the language consisting of all strings that M1 accepts?
Examples
Example: 10⟨RESET⟩22⟨RESET⟩012
Formal Definition of Computation
Designing DFA
• Whether it be of automaton or artwork, design is a creative process.
• A helpful approach: put yourself in the place of the machine you are
trying to design and then see how you would go about performing
the machine’s task.
• First, in order to make these decisions, you have to figure out what
you need to remember about the string as you are reading it.
• Once you have determined the necessary information to remember
about the string as it is being read, you represent this information as
a finite list of possibilities.
Designing DFA
Example: Design a FA for the following language:
Next, you assign the transitions by seeing how to go from one possibility to another
upon reading a symbol.
Designing DFA
• Next, you set the start state to be the state corresponding to the possibility
associated with having seen 0 symbols so far (the empty string ε).
• Last, set the accept states to be those corresponding to possibilities where you
want to accept the input string.
Designing DFA
Example: Design a FA for the following language:
L = {w | w contains 001 as a substring}
What information do you need to remember?
27
Regular Languages
• Finite automata accept a family of languages
collectively known as regular languages.
• A language L is regular if and only if there is a DFA that
accepts L. Therefore, to show that a language is regular, one
must construct a DFA to accept it.
• Practice: show that L = {(ab)na, n > 0} is regular.
• Regular languages have wide applicability in problems
that involve scanning input strings in search of specific
patterns.
Example
• Build a DFA for the following language:
• L = {w | w is a binary string that contains 01 as a substring}
• Steps for building a DFA to recognize L:
• ∑ = {0,1}
• Decide on the states: Q
• Designate start state and final state(s)
• δ: Decide on the transitions:
• “Final” states == same as “accepting states”
• Other states == same as “non-accepting states”
29
Regular expression: (0+1)*01(0+1)*
1 0,1 • ∑ = {0,1}
0
• start state = q0
start 0 1
q0 q1 q2 • F = {q2}
Accepting • Transition table
state symbols
0 1
• What if the language allows q0 q1 q0
empty strings?
states
q1 q1 q2
*q2 q2 q2
30
The Regular Operations
• In arithmetic, the basic objects are numbers and the tools are
operations for manipulating them, such as + and ×.
• In the theory of computation, the objects are languages and the tools
include operations specifically designed for manipulating them.
• We define three operations on languages, called the regular
operations, and use them to study properties of the regular
languages.
The Regular Operations
The Regular Operations
The Regular Operations
The Regular Operations