0% found this document useful (0 votes)
65 views

Chapter 1 Automata and Complexity Theory

Automata defining to use know

Uploaded by

Teshale Siyum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Chapter 1 Automata and Complexity Theory

Automata defining to use know

Uploaded by

Teshale Siyum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 113

Hawassa University

Institute of Technology
Department of Computer Science
Automata and Complexity Theory
(Theory of Computation)

2016 E.C

Tuesday, 17 October, 2023 1


Course Contents
1. Theory of Computation 3. Introduction to Turing Machine(TM)
 Standard TM
 Automata Theory
 Construction of TM
 Formal languages theory  TM Decidable and Acceptable
 Complexity Theory  Undecidable Problems
 Type of Finite Automata  Undecidability
 Turing Decidable
 Conversion of Automata  Turing Acceptable
2. Regular Languages, Expressions  Undecidable Problems
4. Computability Theory
 Regular languages and grammars  Recursive Functions
 Conversions of Res to FA  Recursive Languages(RLs)
 Construction of FA from REs  Recursive Enumerable languages(RELs)
 Context Free Languages, Grammars and 5. Computational complexity Theory
Simplifications  Big o Notation
 Class P vs NP
 Type 2 Grammars, Closure properties
 NP-Complete Problems
 CFG Simplifications  Cook’s Theorem
 Pushdown Automata(PDA)
 Construction of PDA for the given Languages
 PDA Acceptance

Tuesday, 17 October, 2023 2


Course Goals
 Theoretically explore the capabilities and limitations of computers
 Complexity of Algorithms
 How much resources are required to run the algorithms?
 Automata theory
 How can we mathematically model computation?
 Formal language Theory
 How a language defined, described, bounded & accepted?
 Complexity theory
 What makes some problems computationally hard and others easy?
 Computability theory
 What problems can be solved by a computer?
 Computational Complexity theory
 How the solution is efficient and effective enough?

Tuesday, 17 October, 2023 3


Theory of Computation: Areas
 Formal Language Theory
 language = set of sentences (strings)
 grammar = rules for generating strings
 production/deduction systems
 capabilities & limitations
 application: programming language specification
 Automata Theory (Abstract Machines)
 models for the computing process with various resources
 characterize ``computable”
 capabilities & limitations
 application: parsing algorithms
 Complexity Theory
 inherent difficulty of problems (upper and lower bounds)
 time/space resources
 intractable or unsolvable problems
 application: algorithm design

Tuesday, 17 October, 2023 4


Chapter One

Theory of Computation
Automata Theory

Tuesday, 17 October, 2023 5


What is computation?(1)
 Computation is an effective method (an Algorithm!),
which given a problem with possibly a finite number of
inputs, can produce an output which can be
recognized as a solution to the problem.
 'Effective method' is here used in the rather special sense
of a method each step of which is precisely predetermined
and which is certain to produce the answer in a finite
number of steps.

Tuesday, 17 October, 2023 6


What is computation?
 Points to note:
 The “size” of both Input and Output should be finite
 The number of steps should also be finite.
 An arbitrarily large natural number is a finite number.

Tuesday, 17 October, 2023 7


What is a Computer?
 A Computer is a physically realizable machine which
can perform computation.
 A Computer is a Formal System. This is a direct
implication of the requirement that each step in an
“Effective Method” is precisely predetermined.

Tuesday, 17 October, 2023 8


What is Theory of Computation?(1)
 It is the study about the ultimate capability of Computers, that
is what problems can be computed, what cannot and what
can only be solved partially by any computer which works
under the limitation of being “physically realizable” and
employing only “Effective Methods”.
 This requires working with abstract models of computers /
computation and as we will show, this has more to do with the nature
of problems rather than computers.

Tuesday, 17 October, 2023 9


Computation (2)
 Computation is a general term for any type of information
processing that can be represented as an algorithm precisely
(mathematically).
Examples:
 Adding two numbers in our brains, on a piece of paper or using a calculator.
 Converting a decimal number to its binary presentation or vise versa.
 Finding the greatest common divisors of two numbers.
 …etc.

Tuesday, 17 October, 2023 10


Theory of Computation(2)
 A very fundamental and traditional branch of Theory of Computation
that seeks:
1. A more tangible definition for the intuitive notion of algorithm which results in a
more concrete definition for computation.
2. Finding the set of boundaries (limitations) of computation.

Tuesday, 17 October, 2023 11


Complexity Theory
 What make some problems computational hard and others easy?(basic question)
 To solve this problems:
 Understand aspects at the root of difficulty,
 Settle for approximately perfect solution,
 Some are hard in worst case and mostly easy,
 Depending on the application, you may choose slow or quick solutions,
 Other types of computations are randomized that speed up certain tasks.
Algorithm:
 A finite sequence of simple instructions that is guaranteed to halt in a finite amount of
time.
 This is a very abstract definition, since:
 We didn’t specify the nature of this simple instructions.
 For example an instruction can be “increment a number by one” or “Calculate the triple integral”
 We didn’t specify the entity which can execute these instructions.
 For example: is this entity a person, a computer, …
 If it is a computer what is the processor type? How much memory does it have? …. ?

Tuesday, 17 October, 2023 12


Complexity Theory and Classes
 A complexity class is a set of problems of related complexity.
Complexity classes are defined by the following factors:
 Complexity classes provide a way to group languages of similar

computational complexity.
 The type of computational problem:
 The most commonly used problems are decision problems.

However, complexity classes can be defined based on function


problems, counting problems, optimization problems, promise
problems, etc.

Tuesday, 17 October, 2023 13


Complexity Theory and Classes…Cont’d
 The model of computation: The most common model of computation is
 the deterministic Turing machine, but many complexity classes are

based on
 non-deterministic Turing machines,

 Boolean circuits, quantum Turing machines,

 monotone circuits, etc.

 The resource (or resources) that is being bounded and the bound: These two
properties are usually stated together, such as "polynomial time", "logarithmic space",
"constant depth", etc.
 The set of decision problems solvable by a deterministic/non deterministic
