Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views36 pages

Chapter 2 FiniteAutomata - Anim

Finite Automata (FA) is a mathematical model used to recognize patterns in strings and solve decision problems, essential in computer science and artificial intelligence. It consists of states, input symbols, a transition function, a start state, and accepting states, categorized into Deterministic (DFA) and Non-deterministic (NFA) types. DFAs are used for tasks like lexical analysis and regular expression matching, while NFAs allow for multiple state transitions but have similar computational power to DFAs.

Uploaded by

epheynyaga
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)
8 views36 pages

Chapter 2 FiniteAutomata - Anim

Finite Automata (FA) is a mathematical model used to recognize patterns in strings and solve decision problems, essential in computer science and artificial intelligence. It consists of states, input symbols, a transition function, a start state, and accepting states, categorized into Deterministic (DFA) and Non-deterministic (NFA) types. DFAs are used for tasks like lexical analysis and regular expression matching, while NFAs allow for multiple state transitions but have similar computational power to DFAs.

Uploaded by

epheynyaga
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/ 36

Finite Automata

Reading: Lecture 2

1
Finite Automata (FA)
◼ Finite Automata (FA) is a mathematical
model of computation that represents a
simple, abstract machine used to
recognize patterns in strings or solve
decision problems.
◼ It is widely used in computer science,
linguistics, and artificial intelligence for
modeling and designing systems that
require sequential logic.
2
What is Finite Automaton (FA)

◼ Finite Automata(FA) is the simplest machine to recognize


patterns.
◼ 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”
◼ Recognizers
◼ A recognition device reads input strings over the
alphabet of the language and decides whether the input
strings belong to the language
◼ Example: syntax analysis part of a compiler

3
Cont.

• Finite automata are used to recognize patterns.


• It takes the string of symbol as input and changes its state
accordingly. When the desired symbol is found, then the transition
occurs.
• At the time of transition, the automata can either move to the
next state or stay in the same state.
• Finite automata have two states, Accept state or Reject state.
When the input string is processed successfully, and the automata
reached its final state, then it will accept.

4
Finite Automata Model:

Finite Automata Model Diagram


Finite automata can be represented
by input tape and finite control.
◼ Input tape: It is a linear tape having

some number of cells. Each input


symbol is placed in each cell.
◼ Finite control: The finite control
decides the next state on receiving
particular input from input tape.
The tape reader reads the cells one
by one from left to right, and at a
time only one input symbol is read.

5
Cont.
◼ Finite Automata is an abstract machine that consists of a finite
number of states and can transition between these states
based on input symbols.
◼ It operates by reading an input string one symbol at a time and
follows specific rules to determine whether the input string is
accepted or rejected.
◼ FA is a fundamental model for:
• Lexical analysis in compilers (token recognition)
• Pattern matching (regular expressions)
• String searching algorithms (like those used in text editors)
• Control systems and decision-making processes
• Network protocols and artificial intelligence

6
2. Components of Finite Automata

A Finite Automaton consists of:


1. States (Q) – A finite set of states.
2. Alphabet (Σ) – A finite set of input symbols.
3. Transition Function (δ) – Defines state transitions based on input symbols.
4. Start State (q₀) – The state where computation begins.
5. Final/Accepting State (F) – A set of states where input is accepted.
◼ A Finite Automaton is formally represented as a 5-tuple:

◼ Where:

7
Cont : Types of Finite automata
◼ FA is characterized into
two types:
◼ 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

8
What is Introduction to Deterministic Finite Automaton (DFA)?

◼ A Deterministic Finite Automaton (DFA) is a mathematical


model of computation used to recognize patterns and
process sequential data. It is widely used in computer
science, compiler design, text processing, artificial
intelligence, and network protocols.
◼ DFA is a type of Finite Automaton that follows deterministic
rules—meaning for each input symbol, it has a single unique
transition from one state to another.
◼ DFA is particularly useful in situations where an input needs to
be processed in a linear and predictable way, such as
recognizing keywords in programming languages or validating
structured text.
9
Characteristics of DFA:

• Every state has exactly one transition for


each input symbol.
• No state has multiple transitions for the
same input symbol.
• If the automaton reaches a final state at
the end of the input, the string is
accepted.

10
Deterministic Finite Automata
◼ In DFA, for each input Graphical Representation of a DFA
symbol, one can determine ◼ A DFA is represented by
the state to which the digraphs called state diagram
The vertices represent the states.
machine will move.

◼ The arcs labeled with an input


◼ Hence, it is ◼
alphabet show the transitions.
The initial state is denoted by an
called Deterministic empty single incoming arc.

Automaton. ◼ The final state is indicated by double


