0% found this document useful (0 votes)
13 views43 pages

LN2 FiniteAutomata

This document provides an overview of Deterministic Finite Automata (DFA) and their role in recognizing regular languages. It includes formal definitions, design examples, and the construction of DFAs for various languages, emphasizing their applications in lexical analysis and pattern matching. Additionally, it discusses the closure properties of regular languages and the operations that can be performed on them.

Uploaded by

mythemyaseen6
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)
13 views43 pages

LN2 FiniteAutomata

This document provides an overview of Deterministic Finite Automata (DFA) and their role in recognizing regular languages. It includes formal definitions, design examples, and the construction of DFAs for various languages, emphasizing their applications in lexical analysis and pattern matching. Additionally, it discusses the closure properties of regular languages and the operations that can be performed on them.

Uploaded by

mythemyaseen6
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
You are on page 1/ 43

CMP3008

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”

• Deterministic Finite Automata (DFA)


• The machine can exist in only one state at any given time
• Non-deterministic Finite Automata (NFA)
• The machine can exist in multiple states at the same time

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

Draw the corresponding


finite automata
Deterministic Finite Automata (DFA)

• The above figure depicts a finite automaton called M1.


• The figure is called the state diagram of M1.
• It has three states, labeled q1, q2, and q3.
• The start state, q1, is indicated by the arrow pointing at it from
nowhere.
• The accept state, q2, is the one with a double circle.
• The arrows going from one state to another are called transitions.
Deterministic Finite Automata (DFA)

• When this automaton receives an input string such as 1101, it processes


that string and produces an output.
• The output is either accept or reject.
• The processing begins in M1’s start state. The automaton receives the
symbols from the input string one by one from left to right. After reading
each symbol, M1 moves from one state to another along the transition that
has that symbol as its label.
• When it reads the last symbol, M1 produces its output. The output is
accept if M1 is now in an accept state and reject if it is not.
Relation Between a Formal Language and
a Finite Automaton
• If A is the set of all strings that machine M accepts, we say
that A is the language of machine M and write L(M ) = A.
• We say that M recognizes A.
• A machine may accept several strings, but it always recognizes
only one language.
• If the machine accepts no strings, it still recognizes one
language— namely, the empty language ∅
Deterministic Finite Automata (DFA)

Can you describe the language consisting of all strings that M1 accepts?
Examples

L(M2) = {w| w ends in a 1}.


Examples
Examples

L(M4) = {w| w starts and ends with the same symbol}.

Note that in this example Σ = {a, b}


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}

What information do you need to remember?


1. Starting state,
2. Started with 1,
3. Not started with 1
Then you assign a state to each of the possibilities
Designing DFA
Example: Design a FA for the following language:

L = {w | w contains an odd number of 1s}

What information do you need to remember?


1. even so far, and
2. odd so far.
Then you assign a state to each of the possibilities
Designing DFA

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?

Then you assign a state to each of the possibilities


Designing DFA
Designing DFA
Design a FA for the following language:

L = {w | w is a valid variable name},  = {a, b, 0, 1}.


Designing DFA
Design a FA for the following language:
L = {w | w is a floating-point number},  = {0, 1, 2, 3, .}
Example strings:
• 320, 12.0, 0.13, .21, 32.  L
• 23.1.2, 11.., .2.1, .,  L

Will accept a single .


Designing DFA
Design a FA for the following language:

L = {w | the length of w is at least 3},  = {a, b}.


Designing DFA
Design a FA for the following language:

L = {w | accepts any strings that does not contain aabb as a substring in it},
 = {a, b}.

Hint: First, design a DFA that accepts strings including aabb in it


Regular Languages
• Let L(A) be a language recognized by a DFA A.
• Then L(A) is called a “Regular Language”.
• Locate regular languages in the Chomsky Hierarchy

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)*

DFA for strings containing 01


• What makes this DFA deterministic?
• Q = {q0,q1,q2}

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

To prove this, we need to introduce a new technique called nondeterminisim.

You might also like