Turing machine within time f(n). (This complexity class is known as P and NP
class with PTIME(f(n)) and NTIME(f(n)) respectively.)

Tuesday, 17 October, 2023 14


Time Space Complexity

Tuesday, 17 October, 2023 15


Complexity Theory and Classes…Cont’d

Major Classes

Tuesday, 17 October, 2023 16


Complexity Theory and Classes…Cont’d

Tuesday, 17 October, 2023 17


Complexity Theory and Classes…Cont’d

Tuesday, 17 October, 2023 18


Complexity Theory and Classes…Cont’d
 Recall that the complexity class P is the collection of all languages L that can be
recognized “efficiently", i.e., by a deterministic polynomial-time(may be(o(kn)) Turing
machine.
 Whereas the traditional definition of NP associates the class NP with the collection of
languages that can be efficiently recognized by a non-deterministic Turning machine, we
provide an alternative definition, that in our view better captures the conceptual contents
of the class.
 Informally, we view NP as the class of all languages that admit a short “certificate" for
membership in the language. Given this certificate, called a witness, membership in the
language can be verified efficiently, i.e., in polynomial time(o(n2)).
 Every computable function can be computed by a Turing machine.
 Every efficiently computable function can be efficiently computed by a Turing
machine.

Tuesday, 17 October, 2023 19


Computational Complexity Theory
 Computational complexity theory focuses on classifying computational problems according to
their resource usage, and relating these classes to each other. A computational problem is a task
solved by a computer. A computation problem is solvable by mechanical application of
mathematical steps, such as an algorithm.
 Computational complexity, a measure of the amount of computing resources (time and space)
that a particular algorithm consumes when it runs. For those problems, computer scientists seek
to find heuristic algorithms that can almost solve the problem and run in a reasonable amount of
time.
 Complexity theory helps computer scientists relate and group problems together into complexity
classes. Complexity helps determine the difficulty of a problem, often measured by how much
time and space (memory) it takes to solve a particular problem.
 Central to the development of computational complexity theory is the notion of a decision
problem. Decision problems are typically specified in the form of questions about a class of
mathematical objects whose positive instances determine the set in question

Tuesday, 17 October, 2023 20


Computational Complexity Theory …
• Aim of Complexity Theory :Classes of problems and Languages

• All Languages

Decidable
Languages

“Easy” Problems “Hard” Problems

Tuesday, 17 October, 2023 21


Complexity Theory and Classes … Examples

All
Languages
Decidable
Languages

O (n ) O (n 2 ) O (2n )
O ( n log n )

Tuesday, 17 October, 2023 22


Classifying Problems
• We have seen that decision problems (and their associated
languages) can be classified into decidable and undecidable.
• This result was obtained by Turing and others in the 1930’ - before the invention of
computers.

• After the invention of computers, it became clear that it would be


useful to classify decidable problems, to distinguish harder problems
from easier problems.
• This led to the development of computational complexity theory
in the 1960’s and 1970’s.

Tuesday, 17 October, 2023 23


Describing Decison Problems
 Problems described by functions
 functions assign ouputs to inputs
 described by tables, formulae, circuits, math logic, algorithms
Example: TRAVELLING SALESPERSON Problem
Input: n(n-1)/2 distances between n cities
Output: order to visit cities that gives shortest tour (or length of
tour)
 Problems described by languages
 ``yes/no’’ problems or decision problems
 a language represents a problem or question
 input strings in the language: answer is ``yes’’; else ``no”
Example: HALTING Problem
Input: a string w and a Turing Machine M
Output: ``yes” if ;``no” otherwise
 equivalent to asking if string
where

Tuesday, 17 October, 2023 24


What is Automata Theory?
 Study of abstract computing devices, or
“machines”
 Automaton = an abstract computing device
 Note: A “device” need not even be a physical
hardware!
 A fundamental question in computer science:
 Find out what different models of machines can do and
cannot do
 The theory of computation
 Computability vs. Complexity
Tuesday, 17 October, 2023 25
(A pioneer of automata theory)
Alan Turing (1912-1954)
 Father of Modern Computer
Science
 English mathematician
 Studied abstract machines called
Turing machines even before
computers existed
 Heard of the Turing test?

Tuesday, 17 October, 2023 26


Theory of Computation: A Historical Perspective
1930s • Alan Turing studies Turing machines
• Decidability
• Halting problem

1940-1950s • “Finite automata” machines studied


• Noam Chomsky proposes the
“Chomsky Hierarchy” for formal
languages

1969 Cook introduces “intractable” problems


or “NP-Hard” problems

1970- now Modern computer science: compilers,


computational & complexity theory evolve

Tuesday, 17 October, 2023 27


Theory of Computation … Cont’d
 Models of Computation:
 Finite Automaton(FA): Finite control (set of states). Input is read in one
direction. No memory.
 Pushdown Automaton(PDA): Finite control (set of states). Input is read in one
direction. Memory is restricted to be in the form of a stack (however the stack
length is unbounded).
 Linear Bounded Automata(LBA)- Finite control (set of states). Input is read in
two directions. Memory is restricted to be in the form of double stacks (however
the stack length is unbounded).
 Turing machines(TM):A Turing machine can be thought of as a physical
computational device consisting of a tape and a head.

Tuesday, 17 October, 2023 28


Model of Computations and Applications
• The Expressive Power of any machine can
be determined from the class or set of
Languages accepted by that particular type
of Machine. Here is the increasing sequence
of expressive power of machines :
Expressive Power of various Automata:

FA<PDA<LBA<TM
FA≡ PDA with finite Stack ≡ TM with finite tape ≡ TM with
unidirectional tape ≡ TM with read only tape

Tuesday, 17 October, 2023 29


Finite Automata
 Some Applications
 Software for designing and checking the behavior of digital
circuits
 Lexical analyzer of a typical compiler
 Software for scanning large bodies of text (e.g., web pages)
for pattern finding
 Software for verifying systems of all types that have a finite
number of states (e.g., stock market transaction,
communication/network protocol)

Tuesday, 17 October, 2023 30