circles.
◼ As it has a finite number of
states, the machine is
called Deterministic Finite
Machine or Deterministic
Finite Automaton.

11
Deterministic Finite Automata
- Definition
◼ 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, δ }

12
Cont.
Example Cont. transition Table
◼ Let a deterministic Transition function δ as shown
by the following table −
finite automaton be →
• Q = {a, b, c}, Next State Next State
Present State
• ∑ = {0, 1}, for Input 0 for Input 1

• q0 = {a}, a a b
b c a
• F = {c}, and
c b c
Its graphical representation would be as
follows −

13
What does a DFA do on
reading an input string?
◼ 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.
14
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

15
The Chomsky Hierachy
• A containment hierarchy of classes of formal languages

Regular Context-
(DFA) Context-
free Recursively-
sensitive
(PDA) enumerable
(LBA) (TM)

16
Assignment Sample question
Assuming L={W} where W is a binary
string containing 0,1 as substrings.
◼ Explain the steps for building a DFA to
recognize a language.
◼ From the above calculate accepting
state (F).
◼ Generate a transition table for above
language.
17
Example #1

Assume L={W} where W is a binary string containing


0,1 as substrings (Question1)

◼ 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”
18
Regular expression: (0+1)*01(0+1)*

DFA for strings containing 01

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


1 0 0,1 • ∑ = {0,1}
• start state = q0
start 0 1
q0 q1 q2 • F = {q2}
Accepting • Transition table
state symbols
0 1
q0 q1 q0
states

• What if the language allows q1 q1 q2


empty strings? *q2 q2 q2

19
4. Properties of DFA

◼ A. Determinism
• For each state and input symbol, there is only one possible transition.
• No state has multiple transitions for the same symbol.
◼ B. Completeness
• Every state must have a transition for every input symbol.
• If a transition is missing, a dead state (trap state) is added.
◼ C. State Minimization
• DFA can be minimized by removing redundant states while preserving behavior.
• This is done using equivalence partitioning techniques.
◼ D. Regular Language Recognition
• DFA recognizes regular languages, which can also be represented using regular
expressions.
• Example: The DFA above recognizes the *regular expression (0|1)01.

20
Cont.
A. Lexical Analysis in Compilers
• Used in programming language token recognition (e.g., recognizing keywords like if,
while, return).
• Example: DFA for recognizing identifiers in C (int, float, while).
B. Regular Expression Matching
• Used in text editors, search engines, and pattern matching tools (grep, awk).
• Example: Checking if a string contains "ab" using regex (a|b)*ab.
C. Network Protocol Design
• Used to model network protocols such as TCP connection establishment.
D. AI Decision Making & Game Theory
• DFA is used in AI models for state-based decision-making.
• Example: AI bots following finite-state machine rules in games.
E. Robotics & Embedded Systems
• Used in robot control systems and microprocessor design.

21
Limitations of DFA

A. Cannot Recognize Context-Free Languages


• DFA cannot count (e.g., cannot recognize balanced parentheses
{[( )]}).
• It cannot recognize languages requiring memory (e.g., aⁿbⁿ for n ≥
1).
B. State Explosion
• DFA may require an exponentially large number of states
when converted from NFA.
C. Cannot Handle Infinite Memory
• DFA has finite states, so it cannot solve problems requiring
unbounded memory, unlike Turing Machines.

22
NDFA
◼ In NDFA, for a particular input symbol, the
machine can move to any combination of the
states in the machine.
◼ In other words, the exact state to which the
machine moves cannot be determined.
◼ Hence, it is called Non-deterministic
Automaton.
◼ As it has finite number of states, the machine is
called Non-deterministic Finite
Machine or Non-deterministic Finite
Automaton.
23
Non-deterministic Finite
Automata (NFA)
◼ A Non-deterministic Finite Automaton
(NFA)
◼ is of course “non-deterministic”
◼ Implying that the machine can exist in more
than one state at the same time
◼ Transitions could be non-deterministic

1 qj
qi … • Each transition function therefore
1 maps to a set of states
qk
24
Non-deterministic Finite
Automata (NFA)
◼ A Non-deterministic Finite Automaton (NFA)
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 ∑ ==> subset of Q
◼ An NFA is also defined by the 5-tuple:
◼ {Q, ∑ , q0,F, δ }

25
Graphical Representation of an
NDFA
An NDFA is represented by digraphs
called state diagram.
• The vertices represent the states.
• The arcs labeled with an input alphabet show the
transitions.
• The initial state is denoted by an empty single
incoming arc.
• The final state is indicated by double circles.

26
Cont. Example
Let a non- The transition function δ as

shown below −
deterministic finite Present Next State Next State
automaton be → State for Input 0 for Input 1

