LN2 FiniteAutomata
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
Finite Automata (DFA)
• Finite automata (FA) differ from other computational models in
terms of memory.
• The key difference is that finite automata have constant
memory, while more powerful models (e.g. Pushdown
automata, Turing Machine) have varying memory capabilities.
• Finite automata are the most memory-restricted model, making
them efficient for simple pattern recognition but unsuitable for
complex computations requiring variable memory.
4
Finite Automata (DFA)
• Finite automata are widely used in
• lexical analysis (compilers),
• pattern matching (e.g., regular expressions),
• and network protocol design.
• They are also fundamental in understanding more advanced
computational models like pushdown automata and Turing
machines.
5
Deterministic Finite Automata (DFA)
• A Deterministic Finite Automaton (DFA) consists of:
• Q ==> a finite set of states
• ∑ ==> a finite set of input symbols (alphabet)
• δ ==> a transition function, which is a mapping between Q x ∑ ==> Q
• q0 ==> a start state
• F ==> set of accepting states
• A DFA is defined by the 5-tuple:
• {Q, ∑ , δ, q0,F}
6
Formal Definition of a Finite Automaton
Mapped to
a single
state
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.
8
Formal Definition of an Example
Finite Automaton
Can you describe the language consisting of all strings that M1 accepts?
Examples
Example: 10⟨RESET⟩22⟨RESET⟩012
Formal Definition of the Relation Between a
String and a DFA
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:
L = {w | w starts with a 1}
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?
L = {w | accepts any strings that does not contain aabb as a substring in it},
= {a, b}.
30
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.
Construction of a Transition Table: 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”
32
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
33
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: Closure Under Union
The Regular Operations: Closure Under Union
• This is a proof by construction.
• We construct M from M1 and M2.
• Machine M must accept its input exactly when either M1 or M2 would
accept it in order to recognize the union language.
• It works by simulating both M1 and M2 and accepting if either of the
simulations accept.
The Regular Operations: Closure Under Union
• One Idea:
• First simulate M1 on the input and then simulates M2 on the input.
• In this approach, once the symbols of the input have been read and
used to simulate M1, if the input is not accepted, do the same thing to
try the simulation on M2.
• Is this possible in a FA?
• No we can’t “rewind the input tape” to try the simulation on M2.
•We can keep track of the state of machines in parallel.
•Simulate both M1 and M2 simultaneously as input symbols arrive.
•Only one pass through the input is needed.
The Regular •Track the state of each machine at each point, requiring finite
memory.
Operations: •Remember a pair of states: one from M1 and one from M2.
Closure Under •If M1 has k1 states and M2 has k2 states, the number of possible
state pairs is k1 × k2.
Union •The total number of states in the combined machine M is k1 × k2,
corresponding to each state pair.
•Transitions in M occur between state pairs, updating both M1 and
M2's states.
•Accept states of M are those pairs where either M1 or M2 is in an
accept state.
The Regular Operations: Closure Under Union
The Regular Operations: Closure Under Union
The Regular Operations