Finite Automata
 Some Applications (Cont’d)
 For recognizing the pattern using regular expressions.
 For the designing of the combination and sequential
circuits using Mealy and Moore Machines.
 Used in text editors.
 For the implementation of spell checkers.

Tuesday, 17 October, 2023 31


Finite Automata : Examples
 On/Off switch action

state

 Modeling recognition of the word “then”

Start state Transition Intermediate Final state


state

Tuesday, 17 October, 2023 32


Structural expressions
 Grammars
 Regular expressions
 E.g., unix style to capture city names such as “Palo Alto
CA”:
 [A-Z][a-z]*([ ][A-Z][a-z]*)*[ ][A-Z][A-Z]

Start with a letter


A string of other
letters (possibly Should end w/ 2-letter state code
empty)

Other space delimited words


Tuesday, 17 October, 2023 (part of city name) 33
Model of Computations and Applications …Cont’d
2. Push Down Automata (PDA)
• For designing the parsing phase of a compiler (Syntax Analysis).
• For implementation of stack applications.
• For evaluating the arithmetic expressions.
• For solving the Tower of Hanoi Problem.
3. Linear Bounded Automata (LBA) LBA ≡ Finite Automata with double Stacks(2
• For implementation of genetic programming. Stacks)

• For constructing syntactic parse trees for semantic analysis of the compiler.
4. Turing Machine (TM) –
• For solving any recursively enumerable problem.
• For understanding complexity theory.
Turing Machine ≡ PDA with additional Stack ≡
• For implementation of neural networks. FA with 2 Stacks
• For implementation of Robotics Applications.
• For implementation of artificial intelligence.

Tuesday, 17 October, 2023 34


Theory of Computation … Cont’d
 A Formal Language is an abstraction of the general characteristics of programming languages.
 A formal language consists of a set of symbols and some rules of formation by which these
symbols can be combined into entities called sentences.
 A formal language is the set of all strings permitted by the rules of formation.
 Although some of the formal languages we study here are simpler than programming languages,
they have many of the same essential features.
 We can learn a great deal about programming languages from formal languages.
 Though computer science is a practical discipline, study of Formal Languages is a theoretical
approach and it can also be viewed as “Theory of Computation”.
 To start with in this chapter we will discuss about the mathematical notations and basic concepts
required to understand about the Theory of Computation.

Tuesday, 17 October, 2023 35


Theory of Automata … Cont’d
 Theory of automata is the study of abstract machines and the computation
problems that can be solved using these machines.
 The abstract machine is called the automata.

 The main motivation behind developing the automata theory was to develop

methods to describe and analyze the dynamic behavior of discrete systems.


 This automaton consists of states and transitions.
 The State is represented by circles, and the Transitions is represented

by arrows.
 Automata is the kind of machine which takes some string as input and this input
goes through a finite number of states and may enter in the final state.

Tuesday, 17 October, 2023 36


Theory of Automata …cont’d
 At this point, we have only a general understanding of what an automaton is.
 To progress, let us provide more formal and precise definitions, and start to
develop rigorous results.
 We begin with finite acceptors, which are a simple case of the general scheme
discussed already in the previous chapter.
 This type of automaton is characterized by having no temporary storage. Since,
an input file cannot be rewritten; a finite automaton is severely limited in its
capacity to “remember” things during the computation.

Tuesday, 17 October, 2023 37


Theory of Automata …cont’d
 A finite amount of information can be retained in the control unit by
placing the unit into a specific state.
 But since the number of such states is finite, a finite automaton can only
deal with situations in which the information to be stored at any time is
strictly bounded.
 The figure given below is an example of Finite Automata, which accepts
all legal Pascal identifiers.

Tuesday, 17 October, 2023 38


Finite Automata
0 1
𝑀1 0,1
1
𝑞1 𝑞2 𝑞3
0 Input: finite string
Output: Accept or Reject
States: 𝑞1 𝑞2 𝑞3
Computation process: Begin at start state,
Transitions: 1 read input symbols, follow corresponding
transitions,
Start state: Accept if end with accept state, Reject if not.

Accept states: Examples: 01101 → Accept


00101 → Reject
𝑀1 accepts exactly those strings in 𝐴 where
𝐴 = {𝑤| 𝑤 contains substring 11}.

Say that 𝐴 is the language of 𝑀1 and that 𝑀1 recognizes 𝐴 and that 𝐴 =


𝐿(𝑀1). 6
Theory of Computation … Cont’d
 In general, an Automaton is defined as a system where energy, materials and information are
transformed, transmitted and used for performing some functions without direct participation
of man, for example, automatic machine tools, automatic packing machines, and automatic
photo printing machines.
 In Computer Science the term ‘Automaton’ means “Discrete Automaton”.
 An automaton is an abstract model of a digital computer.
 As such, every automaton includes some essential features.
 Automaton mechanism for reading input. It will be assumed that the input is a string over a
given alphabet, written on an input file, which the automaton can read but not change.
 The input mechanism can read the input file left to right, one symbol at a time. The input
mechanism can also detect the end of the input string (by sensing an end-of-file condition).

Tuesday, 17 October, 2023 40