• Q = {a, b, c} a a, b b
b c a, c
• ∑ = {0, 1}
c b, c c
• q0 = {a} Its graphical representation would be as
follows −
• F = {c}

27
Cont:
◼ NFA is similar to DFA except following additional features:
1. Null (or ε) move is allowed i.e., it can move forward
without reading symbols.
2. Ability to transmit to any number of states for a particular
input.
However, these above features don’t add any power to
NFA. If we compare both in terms of power, both are
equivalent.
◼ Due to above additional features, NFA has a different
transition function, rest is same as DFA.

28
How to use an NFA?
◼ Input: a word w in ∑*
◼ Question: Is w acceptable by the NFA?
◼ Steps:
◼ Start at the “start state” q0
◼ For every input symbol in the sequence w do
◼ Determine all possible next states from all current states, given
the current input symbol in w and the transition function
◼ If after all symbols in w are consumed and if at least one of
the current states is a final state then accept w;
◼ Otherwise, reject w.

29
Regular expression: (0+1)*01(0+1)*

NFA for strings containing 01

Why is this non-deterministic?


• Q = {q0,q1,q2}
0,1 0,1 •  = {0,1}
• start state = q0
start 0 1
q0 q1 q2 • F = {q2}
Final • Transition table
state symbols
0 1
What will happen if at state q1 q0 {q0,q1} {q0}
states

an input of 0 is received? q1 Φ {q2}


*q2 {q2} {q2}

30
Technologies for NFAs
◼ Micron’s Automata Processor (introduced in 2013)
◼ 2D array of MISD (multiple instruction single data)
fabric w/ thousands to millions of processing
elements.
◼ 1 input symbol = fed to all states (i.e., cores)
◼ Non-determinism using circuits
◼ http://www.micronautomata.com/

31
7. Applications of NFA
A. Lexical Analysis (Compilers)
• Used in scanners to match tokens like keywords (if, else, while).
• Regular expressions (which use NFA principles) help identify
patterns in programming languages.
B. Pattern Matching
• Regular expressions (Regex) and search algorithms use NFAs
internally.
• Example: Searching for the pattern "ab*" in a document.
C. Artificial Intelligence & Game AI
•Used for decision trees, game logic, and AI models.
•Example: AI state transitions in video games.
D. Network Protocols & Communication
•TCP/IP connection states can be modeled using NFAs.
•Protocol validation and security checks use NFAs for matching
patterns in network traffic.
E. Natural Language Processing (NLP)
•Used in syntax checking, speech recognition, and chatbot
development.
32
8. Limitations of NFA

A. Not Always Practical for Direct Implementation


•NFA can explore multiple states at once, making it difficult to
implement efficiently in hardware/software.
•Requires conversion to DFA for practical use.
B. Exponential State Growth in DFA Conversion
•If converted to a DFA, the number of states may increase
exponentially.
C. Cannot Recognize Context-Free Languages
•Like DFA, an NFA cannot recognize languages requiring memory,
such as:
•Balanced parentheses {[( )]}.
•Palindromes "racecar".
•AnBn language "aaa...bbb".

33
But, DFAs and NFAs are equivalent in their power to capture langauges !!

Differences: DFA vs. NFA


◼ DFA ◼ NFA
1. All transitions are 1. Some transitions could be
deterministic non-deterministic
◼ Each transition leads to ◼ A transition could lead to a
exactly one state subset of states
2. For each state, transition on 2. Not all symbol transitions
all possible symbols need to be defined explicitly (if
(alphabet) should be defined undefined will go to an error
3. Accepts input if the last state state – this is just a design
visited is in F convenience, not to be
4. Sometimes harder to confused with “non-
construct because of the determinism”)
number of states 3. Accepts input if one of the last
5. Practical implementation is states is in F
feasible 4. Generally easier than a DFA
to construct
5. Practical implementations
limited but emerging (e.g.,
Micron automata processor)
34
Applications
◼ Text indexing
◼ inverted indexing
◼ For each unique word in the database, store all
locations that contain it using an NFA or a DFA
◼ Find pattern P in text T
◼ Example: Google querying
◼ Extensions of this idea:
◼ PATRICIA tree, suffix tree

35
Summary
◼ DFA
◼ Definition

◼ Transition diagrams & tables

◼ Regular language
◼ NFA
◼ Definition

◼ Transition diagrams & tables

◼ DFA vs. NFA


◼ NFA to DFA conversion using subset construction
◼ Equivalency of DFA & NFA
◼ Removal of redundant states and including dead states
◼ -transitions in NFA
◼ Pigeon hole principles
◼ Text searching applications 36

You might also like