Characteristics of Finite Automata
 Inputs - It is a finite set of input symbols( or sequences of symbols, {x1, x2, x3,... ...
 Outputs - It is a finite set of output symbols, {y1, y2, y3,...ym}, where m is the number of outputs.
 States - It is a finite set of states, denoted by Q whose definition depends on the type of automaton.
 There are two main perspectives of Finite state automata- Acceptors that can tell if a string is in the
language and Generator that produces only the strings in the language.

Tuesday, 17 October, 2023 41


Finite Automata(FA) …Cont’d
 The automaton can produce output of some form.
 It may have a temporary storage device, consisting of sufficient number of cells, each
capable of holding (not necessarily the same one as the input alphabet).
 The automaton can read and change the contents of the storage cells.
 Finally, automaton has a control unit, which can be in any one of a finite number of internal
states, and which can change state is some defined manner.
 Figure shown below shows a schematic representation of a general automaton:

Tuesday, 17 October, 2023 42


Finite Automata(FA) …Cont’d
 An automaton is assumed to operate in a discrete time frame.
 At any given time, the control unit is in some internal state, and the input mechanism is scanning a
particular symbol of the input file.
 The internal state of the control unit at the next step is determined by the next-state or transition
function.
 This transition function gives the next state in terms of the current state, the current input symbol,
and the information currently in the temporary storage.
 During the transition from one time interval to the next, output may be produced or the informatio
in the temporary storage changed.
 The term Configuration will be used to refer to a particular state of the control unit, input file, and
temporary storage.
 The transition of the automaton from one configuration to the next will be called a move.

Tuesday, 17 October, 2023 43


Basic terminologies Finite Automata
 Alphabet: Any finite set of symbols in automata theory is known as Alphabet.
Represented by the letter∑ the set {a, b, c, d, e,} is called Alphabet set, whereas
the letters of set ‘a’, ‘b’, ‘c’, ‘d’, ‘e’ are called symbols.
 String: In automata, a string is a finite sequence of symbols taken from the
alphabet set ∑, For example, the string S = ‘adeaddadc’ is valid upon the alphabet
set∑ = {a, b, c, d,e,}.
 Length of String: The number of symbols present in the string is known as Length of string. For
the string S = ‘adaada’ length of the string is|S| = 6. If the length of the string is 0, then it is called
an empty string.
 Language: Language is the subset of the Kleene star set∑* for some Alphabet set
Σ. Language can be finite or infinite. For example if a language takes all the
possible strings of length 2 over the set Σ = {a, d}, then L = {aa, ad, da, dd}.

Tuesday, 17 October, 2023 44


Alphabet
An alphabet is a finite, non-empty set of symbols
 We use the symbol ∑ (sigma) to denote an alphabet

 Examples:
 Binary: ∑ = {0,1}
 All lower case letters: ∑ = {a,b,c,..z}
 Alphanumeric: ∑ = {a-z, A-Z, 0-9}
 DNA molecule letters: ∑ = {a,c,g,t}
 …

Tuesday, 17 October, 2023 45


Strings
A string or word is a finite sequence of symbols chosen from ∑
 Empty string is  (or “epsilon”)

 Length of a string w, denoted by “|w|”, is equal to the number of


(non- ) characters in the string
 E.g., x = 010100 |x| = 6
 x = 01  0  1  00  |x| = ?

 xy = concatentation of two strings x and y

Tuesday, 17 October, 2023 46


Powers of an alphabet
Let ∑ be an alphabet.

 ∑k = the set of all strings of length k

 ∑* = ∑0 U ∑1 U ∑2 U …

 ∑ + = ∑1 U ∑ 2 U ∑ 3 U …

Tuesday, 17 October, 2023 47


Languages
L is a said to be a language over alphabet ∑, only if L  ∑*
 this is because ∑* is the set of all strings (of all possible length including 0) over the
given alphabet ∑
Examples:
1. Let L be the language of all strings consisting of n 0’s followed by n 1’s:
L = {, 01, 0011, 000111,…}
2. Let L be the language of all strings of with equal number of 0’s and 1’s:
L = {, 01, 10, 0011, 1100, 0101, 1010, 1001,…}

Definition: Ø denotes the Empty language


 Let L = {}; Is L=Ø? Canonical ordering of strings in the language

NO
Tuesday, 17 October, 2023 48
The Membership Problem
Given a string w ∑*and a language L over ∑, decide
whether or not w L.

Example:
Let w = 100011
Q) Is w  the language of strings with equal number of
0s and 1s?

Tuesday, 17 October, 2023 49


Types of Finite Automata(FA)

Tuesday, 17 October, 2023 50


Types of Finite Automata(FA)
 There are two types of finite automata:
 DFA(deterministic finite automata)
 NFA(non-deterministic finite automata)

• Deterministic refers to the uniqueness of


the computation. In the DFA, the machine
goes to one state only for a particular
• It is used to transmit any
input character. DFA does not accept the
number of states for a
null move.
particular input. It can accept
• In DFA if corresponding to an input
the null move.
symbol, there is single resultant state i.e.
there is only one transition.
Tuesday, 17 October, 2023 51
Automata … DFA and NFA
 A Deterministic Automaton is one in which each move is uniquely determined by the
current configuration(Uniqueness of Computation).
 If we know the internal state, the input, and the contents of the temporary storage, we can
predict the future behavior of the automaton exactly.
 In a Nondeterministic automaton, that is not so. At each point, a Nondeterministic
automaton may have several possible moves, so we can only predict a set of possible
actions (Guess of Computations).
 An automaton whose output response is limited to a simple “yes” or “no” is called an
acceptor. Presented with an input string, an acceptor either accepts (recognizes) the string
or rejects it.
 A more general automaton, capable of producing strings of symbols as output, is called a
transducer.
Tuesday, 17 October, 2023 52
Automata … DFA and NFA
 Some interpretation is necessary:
 We assume that initially the automaton is in initial state; we indicate this by drawing an

arrow to this state.


 When the automaton is either accepting or rejecting the input string, it is said to be in any

one of the final states; we indicate this by drawing two concentric circles.
 As always, the string to be examined is read from left to right, one character at each step; when
the first symbol is a letter, the automaton goes into state 2, after which the rest of the string can
be either letter or digit.
 Finally, when the entire string is processed the state 2 “accepts” the string or represents the
“yes” state of the automaton.
 Conversely, if the first symbol is a digit, the automaton will go into state 3, the “reject” or “no”
state, and remain there.
 In our solution we assume that no input other than letters or digits is possible.
Tuesday, 17 October, 2023 53
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, δ }

54
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.

55
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

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

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

57
Example #1
 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”

58
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
q0 q1 q0

states
• What if the language allows q1 q1 q2
empty strings? *q2 q2 q2

59
Example #2
Clamping Logic:
 A clamping circuit waits for a ”1” input, and turns on forever. However, to avoid
clamping on spurious noise, we’ll design a DFA that waits for two consecutive 1s in
a row before clamping on.
 Build a DFA for the following language:
L = { w | w is a bit string which contains the substring 11}
 State Design:
 q0 : start state (initially off), also means the most recent input was not a 1
 q1: has never seen 11 but the most recent input was a 1
 q2: has seen 11 at least once

60
Example #3
 Build a DFA for the following language:
L = { w | w is a binary string that has even number of 1s
and even number of 0s}
 ?

61
Extension of transitions (δ) to Paths (δ)
 δ (q,w) = destination state from state q on input string
w

 δ (q,wa) = δ (δ(q,w), a)

 Work out example #3 using the input sequence w=10010,


a=1:

 δ (q0,wa) = ?

62
Language of a DFA
A DFA A accepts string w if there is a path from q0 to an
accepting (or final) state that is labeled by w

 i.e., L(A) = { w | δ(q0,w)  F }

 I.e., L(A) = all strings that lead to an accepting state


from q0

63
Deterministic Finite Automata(DFA)
 The first type of automaton we study in detail are Finite Automata
that are deterministic in their operation.
 A DFA is defined by the Quintuple (5-Tuples)

M = (Q, Σ, δ, q0, F)
Where, Q is finite set of internal states
Σ is a finite set of symbols called the input alphabet
δ : QX∑ → Q is a total function called the transition
function
q0 ∈ Q is the initial state
Tuesday, 17 October, 2023
F ⊆ Q is a set of Final states 64
Deterministic Finite Automaton (DFA)
Input Tape

String

Output

“Accept”
Finite or
Automaton “Reject”

Tuesday, 17 October, 2023 65


Deterministic Finite Automata(DFA)
 A Deterministic Finite Automata operates in the following manner
 At the initial time, it is assumed to be in the initial state q0, with its input
mechanism on the leftmost symbol of the input string.
 During each move of the automaton, the input mechanism advances one
position to the right(R), so each move consumes one input symbol.
 When the end of the string is reached, the string is accepted if the
automaton is in one of its final states F. Otherwise the string is rejected.
 The input mechanism can move only from left to right and reads exactly
one symbol on each step.

Tuesday, 17 October, 2023 66


Deterministic Finite Automata(DFA)
 To visualize and represent finite automata, we use transition graphs, in
which the vertices or nodes represent states and the edges represent
transitions.
 The labels on the vertices are the names of the states, while the labels on the
edges are the current values of the input symbols.
 For example, if q0 and q1 are internal states of some DFA M, then the graph
associated with M will have one vertex labeled q0 and another labeled q1.
 An edge (q0, q1) labeled ‘a’ represents the transition δ(q0, a) = q1.
 The initial state will be identified by an incoming unlabeled arrow not
originating at any vertex and final states are identified with double circle.
Tuesday, 17 October, 2023 67
Deterministic Finite Automata(DFA)
 More formally, if M = (Q, Σ, δ, q0, F) is a DFA, then its associated transition graph
Gm has exactly |Q| vertices, each one labeled with a different qi ∈ Q.
 For every transition rule δ(qi, qj) labeled ‘a’.
 The vertex associated with q0 is called the initial vertex, while those labeled with qf
∈ F are the final vertices.
 The transition graph given below represents the DFA
M = ({q0, q1, q2}, {0, 1}, δ, q0, {q1})
where δ is given by δ(q0, 0) = q0, δ(q0, 1) = q1, δ(q1, 0) = q0, δ(q1, 1) = q2,
δ(q2 , 0) = q2 , δ(q2 , 1) = q1
 This DFA accepts the input string 01. The DFA does not accept the string 00, since,
after reading two consecutive 0’s, it will be in state q0.
 By similar reasoning, we see that the automaton will accept the strings 101, 0111,
and 11001, but not 100 or 1100.
Tuesday, 17 October, 2023 68
Deterministic Finite Automata(DFA)
 It is convenient to introduce the extended transition function δ* : Qx∑* → Q
 The second argument of δ* (i.e. ∑*) is a string, rather than a single symbol, and its value gives the state the
automaton will be in after reading that string.
 For example, if δ(q0,a)=q1, and δ( q1, b)=q2 then δ*(q0,ab) = q2
 Formally, we can define δ* recursively by,
δ *(q, ε)=q Equ. (2.1)
δ *(q, wa)= δ (δ *(q, w),a) Equ (2.2)
for all q ∈ Q, w ∈ Σ*, a ∈ Σ.
 To see why this is appropriate, let us apply these definitions to the simple case above
δ *(q0, ab)= δ (δ *(q0, a),b) Equ. (2.3)
But,
δ *(q0, a)= δ (δ *(q0, ε),a)= δ(q0, a)
δ*(q0, a) =q1 Equ.(2.4)
 Now, substituting Equ (2.4) in Equ (2.3), we get, δ *(q0, ab)=δ (q1, b)=q2 as expected.
Tuesday, 17 October, 2023 69
Graphical Representation of a DFA
 A DFA 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.
 Example 1: Let a deterministic finite automaton be →
Q = {a, b, c},
∑ = {0, 1},
q0 = {a},
F = {c}, and

Tuesday, 17 October, 2023 70


DFA
• Transition function δ as shown by the following table -
Transition Functions:- (δ(a,0)= δ(a,1,R)=>b, δ(a,1)= δ(b,1,R)=>b, δ(b,0)= δ(b,0,R)=>c etc) −
States Inputs
State 0 1
• Each particular
input have only
a a b one state
• Can’t move via
b c a

c b c
• Its graphical representation would be as follows −

Tuesday, 17 October, 2023 71


Language of a DFA
A DFA A accepts string w if there is a path from q0 to an
accepting (or final) state that is labeled by w

 i.e., L(A) = { w | δ(q0,w)  F }

 I.e., L(A) = all strings that lead to an accepting state


from q0

72
Languages and DFA
 Having made a precise definition of an automaton, we are now ready to define formally what we
mean by an associated language.
 The association is obvious: the language is the set of all strings recognized by the automaton.
 The language accepted by a DFA M = (Q, Σ, δ, q0, F) is the set of all strings on Σ accepted by M.
 In formal notation, L(M) = {w ∈ Σ* : δ*(q0, w) ∈ F}
 A DFA will process every string in Σ* and either accept it or not accept it.
 Non acceptance means that the DFA stops in a non-final state, so that, L(M) = {w ∈ Σ* : δ*(q0, w)
∉ F}
 Example: Consider the DFA shown in the figure below:

Tuesday, 17 October, 2023 73


Languages and DFA …Cont’d
Can a machine(i.e., algorithm) recognize a regular language? Yes!
Deterministic Finite Automata
A deterministic finite automaton (DFA) over an alphabet A is a finite digraph (where vertices or nodes are called states) for which each
state emits one labeled edge for each letter of A. One state is designated as the start state and a set of states may be final states.
Example 2: Either of the following alternatives is acceptable for representing a DFA, where final states are indicated by double circles.

a b b
1 a, b 1
Start 0 b a Start 0 a
a 2 b 2 a, b

The Execution of DFA for input string w  A* begins at the start state and follows a path whose edges concatenate to w.
The DFA accepts w if the path ends in a final state. Otherwise the DFA rejects w. The language of a DFA is the set of
accepted strings.
Example. The example DFA accepts the strings
a, b, ab, bb, abb, bbb, …, abn, bbn, ….
So the language of the DFA is given by the regular expression (a + b)b*.
Tuesday, 17 October, 2023 74
Languages and DFA …Cont’d
 In the above figure, two labels were allowed on a single edge. Such multiple labeled edges are short
hand for two or more distinct transitions: the transition is taken whenever the input symbol matches
any of the edge labels.
 For example, the automaton in the above figure remains in its initial state q0 until the first ‘b’ is
encountered.
 If this is also the last symbol of the input, then the string is accepted.
 If not, the DFA goes into state q2, from which it can never escape. Such a state is called a trap
state.
 We can see clearly from the graph that the automaton accepts all strings which have exactly one b,
located at the rightmost position of the string.
 All other input strings are rejected. In set notation, the language accepted by this automaton is
L = {an b| n ≥ 0}

Tuesday, 17 October, 2023 75


Theorem
 Let M = (Q, Σ, δ, q0, F) be a deterministic finite acceptor, and let Gm be its
associated transition graph. Then for every qi, qj ∈ Q, and w ∈ Σ+, δ*(qi,w)=qj
if and only if there is in Gm a walk with label w from qi to qj.

Tuesday, 17 October, 2023 76


Proof of the Theorem
 It can be proved rigorously using an induction on the length of w.
 Assume that the claim is true for all strings v with |v|≤n.
 Consider then any string w of length n+1 and represent it as w = va.
 Suppose now that δ*(qi,v)=qk. Since, |v| = n, there must be a walk in Gm labeled v from
qi to qk.
 But if δ*(qi,w)=qj, then M must have a transition δ(qk,a)=qj, so that by construction Gm
has an edge (qk,qj) with label ‘a’.
 Thus, there is a walk in Gm labeled va= w between qi and qj.
 Since, the result is obviously true for n = 1, we can claim by induction that, for every w
∈ Σ+, δ*(qi,w)=qj implies that there is a walk in Gm from qi to qj labeled w.
 The argument can be turned around in a straight forward way to show that the existence
of such a path implies the, thus completing the proof.

Tuesday, 17 October, 2023 77


DFA
 Example 3: Find a Deterministic Finite Acceptor that recognizes the set of all strings on Σ={a,b}
starting with the string ab.
 The only issue here is the first two symbols in the string; after they have been
read no further decisions need to be made.
 We can therefore solve the problem with an automaton that has four states; an
initial state, two states for recognizing ‘ab’ ending in a final trap state, and one
non final trap state.
 If the first symbol is an ‘a’ and the second is a ‘b’, the automaton goes to the
final trap state, where it will stay since the rest of the input does not matter.
 On the other hand, if the first symbol is not an ‘a’ or the second one is not a ‘b’,
the automaton enters the non final trap state.

Tuesday, 17 October, 2023 78


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

79
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, δ }

80
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.

81
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}

82
Note: Omitting to explicitly show error states is just a matter of design convenience
(one that is generally followed for NFAs), and

What is an “error state”?


i.e., this feature should not be confused with the notion of non-determinism.

 A DFA for recognizing the key word “while”

w h i l e
q0 q1 q2 q3 q4 q5

Any other input symbol

 An NFA for the same purpose: qerr


Any symbol

w h i l e
q0 q1 q2 q3 q4 q5

Transitions into a dead state are implicit


83
Example #2
 Build an NFA for the following language:
L = { w | w ends in 01}
 ?
 Other examples
 Keyword recognizer (e.g., if, then, else, while, for, include,
etc.)
 Strings where the first symbol is present somewhere later
on at least once

84
Extension of δ to NFA Paths
 Basis: δ (q,) = {q}

 Induction:
 Let δ (q0,w) = {p1,p2…,pk}
 δ (pi,a) = Si for i=1,2...,k

 Then, δ (q0,wa) = S1 U S2 U … U Sk

85
Language of an NFA
 An NFA accepts w if there exists at least one path
from the start state to an accepting (or final) state that
is labeled by w
 L(N) = { w | δ(q0,w) ∩ F ≠ Φ }

86
Advantages & Caveats for NFA
 Great for modeling regular expressions
 String processing - e.g., grep, lexical analyzer

 Could a non-deterministic state machine be implemented in


practice?
 Probabilistic models could be viewed as extensions of non-deterministic state machines
(e.g., toss of a coin, a roll of dice)
 They are not the same though

 A parallel computer could exist in multiple “states” at the same time

87
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/

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

Differences: DFA vs. NFA


 DFA  NFA
1. All transitions are deterministic 1. Some transitions could be non-
 Each transition leads to exactly one state deterministic
2. For each state, transition on all possible  A transition could lead to a subset of states
symbols (alphabet) should be defined 2. Not all symbol transitions need to be
3. Accepts input if the last state visited is in F defined explicitly (if undefined will go to an
4. Sometimes harder to construct because of error state – this is just a design
the number of states convenience, not to be confused with “non-
determinism”)
5. Practical implementation is feasible 3. Accepts input if one of the last states is in
F
4. Generally easier than a DFA to construct
5. Practical implementations limited but
emerging (e.g., Micron automata
processor)

89
Equivalence of DFA & NFA
 Theorem:
Should be  A language L is accepted by a DFA if and only if it is accepted by an NFA.
true for  Proof:
any L 1. If part:
 Prove by showing every NFA can be converted to an equivalent DFA (in the next few slides…)

2. Only-if part is trivial:


 Every DFA is a special case of an NFA where each state has exactly one transition for every input
symbol. Therefore, if L is accepted by a DFA, it is accepted by a corresponding NFA.

90
Nondeterministic Finite Automata (NFA)

 Non-determinism means a choice of moves for an automaton.


 Rather than prescribing a unique move in each situation, we allow a set of possible moves.
 Formally, we achieve this by defining the transition function so that its range is a set of possible states.
 A Nondeterministic Finite Automata or NFA is defined by the quintuple.
M = (Q, Σ, δ, q0, F)
where,
Q is a finite set of internal states
Σ is a finite set of symbols called the input alphabet
q0 ∈ Q is the initial state
F ⊆ Q is a set of final states
but,
δ: Q X (Σ ∪ {ε}) → 2Q

Tuesday, 17 October, 2023 91


Graphical Representation of an NFA

 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.
 Example 1: Let a non-deterministic finite automaton be →
Q = {a, b, c}
∑ = {0, 1}
q0 = {a}
F = {c}
Tuesday, 17 October, 2023 92
NFA … Example
A. Transition Table: The transition function δ as shown below − Inputs

State State 0 1
s -At each state there are many
next states and many
a {a, b} {b} outputs(paths) at same time.

b {c} {a, c}

c {b, c} {c}

B. State Diagram: Its graphical representation would be as follows −

Tuesday, 17 October, 2023 93


NFA … Example …
 Example 2: one or more 0’s followed by one or more 1’s
L={01n ,n>=0} A. State Diagram 0/1
0 1
Q = {q0, q1, q2}
Σ = {0, 1} 0 1
q0 q1 q2
Start state is q0
F = {q2}
B. Transition Table
T. function Inputs
δ: 0 1
q0

q1 {q0, q1} {}

q2 {} {q1, q2}

{q2} {q2}

Tuesday, 17 October, 2023 94


NFA … Example …

 Example 3: The following NFA recognizes the language of a + aa*b + a*b.


A. State Diagram 1 a
L
a b
a
Start 0 2

B. Transition Table representation of NFA

T a b L
start 0 {1, 2}  {1}
1 {1} {2} 
final 2   



Tuesday, 17 October, 2023 95


NFA … Example …
 Example 4: Pair of 0’s or pair of 1’s as substring
Q = {q0, q1, q2 , q3 , q4} 0/1 0/1
A. State Diagram
Σ = {0, 1} 0 0 q4
Start state is q0 q0 q3
F = {q2, q4}
1 0/1
B. Transition Table
δ: 0 1 1
q1 q2
q0
{q0, q3} {q0, q1}

q1 {} {q2}

q2 {q2} {q2}

q3 {q4} {}

q4 {q4} {q4}

Tuesday, 17 October, 2023 96


Differences between NFA and DFA

 Note that there are two major differences between the above NFA
definition and the definition of a DFA.
1. In a NFA, the range of δ is the power set 2Q, so that its value is
not a single element of Q, but a subset of it. This subset defines
the set of all possible states that can be reached by the transition.
Example, δ(q1, a) = {q0, q2}.
2. Also we allow ε (null) as the second argument of δ. This means
that the NFA can make a transition without consuming an input
symbol.
Tuesday, 17 October, 2023 97
NFA Vs. DFA
 Like DFAs, NFA can also be represented by transition graphs.
 The vertices are determined by Q, while an edge (qi, qj) with label ‘a’ is in the graph if and only if δ(qi, a) contains
qj.
 Note that since ‘a’ may be the empty string, there can be some edges labeled ε.
 A string is accepted by an NFA if there is any sequence of possible moves that will put the machine in a final state
at the end of the string.
 Non-determinism can therefore be viewed as involving “intuitive” insight by which the best move can be chosen
at every stage (assuming that the NFA wants to accept every string).
 For example consider the transition graph shown in the figure below. It describes a nondeterministic automaton
since there are two transitions labeled ‘a’ out of q0.

Tuesday, 17 October, 2023 98


NFA Vs. DFA …

 Another nondeterministic automaton is shown in the figure below.

 It is nondeterministic not only because several edges with the same


label originate from one vertex, but also it has ε - transition.

Tuesday, 17 October, 2023 99


NFA Vs. DFA …
 Again, the transition function can be extended so its second argument is a string.
 We require of the extended transition function δ* that if δ* (qi, w) = Qj then Qj is the set of
states the automaton may be in, having started in state q all possible states and having read
‘w’.
 For an NFA, the extended transition function is defined so that δ*(qi, w) contains qj if and on
if there is a walk in the transition graph from qi to qj labeled w.
 This holds for all qi, qj ∈ Q and w ∈ Σ*
 The language L accepted by an NFA M = (Q, Σ, δ, q0, F) is defined as the set of all strings
on Σ accepted by M.
 Formally, L(M) = {w ∈ Σ* : δ*(q0, w) ∩ F ≠ ∅}.
 In words, the language contains all strings ‘w’ for which there is a walk labeled w from the
initial vertex of the transition graph to some final vertex. Where, ∅ denotes the empty set.

Tuesday, 17 October, 2023 100


DFA and NFA
Deterministic Finite Automata Non-Deterministic Finite Automata
Each transition leads to exactly one state called as A transition leads to a subset of states i.e. some
deterministic transitions can be non-deterministic.
Accepts input if the last state is in Final Accepts input if one of the last states is in Final.
Backtracking is allowed in DFA. Backtracking is not always possible.
Requires more space. Requires less space.
Empty string transitions are not seen in DFA. Permits empty string transition.
For a given state, on a given input we reach a For a given state, on a given input we reach more than
deterministic and unique state. one state.
DFA is a subset of NFA. Need to convert NFA to DFA in the design of a compiler.
Q
δ:Q×Σ→Q δ:Q×Σ→2
For example − δ(q0,a)={q1} For example − δ(q0,a)={q1,q2}
DFA is understood as one machine. NFA is understood as multiple small machines
computing at the same time.

DFA is more difficult to construct. NFA is easier to construct.


Tuesday, 17 October, 2023 101
Equivalence of NFA and DFA
 Starting now to discuss the fundamental concept – In what sense are DFAs and
NFAs different? Is there any other difference other than the definition?
 To explore this question, we introduce the notion of equivalence between
automata.
 We say that two automata are equivalent if they accept the same language.

 For any given language, we can usually find an unlimited number of equivalent
automata – deterministic or not.
 The DFA shown in Fig.(a) is equivalent to the NFA shown in Fig.(b) since,
they both accept the language {(10)n/n≥0}.

Tuesday, 17 October, 2023 102


Equivalence of NFA and DFA …
 When we compare different classes of automata, the question invariably arises whether one clas
is more powerful than the other.
 By more powerful we mean that tan automaton of one kind can achieve something that cannot be
done by any automaton of the other kind.
 Since, a DFA is a restricted kind of NFA, it is clear that any language that is accepted by a DFA
is also accepted by some NFA.
 But the converse is not so obvious.
 This means that we can actually give a way of converting any NFA into an equivalent DFA.
 The rationale for the construction is the following. After an NFA has read a string ‘w’, we may
not know exactly what state it will be in, but we can say that it must be in one state of a set of
possible states, say {qi, qj, ……, qk}.
 An equivalent DFA after reading the same string must be in some definite state.

Tuesday, 17 October, 2023 103


Equivalence of NFA and DFA …
 How can we make these two situations correspond?
 The solution is to label the states in such a way that, after reading w, the
equivalent DFA will be in a single state labeled {qi, qj, ……, qk}.
 Since for a set of |Q| states there are exactly 2|Q|subsets, the corresponding
DFA will have a finite number of states.
 We now present an algorithm for constructing from an NFA a DFA that
recognizes the same language.
 This algorithm is often called as “subset construction”, is useful for
simulating an NFA by a computer program.

Tuesday, 17 October, 2023 104


Acceptability by DFA and NDFA

 A string is accepted by a DFA/NDFA iff the DFA/NDFA starting at the initial state
ends in an accepting state (any of the final states) after reading the string wholly.
 A string S is accepted by a DFA/NDFA (Q, ∑, δ, q0, F), iff
δ*(q0, S) ∈ F
 The language L accepted by DFA/NDFA is
{S | S ∈ ∑* and δ*(q0, S) ∈ F}
 A string S′ is not accepted by a DFA/NDFA (Q, ∑, δ, q0, F), iff
δ*(q0, S′) ∉ F
 The language L′ not accepted by DFA/NDFA (Complement of accepted language
L) is
{S | S ∈ ∑* and δ*(q0, S) ∉ F}

Tuesday, 17 October, 2023 105


Acceptability by DFA and NFA …
 Example: Let us consider the DFA shown in Figure below from the DFA, the
acceptable strings can be derived.

• Strings accepted by the above DFA: {0, 00, 11, 010, 101, ...........}
• Strings not accepted by the above DFA: {1, 011, 111, ........}

Tuesday, 17 October, 2023 106


Regular Languages
 Every Finite automaton accepts some language.
 If we consider all possible finite automata, we get a set of languages

associated with them.


 We will call such a set of languages a family.

 The family of languages that is accepted by deterministic finite automata is

quite limited.
 A language L is called regular if and only if there exists some deterministic

finite accepter M such that


L = L(M)
 Precisely, a language can be claimed as regular if a DFA can be constructed

for 2023
Tuesday, 17 October, it. 107
Regular Languages …
 For example: Show that the language L={awa|w ∈ {a,b}*} is regular.

Tuesday, 17 October, 2023 108


Conversion NFA to DFA
 Let X = (Qx, ∑, δx, q0, Fx) be an NFA which accepts the language L(X). We have
to design an equivalent DFA Y = (Qy, ∑, δy, q0, Fy) such that L(Y) = L(X).
 The following procedure converts the NDFA to its equivalent DFA:

Algorithm
Input − An NDFA
Output − An equivalent DFA
Step 1 − Create state table from the given NDFA.
Step 2 − Create a blank state table under possible input alphabets for the equivalent
DFA.
Step 3 − Mark the start state of the DFA by q0 (Same as the NDFA).
Step 4 − Find out the combination of States {Q0, Q1,... , Qn} for each possible input
alphabet.
Step 5 − Each time we generate a new DFA state under the input alphabet columns,
we have to apply step 4 again, otherwise go to step 6.
Step 6 − The states which contain any of the final states of the NDFA are the final
states of the equivalent DFA.

Tuesday, 17 October, 2023 109


Conversion NFA to DFA
 Example 1: Let us consider the NDFA shown in the figure

below.

q δ(q,0) δ(q,1)
a {a,b,c,d,e} {d,e}
b {c} {e}
c ∅ {b}
d {e} ∅
e ∅ ∅
Tuesday, 17 October, 2023 110
Conversion NFA to DFA
• Using the above algorithm, we find its equivalent DFA. The state table of the DFA is shown in
below.

q δ(q,0) δ(q,1)
[a] [a,b,c,d,e] [d,e]
[a,b,c,d,e] [a,b,c,d,e] [b,d,e]
[d,e] [e] ∅
[b,d,e] [c,e] [e]
[e] ∅ ∅
[c, e] ∅ [b]
[b] [c] [e]
[c] ∅ [b]

Tuesday, 17 October, 2023 111


Conversion NFA to DFA
 The state diagram of the DFA is as follows −

Tuesday, 17 October, 2023 112


Tuesday, 17 October, 2023 113

You might also like