Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

DEPARTMENT OF COMPUTER SCIENCEANDENGINEERING

(OCT 2022 - FEB 2023)


AUTONOMOUS REGULATION 2019 - 2020

AUTOMATA AND COMPILER DESIGN

III SEMESTER

P a g e | 1AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

SYLLABUS

Subject Code Subject Name


CST34 AUTOMATA AND COMPILER DESIGN
Course Objectives:
1. To introduce the Finite Automata, NFA and DFA.
2. To gain insight into the Context Free Language and Push Down Automata.
3. To understand in depth about Parsing and Turing machine.
4. To study the Phases of a Compiler and Lexical Analysis and Syntax Analysis.
5. To acquaint the Intermediate Code Generation, Code Optimization and Code Generation.

Course Outcomes:
After completion of the course, the students will be able to
CO1 – Understand the concept of Finite Automata, NFA and DFA.
CO2 – Understand about Context Free Language and Push Down Automata.
CO3 – Construct a Turing Machine.
CO4 – Explain the concept of Phases of a Compiler, Lexical Analysis and Syntax Analysis.
CO5 – Describe the Intermediate code generation, Code Optimization and Code Generation.
UNIT – I
Finite Automata and Regular Expressions: Finite Automata - Examples and Definitions - Accepting the
Union, Intersection, or Difference of Two Languages. Regular Expressions: Regular Languages and
Regular Expressions – Conversion from Regular Expression to Deterministic Finite Automata.
UNIT – II
Context-Free Grammar And Languages And Pushdown Automata: Definitions and More Examples -
Regular Languages and Regular Grammars - Derivation Trees and Ambiguity - Simplified Forms and
Normal Forms - Chomsky Normal Form – Greibach Normal Form. Pushdown Automata: Definitions and
Examples - A PDA from a Given CFG - A CFG from a Given PDA. Pumping Lemma.
UNIT – III
Turing Machines: Turing Machines as Language Acceptors – Turing Machines for Accepting Regular
Languages – Turing Machine for Addition and Subtraction.
UNIT – IV
Lexical Analysis And Syntax Analysis: The Phases of compiler – Lexical analysis - The role of the lexical
analyser - Input buffering - Specification of tokens - Recognition of tokens - A language for specifying
lexical analyzers - design of a lexical analyzer. Parser: Top Down Parser- Predictive Parser, Bottom up
Parser- SLR Parser - Syntax directed definitions - construction of syntax trees.
UNIT – V
Intermediate Code Generation, Code Optimization And Code Generation : Declarations-Assignment
statements-Boolean expressions- Procedure calls. Code Optimization: Principle sources of optimization –
Loop Optimization. Code Generation: Issues in the design of code generator - Simple code generator -
Basic blocks and flow graphs - The DAG representation of Basic Block - Generating code form DAGs -
Peephole optimization.
Text Books:
1. John E. Hopcroft and Jeffrey D. Ullman, ‘Introduction to Automata Theory, Languages, and Computation, 3rd
Edition, Pearson Edition.
2. Alfred Aho, V. Ravi Sethi, and D. Jeffery Ullman, “Compilers Principles, Techniques and Tools”, Addison-
Wesley, 2nd Edition, 2007.
3. John C. Martin, ‘Introduction to Languages and the Theory of Computations’, McGraw Hill, 3rd Edition,
2007.

P a g e | 2AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Reference Books:
1. Mishra K.L.P, ‘Theory of Computer Science: Automata, Languages and Computation’, PHI press, 2006.
2. ‘Theory of Computation & Applications - Automata Theory Formal Languages’ - by Anil
Malviya, MalabikaDatta, BPB publications, 2015.
3. Charles N. Fischer and Richard J. Leblanc, “Crafting a Compiler with C”, Benjamin Cummings, 2009 .
Website:
1. https://www.cse.iitb.ac.in/~akg/courses/2019-cs310/index.html
2. https://www.cse.iitm.ac.in/~krishna/cs3300/
3. https://www.geeksforgeeks.org/theory-of-computation-automata-tutorials/
4. https://www.javatpoint.com/automata-tutorial
5. https://www.tutorialspoint.com/automata_theory/index.htm
6. https://nptel.ac.in/courses/106105190/CompilerDesign
7. https://freevideolectures.com/course/3051/compiler-design
8. https://cs.nyu.edu/courses/fall06/G22.2130-001/class-notes.html
9. http://www.cs.cmu.edu/~fp/courses/15411-f09/lectures/01-overview.pdf

P a g e | 3AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERINGCOLLEGE

DEPARTMENT OF COMPUTER SCIENCE ANDENGINEERING

SUBJECT NAME: AUTOMATA AND COMPILER DESIGN SUBJECT CODE:U20CST305

Prepared By:
Mr.M.Shanmugam, AP/CSE

Mr. A. Prakash, AP/CSE

Mrs. S.Deeba, AP/CSE

Verifiedby: Approvedby:

UNIT-I

Finite Automata and Regular Expressions: Finite Automata - Examples and Definitions -
Accepting the Union, Intersection, or Difference of Two Languages. Regular Expressions: Regular
Languages and Regular Expressions – Conversion from Regular Expression to Deterministic Finite
Automata.

P a g e | 4AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERINGCOLLEGE

P a g e | 5AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

2 MARKS

1. What is meant byComputations?


Computation is executing an algorithm (i.e.) it involves taking some inputs and performing required
operation on it to produce an output.

Inputx Function f Outputy=f(x)

 Computationisthesequenceofstepsthatcanbeperformedbycomputer.
 Thecomputerwhichperformscomputationisnotactualcomputerstheyare“abstractmachines”.It can
be definedmathematically.

2. Give example of abstractmachines?


 Turing Machine (Powerful as realComputers)
 Finite Automata(Simple)

3. What is a formallanguage?
Language is a set of valid strings from some alphabet. The set may be empty, finite or infinite. L(M) is the
language defined by machine M and L(G) is the language defined by context free grammar. The two
notations for specifying formal languages are:
 Grammar or regular expression (Generativeapproach)
 Automaton (Recognitionapproach)

4. What is theory ofcomputations?


The theory of computation is the branch that deals with how efficiently problems can be solved on a
model of computation, using an algorithm.
The field is divided into three major branches:
1. automatatheory,
2. computability theory,and
3. computational complexitytheory

5. What is AutomataTheory?
 Automata theory is the study of abstract machines (or abstract 'mathematical' machines or systems)
and the computational problems that can be solved using these machines. These abstract machines
are calledautomata.

P a g e | 6AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
 Automata which means that something is doing something by itself. Automata theory is also closely
related to formal language theory, as the automata are often classified by the class of formal
languages they are able to recognize. An automaton can be a finite representation of a formal
language that may be an infiniteset.

6. Why are switching circuits called as finite statesystems?


A switching circuit consists of a finite number of gates, each of which can be in any one of the two
conditions 0 or 1. Although the voltages assume infinite set of values, the electronic circuitry is designed
so that the voltages corresponding to 0 or 1 are stable and all others adjust to these values. Thus control
unit of a computer is a finite state system.

7. What are the Operations onstrings?


 Length ofstring
 Empty or nullstring
 Concatenation ofstring
 Reverse of astring
 Powers of an alphabet
 Substring
 Reversal
 KleeneClosure

8. Define alphabets inautomata?


An alphabet is a finite, non-empty set no of symbols. It is denoted by Σ.
Example:
 Σ = {a, b}, an alphabet of 2 symbols a andb.
 Σ = {0, 1, 2} an alphabet of 3 symbols 0, 1, and2.

9. Define strings withexamples?


A String or Word is a finite sequence of symbols from Σ. The group of characters also referred as a String.
Example:
 a, b, and c are symbols and abcbis astring.
 If Σ = {a,b} then abab,aabbb,aaabb,…… are all strings over the alphabet Σ={a,b}.
 0, 1, 11, 00, and 01101 are strings over{0,1}.

P a g e | 7AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
10. What is substring withexample?
Let x and y be strings over an alphabet Σ.
The string x is a substring of y if there exist strings w and z over Σ such that y = w x z.
 ε is a substring of everystring.
 For every string x, x is a substring of xitself.
Example:
 ε, comput and computation are substrings ofcomputation.

11. What is Reversal withexample?


Let x be a string over an alphabet N.The reversal of the string x, denoted by x r, is a string such that
 ifx is ε, then xrisε.
 If a is in Σ, y is in Σ* and x = a y, then xr= yr a.
(automata)r=
= (utomata)ra
= (tomata)rua
= (omata)rtua
= (mata)rotua
= (ata)rmotua
= (ta)ramotua
= (a)rtamotua
= (ε)ratamotua
= atamotua
The set of strings created from any number (0 or 1 or …) of symbols in an alphabet Σ is denoted by Σ*.

12. Explain the following a. Length of string b. Empty or nullstring?


a. Length ofstring
Let w is a string. Length of the string is |w|=> number of symbols composing the string.
Example:
1) If w=abcd then|w|=4
2) If x=01010110 the |x|=8
3) If y= 0101 the |y|=4
4) If |Є| = 0
b. Empty or nullstring
The string consisting of zero symbols. It is denoted by Є.
Example:
{Є}=0.

P a g e | 8AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
13. Define Concatenation of string and Reverse of a string?
Concatenation of string
Appending the strings (2) referred as concatenation of strings.
i.e w=a1,a2,….am
v=b1,b2,b3,……bn
then wv=a1,a2,….amb1,b2,…..bn

Example:
1. x=00 y=1
xy=001, yx=100
x=AL y=GOL
xy=ALGOL
2. Empty string is the identity element for concatenation operator. i.e
w Є= Єw=w

Reverse of a string
The reverse of a string is obtained by writing the symbols in reverse order.
Let w is the string
Reverse is wR
i.e w=a1,a2,……am
wR=am,……a2,a1
Example:
Let u=010111
uR=1101010

14. What is meant by Powers of analphabet?


Let Σ be the alphabet
Σ * is the set of all strings over alphabet Σ.
Σ m denotes the set of all strings over alphabet Σ of length m.
Example:
Σ = {0, 1}
Σ0= {Є} empty string of length 0.
Σ1= {0, 1} is the set of all strings of length one over Σ = {0, 1}
Σ2= {00, 01, 10, 11} is the set of all strings of length two over Σ = {0, 1}.

P a g e | 9AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
15. Define KleenClosure?
Let Σ be the alphabet
“ Kleen Closure”-> Σ* denotes the set of all strings (Σ) over the alphabet

Example:
If Σ ={a} the Σ*={ Є,a,aa,aaa,………}
If Σ ={0,1} theΣ*={Є,0,1,00,10,10, ........................... }
Σ0={Є}
Σ1={a}
Σ2={aa}
Therefore Σ*= Σ0U Σ1U Σ2,……………..

16. Define alanguage.


Analphabetisafiniteset ofsymbols.Alanguageisasetofstringsofsymbolsfromsomeonealphabet. e.g. If Σ
= {0,1},thenΣ*={Є,0,1,01,11,10,111, ..............................}

17. List out the applications ofautomatatheory? (APR2017)


 StringProcessing
 Analysis of algorithms
 ComplexityTheory
 Cryptography
 CompilerDesign
 Interpreters
 Parser
 Circuitdesign
 Robotics
 ArtificialIntelligence
 KnowledgeEngineering
 Natural languageProcessing

18. What are Finite Automata?Giveanexample. (NOV2015)


 Afiniteautomaton(FA)consistsof afinitesetofstates andasetoftransitions fromstatetostate that
occur on input symbols chosen from an alphabetΣ.
 Eachinputsymbolthereisexactlyonetransitionoutofeachstate(possiblybacktothestateitself).
 OneState,usuallyq0,istheinitialstate,inwhichtheautomatonstarts.
 Some states are designated as final or acceptingstates.

P a g e | 10AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Example:
Let a deterministic finite automaton be
1. Q = {a, b, c},
2. ∑ = {0, 1},
3. q0={a},
4. F={c},and
5. Transition function δ as shown by the followingtable

Present State Next State for Input 0 Next State for Input 1
a a b
b c a
c b c

Its graphical representation would be as follows −

19. How does an FAwork?


 At thebeginning,
 an FA is in the start state (initialstate)
 its tape head points at the firstcell
 For each move,FA
 reads the symbol under its tapehead
 changes its state (according to the transition function) to the next state determined by the
symbol read from the tape and its currentstate
 move its tape head to the right onecell

P a g e | 11AUTOMATA AND COMPILER DESIGN DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
20. Give the purpose of transitiondiagram?
A directed graph, called a transition diagram, is associated with an FA as follows:
 The vertices of the graph correspond to the states of theFA.
 If there is a transition from state q to state p on input a, then there is an arc labeled a from state q to
state p in the transitiondiagram.
 The FA accepts a string x if the sequence of transitions corresponding to the symbols of x leads from
the start state to an acceptingstate.

21. What is TransitionTable?


The transition table is the tabular representation of the transition function “delta (∂)” with the rows
denoting states and columns denoting input symbol.

22. What are the applications of Finite Automata(FA)?


 Software for designing and checking the behavior of digitalcircuits.
 Lexical analyzer of a typicalcompiler.
 Software for scanning large bodies of text (e.g., web pages) for patternfinding.
 Softwareforverifyingsystemsofalltypesthat haveafinitenumberofstates(e.g.,stockmarket
transaction, communication/networkprotocol).

23. Write theDFASpecifications? (NOV2016)


Deterministic Finite Automata (DFA) is generally specified by a 5 tuples (Q, Σ, δ, q0, F),
where
1. Q is a finite set ofstates
2. Σ is a finite inputalphabet
3. q0 in Q is the start state orinitialstate
4. F⊆Q is the set of finalstates
5. δis the transition function mapping δ: QX ΣQ.(i.e.) δ(q,a) is a state for each state q and
input symbola.

24. Explain working of DFA?


1. Initialisation
 Reader (read head) should be over the leftmostsymbol.
 Finite Control is in startstate.
2. SingleStep
 Reader moves to the next symbol to theright.
 Controlentersanewstatethat(deterministically)dependsoncurrentstateandcurrent
symbol. There may be no desired next state, Machine willstop.
 The machine repeats thisaction.

P a g e | 10AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
3. No currentsymbol
 All Symbols have beenread.
 If control is in final state, the input string isaccepted.
 Otherwise, the input string is not accepted.

25. What are the Applications ofDFA?


 CompilerDesign
 Design of LexicalAnalyser
 TextEditor
 PatternMatching
 File searchingProgram
 TextProcessing

26. DefineNFA. (APR-22)


Non-Deterministic Finite Automata (NFA) is generally specified by a 5 tuples (Q, Σ, δ, q0, F)
Where,
1. Q is a finite set ofstates
2. Σ is a finite inputalphabet
3. q0 in Q is the start state orinitialstate
4. F⊆Q is the set of finalstates
5. δis the transition function mapping δ Q x Σ* to2Q.

On receiving same inputs it goes to many states


 themachinecanmovewithoutconsuminganysymbolsandsometimestherearepossiblemovesand
sometimes there are move then one possiblemoves.
 the state is only partially determined by the current state andi/psymbol.

27. What are the difference between NFAandDFA? (APR2015, 2016,2017) ( NOV2015)
DFA NFA
i. For each and every state and for each and i. For each and every state and for each and everyinput
every input symbol there exists at most one symbol there exists more than onetransition.
transition. ii. The transition mapping for NFA is Q × (Σ U {ε})2Q.
ii. The transition mapping for DFA isQ×ΣQ. iii. The language accepted by NFA is denoted byL(M’).
iii. The language accepted by DFA is denoted iv. Epsilon transition ispossible.
as L(M).
iv. Epsilon transition is notpossible.

P a g e | 11AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
28. What are Transition Function and give their properties?
Changing from one state to another state on applying the
inputsProperties of Transitionfunction:
1. δ (q,ε)=q
This means the state of the system can be changed only by an input symbol else remains in original
state.
2. For all strings w and input symbol a δ(q,aw)= δ(δ(q,a),w)
Similarly δ(q,wa)=δ(δ(q,w),a)
3. The transition function δ can be extended to δ or δ that operates on states andstrings.
Basis: δ(q,ε)=q
Induction: δ (q,xa)= δ(δ(q,x),a)

29. Define finite automata with εmoves?


 The Non deterministic finite automaton with ε moves to be a quintuple (Q, Σ, δ, q 0, F) with all
components as before, but δ, the transition function, maps δ: Q × (Σ U {ε}) 2Q.
 The intention is that δ(q,a) will consists of all states p such that there is a transition labeled a fromq
top, where a is either ε or a symbol in Σ.
ε- closure (q) denotes the set of all vertices P such that there is path from q to P labeled ε.

30. Define regularexpressions? (OCT-22)


The languages accepted by finite automata are easily described by simple expressions called regular
expression.
Let Σ be an alphabet. The regular expression over Σ and the sets that they denote are defined
recursively as follows:
1. Ф is a regular expression and denotes the emptyset.
2. ε is a regular expression and denotes the set { ε}.
3. For each a ϵ Σ, ‘a’ is a regular expression and denotes the set{a}.
4. IfrandsareregularexpressionsdenotingthelanguagesRandSrespectivelythen(r+s),(rs), and
(r)* are regular expressions that denotes the sets RUS, RS and R*respectively.

P a g e | 12AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
31. What is Kleene and positiveclosure?
 The Kleene closure of L, denoted L*, is theset
L* Li
 The positive closure of L, denoted L+, is the set
L+ Li

32. What are the Identities for RegularExpression?


1. Ф + R =R
2. ФR = R Ф =Ф
3. λR = R λ =R
4. λ* = λ and Ф* =λ
5. R + R = R
6. R* R* =R*
7. RR* = R*R
8. (R*)* = R*
9. λ+ RR* = R* = λ+R*R
10. (PQ)* P = P(QP)*
11. (P + Q)* = (P* Q*)* = (P* + Q*)*
12. (P + Q)R = PR + QR and R(P +Q ) = RP + RQ

33. Give the applications offiniteautomata? (APR


2016)LexicalAnalyzers
 Tokens of a programming language are regularsets.
 Example:ALGOLidentifiers,whichareupper-orlower-caselettersfollowedbyanysequenceof
letters and digits with no limit on length, expressedas,
(letter)(letter + digit)*
where
 letter stands for A + B + …… + Z + a + b + …… +zand
 digit stands for 0 + 1 + …..+9

Text Editors
 Certain text editor and similar programs permits substitution of string for any string matching given
regularexpression.
 For example: the UNIX text editor allows a command suchas
s /bbb*/b*

P a g e | 13AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
that substitutes a single blank for the first string of two or more blanks found in a given line.
Let “any” represents expression a1+a2+…..+an.
where ai are computer characters except “newline “character.

34. Define FORTRANidentifiers?


 FORTRANidentifiers,withlengthshouldlimitedofsixandlettersrestrictedtouppercaseand
symbol $, may be expressedas
(letter)(+ letter + digit)*
Where, letter stands for ($ + A + B +……. + Z)

35. Define theSNOBOL?


 SNOBOL arithmeticconstants(donotpermittheexponentialnotation)maybeexpressedas
(+ -)(digit+ (.digit* + ) +.digit+)
 Lexicalanalyzerstakesinputassequenceofregularexpressionsdescribingthetokensandproduce a
single finite automaton recognizing the anytoken.
 Usually Regular expression to NFA with moves to NFA without moves andtoDFA.

36. Construct DFA that accepts input stings of 0’s and 1’s that end with11. (APR-22)
0 0 1
Start
q2
q0 q1
The language accepted by this automaton is L = {11, 011, 01011, and 000111}
1. Machine will be in start stateqo.
2. It will remain unchanged until it sees the input symbol‘1’.
3. On getting ‘1’ goes toq1.
4. From q1, on input symbol ‘0’ goes to qo. From q1, one i/p symbol ’1’ goes to q2(acceptancestate).
5. From q2, any number of 1 is accepted and if any 0 comes it goes to startstate.

37. Check whether given input string 0111 is accepted ornot?


Transitiontable
Input
States
0 1
* q0 {q0} {q1}
q1 {q0} {q2}
q2 {q2} {q1}

M= ({q0, q1, q2}, {0, 1}, {q1}, δ)

P a g e | 14AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Solution
Let M be the Machine. It consists of the following attributes or tuples.
M= (Q, Σ, δ, S, F)
Q= {q0, q1, q2}
Σ = {0, 1}
S=q0
F={q0}

TransitionDiagram

δ (q0, 0) ={q0}
δ (q0, 1) ={q1}
δ (q1, 1) ={q2}
δ (q2, 1) ={q1}
Here {q1} is the final state. Hence the given input string 0111 is accepted by DFA.

38. Define EquivalenceRelation?


A relation R that is reflexive, symmetric, and transitive is said to be an equivalence relation. An
important property of an equivalence relation R on a set S is that R partitions S into disjoint non-empty
equivalence classes. That is S=S1 ∪ S2 ∪…, where for each i and j, with i≠j:
1. SiSj=𝜑

2. For each a and b: n Si, aRb istrue;


3. For each a in Si and b is Sj,aRb is false.
The Si’s are called equivalenceclasses.

39. What are the applications of automatatheory?


1. In compilerconstruction.
2. In switching theory and design of digitalcircuits.
3. To verify the correctness of aprogram.
4. Design and analysis of complex software and hardwaresystems.
5. To design finite state machines such as Moore andmealymachines.

P a g e | 15AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

40. Construct NFA equivalent to theregularexpression:(0+1)01. (APR2015)


The NFA equivalent for the given Regular Expression is (0+1) 01

41. What isRegularLanguage? (APR2017)


 A language is regular if it can be expressed in terms ofregularexpression.
 Aregularlanguageisalanguagethatcanbeexpressedwitharegularexpressionoradeterministic or
non-deterministic finite automata or statemachine.
 Alanguageisaset ofstringswhicharemadeupofcharactersfrom aspecified alphabet,orset of
symbols.
 Regular languages are a subset of the set of allstrings.
 Regular languages are used in parsing and designing programminglanguages.
 Aregularlanguagecanbedefined asalanguagerecognized byafiniteautomaton.Theequivalence of
regular expressions and finite automata is known as Kleene'stheorem.

42. DefineInductionprinciple. (APR2017)


The principle of mathematical induction is that P(n) follows from
a) P(0),and
b) P(n-1) implies P(n) for n≥1.
Condition (a) in an inductive proof is called the basis, and condition (b) is called the inductive step. The
left-hand side of (b), that is P(n-1), is called the inductive hypothesis.

43. State the relations, among regular expression, deterministic finite automaton,non-deterministic
finite automaton and finite automatonwithepsilontransitions. (APR2015)

DFA NFA RE -NFA


Q×ΣQ Q × Σ 2Q (r+s), (rs), and (r)* Q × (Σ U {ε}) 2Q

P a g e | 16AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

10 MARKS

1. Explain the Operationsonstrings? (10MARKS)


The operations on Strings are
i. Length ofstring
ii. Empty or nullstring
iii. Concatenation ofstring
iv. Reverse of astring
v. Powers of an alphabet
vi. Substring
vii. Reversal
viii. KleeneClosure

Alphabets:
An alphabet is a finite, non-empty set no of symbols. It is denoted by Σ.
Example:
 Σ = {a, b}, an alphabet of 2 symbols a andb.
 Σ = {0, 1, 2} an alphabet of 3 symbols 0, 1, and2.

Strings:
A String or Word is a finite sequence of symbols from Σ. The group of characters also referred as a String.
Example:
 a, b, and c are symbols and abcbis astring.
 If Σ = {a,b} then abab,aabbb,aaabb,…… are all strings over the alphabet Σ={a,b}.
 0, 1, 11, 00, and 01101 are strings over{0,1}.

Substring:
Let x and y be strings over an alphabet Σ.
The string x is a substring of y if there exist strings w and z over Σ such that y = w x z.
 ε is a substring of everystring.
 For every string x, x is a substring of xitself.
Example:
 ε, comput and computation are substrings ofcomputation.

Reversal:
Let x be a string over an alphabet N.The reversal of the string x, denoted by x r, is a string such that
 ifx is ε, then xrisε.
 If a is in Σ, y is in Σ* and x = a y, then xr= yra.

P a g e | 17AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
(automata)r =
= (utomata)ra
= (tomata)rua
= (omata)rtua
= (mata)rotua
= (ata)rmotua
= (ta)ramotua
= (a)rtamotua
= (ε)ratamotua
= atamotua
The set of strings created from any number (0 or 1 or …) of symbols in an alphabet Σ is denoted by Σ*.

Length of string:
Let w is a string. Length of the string is |w|=> number of symbols composing the string.
Example:
1) If w=abcd then |w|=4
2) If x=01010110 the |x|=8
3) If y= 0101 the |y|=4
4) If |Є| = 0

Empty or null string:


The string consisting of zero symbols. It is denoted by Є.
Example:
{Є}=0.

Concatenation of string
Appending the strings (2) referred as concatenation of strings.
i.e w=a1,a2,….am
v=b1,b2,b3,……bn
then wv=a1,a2,….amb1,b2,…..bn

Example:
1. x=00 y=1
xy=001, yx=100
x=AL y=GOL
xy=ALGOL

P a g e | 18AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
2. Empty string is the identity element for concatenation operator. i.e
w Є=Єw=w

Reverse of a string
The reverse of a string is obtained by writing the symbols in reverse order.
Let w is the string
Reverse is wR
i.e w=a1,a2,……am
wR=am,……a2,a1

Example:
Let u=010111
uR=1101010

Powers of an alphabet:
Let Σ be the alphabet
Σ * is the set of all strings over alphabet Σ.
Σ m denotes the set of all strings over alphabet Σ of length m.

Example:
 Σ = {0,1}
 Σ0= {Є} empty string of length0.
 Σ1= {0, 1} is the set of all strings of length one over Σ = {0,1}
 Σ2={00,01,10,11}isthesetof allstringsof lengthtwooverΣ={0,1}.

Kleen Closure:
Let Σ be the alphabet
“ Kleen Closure”-> Σ* denotes the set of all strings (Σ) over the alphabet

Example:
If Σ ={a} the Σ*={ Є,a,aa,aaa,………}
If Σ ={0,1} theΣ*={Є,0,1,00,10,10, ........................... }
Σ0={Є}
Σ1={a}
Σ2={aa}
Therefore Σ*= Σ0U Σ1U Σ2,……………..

P a g e | 19AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

2. Explain in detail RegularExpressions? (10MARKS)(OCT-22)


 The languages accepted by finite automata are easily described by simple expressions called regular
expressions.
 Let Σ be a finite set of symbols and let L, L1, and L2 be sets of strings from Σ*.
The operations of regular expressionsare
1. Concatenation
2. Kleeneclosure
3. Positiveclosure
 The concatenation of L1 and L2, denoted L1L2, is the set {xy| x is in L1 and y is in L2}.That is, the
strings in L1L2 are formed by choosing a string L1 and following it by a string inL2.
 The Kleene closure of L, denoted L*, is the set
L* Li
 The positive closure of L, denoted L+, is the set
L+ Li
Let Σ be an alphabet. The regular expression over Σ and the sets that they denote are defined
recursively as follows:
1. Ф is a regular expression and denotes the emptyset.
2. ε is a regular expression and denotes the set { ε}.
3. For each a ϵ Σ, ‘a’ is a regular expression and denotes the set{a}.
4. IfrandsareregularexpressionsdenotingthelanguagesRandSrespectivelythen(r+s),(rs), and
(r)* are regular expressions that denotes the sets RUS, RS and R*respectively.

Equivalence of finite automata and regular expressions:


The language accepted by finite automata are precisely the languages denoted by regular expressions.
This equivalence for calling finite automaton languages regular sets.

P a g e | 20AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
3. Explain Deterministic Finite Automata (DFA)withanexample? (10MARKS)

FINITE STATE SYSTEMS:


 Finite Automata is a mathematical model of a system that represents discrete number of
inputsandoutputs.
 The system can be in any one of a finite number of internal configurationsorstates.
 Thestateofthesystemsummarizestheinformationconcerningpastinputsthatisneeded to
determine the behavior of the system on subsequentinputs.
 The control mechanism of an elevator is a good example of a Finite StateMachine(FSM).
 The commonly used programs such as text editors and the lexical analyzers found in most compilers
are often designed as finite statesystems.
 Forexample,a lexicalanalyzerscans thesymbols ofacomputerprogramstolocatethestring of
characters corresponding to identifiers, numerical constants, reserved wordsetc.

FINITE AUTOMATA:
 Afiniteautomaton(FA)consistsofafinitesetofstates andasetoftransitions fromstatetostatethat occur on
input symbols chosen from an alphabetΣ.
 Eachinputsymbolthereis exactlyonetransition outofeachstate(possiblybacktothestateitself).
 OneState,usuallyq0,istheinitialstate,inwhichtheautomatonstarts.
 Some states are designated as final or acceptingstates.

Finite automata are computing devices that accept/recognize regular languages and are used to model
operations of many systems we find in practice. Their operations can be simulated by a very simple.

The finite automata are of two types;


1. Deterministic Finite Automata(DFA)
2. Non-Deterministic Automata(NFA)

How does anFAwork?


 At thebeginning,
 an FA is in the start state (initialstate)
 its tape head points at the firstcell
 For each move,FA
 reads the symbol under its tapehead
 changesitsstate(accordingtothetransitionfunction)tothenext statedetermined by the
symbol read from the tape and its currentstate
 move its tape head to the right onecell

P a g e | 21AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

Transition diagram:
A directed graph, called a transition diagram, is associated with an FA as follows:
 The vertices of the graph correspond to the states of theFA.
 If there is a transition from state q to state p on input a, then there is an arc labeled a from state q to
state p in the transitiondiagram.
 The FA accepts a string x if the sequence of transitions corresponding to the symbols of x leads from
the start state to an acceptingstate.

DETERMINISTIC FINITE AUTOMATA (DFA):


Deterministic Finite Automata (DFA) is generally specified by a 5 tuples (Q, Σ, δ, q0, F)
where
1. Q is a finite set ofstates
2. Σ is a finite inputalphabet
3. q0 in Q is the start state orinitialstate
4. F⊆Q is the set of finalstates
5. δis the transition function mapping δ: QX ΣQ.(i.e.) δ(q,a) is a state for each state q and
input symbol a. (i.e.) δ(q,a) is a state for each state q and input symbola.
 AnFA as finitecontrol,whichisin somestatefromQ,reading asequenceofsymbols fromΣ
written ontape.
0 1 1 0 0 1 0 1

Finite Control

A finite automaton as a machine can also be thought of as the device shown below consisting of a tape and a
control circuit which satisfy the following conditions:
1. The tape has the left end and extends to the right without anend.
2. Thetapeis divideintosquares in eachofwhichasymbolcan bewrittenpriortothestart ofthe
operation of theautomaton.
3. The tape has a read onlyhead.
4. The head is always at the leftmost square at the beginning oftheoperation.
5. The head moves to the right one square every time it reads a symbol.
It never moves to the left. When it sees no symbol, it stops and the automaton terminates its
operation.
6. There is a finite control which determines the state of the automaton and also controls the
movement of the head.

P a g e | 22AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

 A string xis saidtobeacceptedbyafiniteautomatonM=(Q,Σ,δ,q0,F) if δ(q,x) =p forsomepinF.


 The language accepted by M, designated L (M), is the set {x| δ (q 0, x) is inF}.
 A language is a regular set if it’s the accepted by some finiteautomaton.

Example:
Consider the formal notation this FA is denoted M= (Q, Σ, δ, q0, F), where Q= {q0, q1, q2, q3}, Σ= {0, 1},
F= {q0} and δ is shown as

Transition Diagram:

Transition Table:
Inputs
States
0 1
* q0 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2

Check whether given input string 110101 are accepted or not.

Solution:
The given input string is 110101 to machine M. We denote that
δ (q0, 1) ={q1}
δ (q1, 1) ={q0}
δ (q0, 0) ={q2}
δ (q2, 1) ={q3}
δ (q3, 0) ={q1}
δ (q1, 1) ={q0}
Therefore q0 is the accepting or final state.
Hence the given input string 110101 is accepted by DFA.

P a g e | 23AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
4. Explain Non-Deterministic Finite Automata (NFA)withanexample? (10MARKS)
 Considermodifyingthefiniteautomatonmodeltoallowzero,one,ormoretransitionsfromastate
onthesameinputsymbol.This newmodelis calledaNon-DeterministicFiniteAutomata(NFA).
 Non-deterministic finite automaton is a useful concept in provingtheorems.
 NFA plays a central role in both the theory of languages and the theoryofcomputation.
 Any set accepted by a NFA can also accepted by aDFA.

NFA Mathematical Specification:


Non-Deterministic Finite Automata (NFA) is generally specified by a 5 tuples (Q, Σ, δ, q0, F) where
1. Q is a finite set ofstates
2. Σ is a finite inputalphabet
3. q0 in Q is the start state orinitialstate
4. F⊆Q is the set of finalstates
5. δis the transition function mapping δ Q x Σ* to2Q.

On receiving same inputs it goes to many states


 Themachinecanmovewithoutconsuminganysymbolsandsometimestherearepossiblemoves and
sometimes there are move then one possiblemoves.
 The state is only partially determined by the current state andi/psymbol.

Examples:
Consider the given NFA to check whether the string is accepted or not W=01001.
Transition diagram:

P a g e | 24AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Solution :
In Non-Deterministic Finite Automata (NFA), Consider a machine M= (Q, Σ, δ, q0, F),
where,
Q = {q0, q1, q2, q3, q4}
Σ = {0, 1}
{q0}=initial state
{q2, q4}=Final state

Transition table:

Input
States
0 1
 q0 {q0,q3} {q0,q1}
q1 Ф {q2}
* q2 {q2} {q2}
q3 {q4} Ф
* q4 {q4} Ф

Method1:
The given input string is 01001

δ(q0,0) = {q0,q3}

δ(q0,01) = δ (δ (q0, 0),1)


= δ ({q0, q3},1)
= δ (q0, 1) U δ (q3, 1)
= {q0, q1} U {Ф}
= {q0, q1}

δ (q0, 010) = δ (δ (q0, 01), 0)


= δ ({q0, q1}, 0)
= δ (q0, 0) U δ (q1, 0)
= {q0, q3} U {Φ}
= {q0, q3}

P a g e | 25AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
δ(q0,0100) = δ (δ (q0, 010),0)
= δ ({q0, q3}, 0)
= δ (q0, 0) U δ (q3, 0)
= {q0, q3} U {q4}
= {q0, q3, q4}

δ(q0,01001) = δ (δ (q0, 010),1)


= δ ({q0, q3, q4}, 1)
= δ (q0, 1) U δ (q3, 1) U δ (q4, 1)
= {q0, q1} U {Φ} U {q4}
= {q0, q1, q4}
The given input string 010001 is accepted by machine. Therefore q4 is the final state or accepting state.

5. Explain about Finite Automata with ε – moveswithanexample? (10MARKS)


 Inourmodelofthenon-deterministicfiniteautomaton toincludetransitionsontheemptyinputε.
 ThetransitiondiagramforNFAacceptingthelanguageconsistingofanynumber(includingzero)of 0’s
followed by any number of 1’s followed by any number of2’s.
 An NFA accepts a string ω if there is some path labeled ω from the initial state to afinalstate.
 The edges labeled ε may be included in the path, although the ε’s do not appear explicitlyinω.

For example, the string ω= 002 is accepted by NFA along the path q0, q0, q0, q1, q2, q2 with arcs labeled
0, 0, ε, ε, 2.
 The Non-deterministic finite automaton with ε-moves to be a quintuple (Q, Σ, δ, q0, F) with all
components as before, but δ, the transition function, maps δ: Q × (Σ U {ε}) 2Q.
 Theintentionis thatδ(q,a)willconsistsofallstatespsuchthatthereis atransitionlabeledafromq
top, where a is either ε or a symbol in Σ.
 ε- closure (q) denotes the set of all vertices P such that there is path from q to Plabeledε.
 Thetransitionfunction δtoafunctionδ^that mapsQ×Σ*to2Q.In thatδ^(q,w) willbeallstatespsuch that one
can go from q to palong labeled ω, perhaps including edges labeledε.

P a g e | 26AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
 For constructing δ^ is to compute the set of states reachable from a given state q using ε transitions only.
The source vertex is the vertex for state q in the transition diagram, and the directed graph consists of all
and only the arcs labeledε.
 Weuseε-CLOSURE(q)todenotethesetof allverticespsuchthatthereis apathfromqtoplabeledε.

Example:
Consider the NFA with ε given below and convert it into NFA without ε.

Solution:
Consider Non-Deterministic Finite Automata (NFA), Let a machine M= (Q, Σ, δ, q0, F),
Where,
Q = {q0, q1, q2}
Σ= {0, 1, 2}
{q0}=start state
F = {q2}

Transition Table for with ε NFA:

Inputs
States
0 1 2 ε
 q0 {q0} φ φ {q1}
q1 φ {q1} φ {q2}
* q2 φ φ {q2} φ

The ε-closure as
ε closure {q0} ={q0,q1,q2}
ε closure{q1} = {q1,q2}
ε closure{q2} = {q2}

ε closure(state) -> denotes wherever the ε state travelling from the given state continuously. We should
consider all the state. If we don’t have continuity, we have to stop the previous state.

P a g e | 27AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Let M= (Q, Σ, δ, q0, F) be NFA with ε –transition.
Let M΄= (Q, Σ, δ΄, q0, F΄) be a NFA without ε –transition.

The formula is
δ’(q0,ε) =ε-closure(q0)
= {q0, q1, q2}

δ'(q0,0) =δ^(q0,0)
= ε closure (δ (δ^ (q0, ε),0))
=εclosure(δ{q0, q1, q2},0)
= ε closure (δ (q0, 0) U δ (q1, 0) U δ (q2, 0))
= ε closure ({q0} U {φ} U {φ})
= ε closure ({q0})
= {q0, q1, q2}

δ'(q0,1) =δ^(q0,1)
= ε closure (δ (δ^ (q0, ε),1))
=εclosure(δ{q0, q1, q2},0)
= ε closure ({φ} U {q1} U {φ})
= ε closure ({q1})
= {q1, q2}

δ'(q0,2) =δ^(q0,2)
= ε closure (δ (δ^ (q0, ε),2))
=εclosure(δ{q0, q1, q2},2)
= ε closure (δ (q0, 2) U δ (q1, 2) U δ (q2, 2))
= ε closure ({φ} U {φ} U q2)
= ε closure ({q2})
= {q2}

δ'(q1,0) =δ^(q1,0)
= ε closure (δ (δ^ (q1, ε), 0))
= ε closure (δ {q1, q2}, 0)
= ε closure (δ (q1, 0) U δ (q2, 0))
= ε closure ({φ} U {φ})
= ε closure (φ)
= {φ}

P a g e | 28AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
δ'(q1,1) =δ^(q1,1)
= ε closure (δ (δ^ (q1, ε), 1))
= ε closure (δ {q1, q2}, 1)
= ε closure (δ (q1, 1) U δ (q2, 1))
= ε closure ({q1} U {φ})
= ε closure ({q1})
= {q1, q2}

δ'(q1,2) =δ^(q1,2)
= ε closure (δ (δ^ (q1, ε), 2))
= ε closure (δ {q1, q2}, 2)
= ε closure (δ (q1, 2) U δ (q2, 2))
= ε closure ({φ} U {q2})
= ε closure ({q2})
= {q2}

δ'(q2,0) =δ^(q2,0)
= ε closure (δ (δ^ (q2, ε), 0))
= ε closure (δ {q2},0)
= ε closure (δ (q2,0))
= ε closure ({φ})
= {φ}

δ'(q2,1) =δ^(q2,1)
= ε closure (δ (δ^ (q2, ε), 1))
= ε closure (δ {q2},1)
= ε closure (δ (q2,1))
= ε closure ({φ})
= {φ}

δ'(q2,2) =δ^(q2,2)
= ε closure (δ (δ^ (q2, ε), 2))
= ε closure (δ {q2},2)
= ε closure (δ (q2,2))
= ε closure ({q2})
= {q2}

P a g e | 29AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Transition Table for without ε NFA:

Inputs
States
0 1 2
* q0 {q0,q1,q2} {q1,q2} {q2}
* q1 {φ} {q1,q2} {q2}
* q2 {φ} {φ} {q2}

Transition Diagram for NFA:

6. Construct a DFA equivalent to NFA, where M = ({q0, q1, q2}, {0, 1, 2}, δ, q0, {q0, q1, q2}).
The Transition is given by the transition diagramandtransitiontable. (10MARKS)

Transition Table:

Inputs
States
0 1 2
* q0 {q0,q1,q2} {q1,q2} {q2}
* q1 {φ} {q1,q2} {q2}
* q2 {φ} {φ} {q2}

Transition Diagram:

P a g e | 30AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
CONSTRUCTING DFA:
Solution:
The equivalent DFA is M’ = (Q, {0, 1, 2}, δ’, S’, F’)
Q = {q0, q1, q2}
∑ = {0, 1, 2}
Q' = 2Q
S’= [q0] Є Q’

All subsets = { [φ],[q0],[q1],[q2],[q0,q1,q2],[q0q1],[q0q2],[q1q2][q0q1q2]}

Transition Function:

δ'(q0,0) = [q0q1q2]
δ'(q0,1) = [q1q2]
δ'(q0,2) = [q2]
δ'(q1,0) = [φ]
δ'(q1,1) = [q1q2]
δ'(q1,2) = [q2]
δ'(q2,0) =[φ]
δ'(q2,1) =[φ]
δ'(q2,2) = [q2]

δ'(q0q1,0) = δ'(q0,0) Uδ'(q1,0)


= [q0, q1, q2] U {φ}
= [q0, q1, q2]

δ'(q0q1,1) = δ'(q0,1) Uδ'(q1,1)


= [1q2] U [q1q2]
= [q1, q2]

δ'(q0q1,2) = δ'(q0,2) Uδ'(q1,2)


= [q2] U [q2]
= [q2]

δ'(q0q2,0) = δ'(q0,0) Uδ'(q2,0)


= [q0q1q2] U {φ}
= [q0q1q2]

P a g e | 31AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
δ'(q0q2,1) = δ'(q0,1) Uδ'(q2,1)
= [q1q2] U {φ}
= [q1q2]

δ'(q0q2,2) = δ'(q0,2) Uδ'(q2,2)


= [q2] U [q2]
= [q2]

δ'(q1q2,0) = δ'(q1,0) Uδ'(q2,0)


= {φ} U {φ}
= [φ]

δ'(q1q2,1) = δ'(q1,1) Uδ'(q2,1)


= [q1q2] U {φ}
= [q1q2]

δ'(q1q2,2) = δ'(q1,2) Uδ'(q2,2)


= [q2] U [q2]
= [q2]

δ'(q0q1q2,0) = δ'(q0,0) U δ'(q1,0) U δ'(q2,0)


= {q0q1q2} U {φ} U {φ}
= [q0q1q2]

δ(q0q1q2,1) = δ'(q0,1) U δ'(q1,1) U δ'(q2,1)


= [q1q2] U [q1q2] U {φ}
= [q1q2]

δ'(q0q1q2,2) = δ'(q0,2) U δ'(q1,2) U δ'(q2,2)


= [q2] U [q2] U [q2]
= [q2]

P a g e | 32AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Transition Table for DFA:

Inputs
States
0 1 2
[q0] [q0q1q2] [q1q2] [q2]
[q1] φ [q1q2] [q2]
* [q2] φ φ [q2]
[q0q1] [q0q1q2] [q1q2] [q2]
[q0q2] [q0q1q2] [q1q2] [q2]
*[q1q2] φ [q1q2] [q2]
*[q0q1q2] [q0q1q2] [q1q2] [q2]

Final States are {[q2], [q1q2], and [q0q1q2]}

Transition Diagram:

P a g e | 33AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

7. Give applications of finite automata?(5MARKS) (APR2017)


There are a variety of software design problems that are simplified by automatic conversion of regular
expression notation to an efficient computer implementation of the corresponding finite automaton.
The two applications are
1. Lexicalanalyzers
2. Text editors

LEXICAL ANALYZERS:
 Tokens of a programming language are regularsets.
 Forexample:ALGOLidentifiers,whichareupper-orlower-caselettersfollowedbyanysequenceof
letters and digits with no limit on length, expressedas,
(letter)(letter + digit)*
where
 “letter“ stands for A + B + …… + Z + a + b + …… +zand
 “digit“ stands for 0 + 1 + ….. +9
 FORTRANidentifiers,withlengthshouldlimitedofsixandlettersrestrictedtouppercaseand
symbol $, may be expressedas
(letter)(+ letter + digit)*
where, “letter” stands for ($ + A + B + ……. + Z).
 SNOBOL arithmetic constants ( which do not permit exponential notation present in many other
languages) can be expressedas
(+ -)(digit+ (.digit* + )+ .digit+)
 Anumberoflexicalanalyzerstakesinputassequenceofregularexpressionsdescribingthetokens and
produce a single finite automaton recognizing the anytoken.
 Usually, they convert the regular expression to an NFA with -transitions and then constructsubset
of states to produce a DFA directly rather than first eliminating -transitions.
 Eachfinalstateindicates theparticulartoken found,sotheautomatonis reallyaMooreMachine.
 The transition function of the FA is encoded in one of several ways to take less space than the
transition table represented as a two-dimensionalarray.
 The lexical analyzer produced by the generator is a fixed program that interprets coded tables,
together with the particular table that represents the FA recognizing thetokens.
 This lexical analyzer can be used as a module inacompiler.

P a g e | 34AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
TEXT EDITORS:
 Certain text editor and similar programs permits substitution of string for any string matching given
regularexpression.
 For example: the UNIX text editor allows a command suchas
s/bbb*/b/
that substitutes a single blank for the first string of two or more blanks found in a given line.
 Let “any” represents expression a1+a2+…..+an, where ai’s are computer characters except the
“newline“character.
 We could convert a regular expression r to a DFA that accepts any*r.
 The presence of any* allows to recognize a member of L(r) beginning anywhere in theline.
 The conversion of a regular expression to a DFA takes more time than it takes to scan a single sort
line using the DFA and the DFA have a number of states that is an exponential function of the length
of the regularexpression.
 In UNIX text editor is that Regular expression of any*r converted to an NFA with -transitions and
NFA is then simulateddirectly.
 However once a column has been constructed listing all the states the NFA can enter on a particular
prefix of the input, the previous column is no longer needed and is thrown away tosavespace.

A Logic Circuit
Deterministic finite automata have many practical applications:
1. Almost all compilers and other language-processing systems use DFA-like code to divide an input
program into tokens like identifiers, constants, and keywords and to remove comments and white
space.
2. For many applications that accept typed commands, the command language is quite complex, almost
likealittleprogramminglanguage.SuchapplicationsuseDFA-likecodetoprocesstheinputcommand.

P a g e | 35AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
3. Text processors often use DFA-like code to search a text fi le for strings that match a given pattern.
This includes most versions of UNIX tools like awk, egrep, and Procmail, along with a number of
platform-independent systems such asMySQL.
4. Speech-processing and other signal-processing systems often use a DFA-like technique to transform
an incomingsignal.
5. Controllers use DFA-like techniques to track the current state of a wide variety of finite-state systems,
from industrial processes to video games. They can be implemented in hardware orinsoftware.
6. Sometimes, the DFA-like code in such applications is generated automatically by special tools such as
lex.

8. Prove that for every regular expression there isanequivalentNFA?


(10MARKS)Statement:
Let r be a regular expression. Then there exists an NFA with ε-transitions that accepts L(r).

Proof:
We prove by induction on the number of operators in the regular expression r that there is an NFA M with
ε-transition, having one final state and no transitions out of this final state, such that L(M)= L(r).

Basis Step (Zero operators):


The expression ‘r’ must be ε (epsilon), Ф or ‘a’ for some a ϵ Σ. Then the equivalent NFA’s are (a), (b) and (c)
clearly satisfy the conditions.

Induction (One or more operators):


Assume that the theorem is true for regular expressions with fewer than i operators, i≥1. Let r have i
operators. There are three cases depending on the form of ‘r’.

Case (1):
Let r= r1+ r2. Both r1 and r2 must have fewer than i operators.
Thus there are NFA’s,
M1 = (Q1, Σ1, δ1, q1, {f1}) and M2 = (Q2, Σ2, δ2, q2, {f2}) with L(M1)= L(r1) and L(M2)= L(r2).
Assume Q1 and Q2 are disjoint. Let q0 be a new initial and f0 a new final state.
Construct M = (Q1 Q2 {q0, f0}, Σ1 Σ2, δ, {q0}, {f0}), where δ is defined by

P a g e | 36AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
1. δ(q0, ε) = {q1, q2}
2. δ(q, a) = δ1(q, a) if q ϵ Q1 {f1}, a ϵ Σ1 { ε}
3. δ(q, a) = δ2(q, a) if q ϵ Q2 {f1}, a ϵ Σ2 U {ε}
4. δ1(f1, ε)= δ1(f2, ε)= {f0}.

(a).Union

All the moves of M1 and M2 are present in M any path in the transition diagram of M from q0 to f0 must
begin by going to either Q1 or Q2 on ε. If the path goes to Q1, it may follow any path in M1 to f1 and go to f0
on ε. Similarly paths begins by going to Q2 may follow any path in M2 to f2 and then go to f0 on ε. These are
the only paths from g0 to f0. If there is a path labeled ‘x’ in M1, from Q1 to f1 or a path in M2 from q2 to f2.
Hence L(M)= L(M1) L(M2).

Case (2):
Let r= r1r2.
Let M1 = (Q1, Σ1, δ1, q1, {f1}) and M2 = (Q2, Σ2, δ2, q2, {f2}) with L(M1) = L(r1) and L(M2) = L(r2).

(b).Concatenation
Construct M = (Q1 Q2, Σ1 Σ2, δ, {q1}, {f2}),
where δ is defined as,
1. δ(q, a) = δ1(q, a) for q in Q1{f1}, a in Σ { ε}
2. δ(f1, ε) = {q2}
3. δ(q, a) = δ(q, a) for q in Q2 and a in Σ2 { ε}
Every path in M from q1 to f2 is a path labeled by some string ‘x’ from q1 to f1, followed by some string ‘y’
from q2 to f2. Thus L(M) = {xy | x is in L(M1) and y is in L(M2)}. And L(M)= L(M1)L(M2).

P a g e | 37AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Case (3):
Let r= r*. Let M1= (Q1, Σ1, δ1, q1, {f1}) and L(M1) = r1.
Construct M= (Q1 {f0}, Σ1, δ1, q0, {f0})

(c).Closure
Where δ is given by
1. δ(q0, ε) = δ(f1, ε) = {q1, f0}
2. δ(q, a) = δ1(q, a) for q in Q1 {f1} and a in Σ1 { ε}.

Any path from q0 to f0 consists either of a path from q0 to f0 or a path from q0 to q1 on ε followed by same
no. of paths from q1 to f1, then back to q1 on ε. There is a path in M from q0 to f0 labeled ‘x’ if we write
x= x1, x2, ……xj for some j≥ 0 such that each xi belongs to L(M1). Hence L(M)= L(M1*).

9. Discuss about the conversion of NFAtoDFA. (5MARKS)

S.NO DFA NFA


1 “DFA” stands for “Deterministic Finite “NFA” stands for “Nondeterministic Finite
Automata” Automata.”
2 Both are transition functions of automata. In In NFA each pair of state and input symbol can
DFA the next possible state is distinctly set have many possible next states.
3 DFA cannot use empty string transition. NFA can use empty string transition
4 It is more difficult to construct DFA. NFA is easier to construct
5 Backtracking is allowed in DFA In NFA it may or may not be allowed.
6 DFA requires more space NFA requires less space.
7 DFA can be understood as one machine and a NFA can be understood as several little machines
DFA machine can be constructed for every that compute together, and there is no possibility of
input and output, constructing an NFA machine for every input and
output.

P a g e | 38AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Steps: The method of converting NFA to its equivalent DFA. Let M = (Q, Σ, δ, q0, F) is a NFA which accepts
the language L(M). There should be equivalent DFA denoted by M’= (Q’, Σ’, δ’, q0’, F’) such that L (M) =L(M’).

The conversion method will follow following steps:


1. ThestartstateofNFA MwillbethestartforDFA M’.Henceaddq0ofNFA(startstate)toQ’.Then find the
transitions from this startstate.
2. For each state [q1,q2..qi] in Q the transition for each input symbol Σ can beobtainedas,
 δ'([q1,q2...qi],a)=δ(q1,a)Uδ(q1,a)U...........δ(qi,a)=[q1,q2...qk]maybesomestate.
 Add the state [q1,q2. qk] to DFA if it is not already added inQ’.
 Thenfind out thetransition foreveryinput symbolfromΣforstate[q1,q2.qk].ifweget somestate
[q1,q2... qn] which is not in Q’ of DFA then add this statetoQ’.
 If there is no new state generating then stop the process after finding allthetransitions.
3. For thestate[q1,q2 ....... qn] є Q’ of DFA if any one state qi is a final state of NFA then[q1,q2,,,,,qn]
becomes a final state. Thus the set of all the final states є F’ of DFA.

Example
Consider a NFA with the transition diagram

The NFA is given by


Q= {q0, q1, q2}
Σ= {a, b}
q0= {q0}
F= {q2}

Transition Table

δ a b
q0 {q0,q1} {q1}
q1 {q2} {q1,q2}
q2 φ {q2}

P a g e | 39AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Converting to DFA
The DFA can be expressed during conversion M´ = (Q, Σ, δ ´, q0, F´)
where
Q´=2Q
Σ= {a, b}
q0=q0
F´= {{q2}, {q1, q2}, {q0, q2}, {q0, q1, q2}}

Transition table for DFA


δ a b
{q0} {q0,q1} {q1}
{q1} {q2} {q1,q2}
{q2} φ {q2}
{q0,q1} {q0,q1,q2} {q1,q2}
{q1,q2} {q2} {q1,q2}
{q0,q1,q2} {q0,q1,q2} {q1,q2}

Transition diagram for DFA

P a g e | 40AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
10. Consider thefollowingε-NFA. (APR2015)
δ ε a b

p {r} {q} {p, r}

q φ {p} φ

r* {p,q} {r} {p}

(a) Compute ε-closure ofeachstate. (2 MARKS)


(b) Givetheset of allstringsof length3orlessacceptedbyautomaton.(2MARKS)
(c) Convert the given automaton to DFA. (5MARKS)

Solution:

(a) Compute the ε -closure of eachstate


ε -closure (p) = {p, q, r}
ε -closure (q) = {q}
ε -closure (r) = {p, q, r}

(b) Give all the strings of length 3 or less accepted by theautomaton.


{ε,a,b,ba,bb,aaa,aab,aba,abb,baa,bab,bba,bbb}

11. Prove: A language L is accepted by some ε-NFA if and only if L is accepted by some DFA.
(5 MARKS) (APR, NOV 2015, 2017) (APR2016)
To Prove:
The Language accepted by NFA is equal to the language set accepted by DFA.
i.e. L(M)=L(M´) ,
Where M is the NFA and M´ is the DFA.
Proof:
Let M= (Q, Σ, δ, q0, F) be an NFA, accepting L and we can define a DFA
M´ = (Q, Σ, δ´, q0, F´) as follows.
The states of M´ are all the subsets of the set of states of M.
That is, Q´ = 2Q
M´willkeep trackinitsstates ofallthestates Mcouldbein at anygiven time.F´isthesetallthestates in
Q´containingthefinalstateofM.An elementofQ´willbedenotedby[q1,q2,q3 ......................qi] are inQ.
Observe that, [q1,q2,q3 .... qi] is a single state of DFA corresponding to the states of theNFA.
Note q0´= [q0]

P a g e | 41AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
We define
δ´([q1 ,q2, q3.... qi], a)= [P1,P2,P3 ...... Pj]
if and only if
δ([q1, q2, q3....qi], a)= [P1,P2,P3 ....... Pj]
that is
δ´ applied to an element [q1, q2,q3 ........ qi]ofQ´iscomputedbyapplyingδtoeachstateofQrepresented
by [q1, q2, q3 .... qi] in applying δ to each of [q1, q2, q3 .......qi] and taking “union” we get some new set of
states P1, P2, P3 .... Pj. This new set of states has a representative P1,P2,P3 ........ Pj in Q´ and that elementis
the value of δ´([q1,q2,q3 ........qi],a).

It is easy to show by induction for the length of the input string x,that
δ´( q0´, x) =[q1,q2,q3........ qi]
if and only if,
δ( q0, x) ={q1,q2,q3 ....... qi}

Basis
Consider |x|=0 then x must be since q0´= [q0]
Then
δ´( q0, ε )=[q0]
if and only if
δ( q0, ε )= { q0}
Hence the result is trivial.

Induction
Let us assume that the hypothesis is true for inputs of length m, Let xa be a string of length m+1 with a in
Σ, then
δ´( q0’,xa ) = δ´( δ´( q0’,x),a)
By the inductive hypothesis,
δ´( q0’, x) = [P1,P2,P3 ........Pj]
If and only if ,
δ( q0, x) = {P1,P2,P3........ Pj}.
But by the definition of δ´,
δ´[(P1, P2, P3 .... Pi), a] = [r1,r2,r3 ........ rk]
If and only if,
δ({P1, P2, P3 .... Pi}, a) = [r1,r2,r3 ........ rk]
Thus,
δ´( q0, xa)= [r1,r2,r3 ....... rk]

P a g e | 42AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
If and only if,
δ(q0, xa )= [r1,r2,r3 ........ rk]
Which establishes the inductive hypothesis,
To complete the proof, we have only to add that δ´( q0’,x) is in F´ exactly when δ( q0 ) contains a state of Q
that is F.
Thus, L(M)=L(M´)

12. Construct a NFA that accept the set of all strings {a, b} ending with “aba” as substringand
constructsDFA. (5MARKS) (NOV2015) (OCT-22)
In NFA , which can formally be specified as follows

13. Prove the equivalence of NFA and DFA using subset construction with anexample.
(5 MARKS) (NOV2015)
Since every DFA is an NFA, that the class of languages accepted by NFA’s includes the regular sets (the
languages accepted by DFA’s). The DFA’s can simulate NFA’s; that is for every NFA can construct an
equivalent DFA (one which accepts the same language). The way a DFA simulates an NFA is to allow the
states of the DFA to correspond to set of states of the NFA. The constructed DFA keeps track in its finite
control of all states that the NFA could be in after reading the same input as the DFA has read.

Two finite automata M1 and M2 are equivalent if L(M1) = L(M2), that is, if they both accept the same
language.

Equivalence of NFAs and DFAs


We now show that DFAs and NFAs accept exactly the same set of languages. That is, non-determinism
does not make a finite automaton any more powerful.
To show that NFAs and DFAs accept the same class of languages, we show two things:
1. any language accepted by a DFA can also be accepted bysomeNFA.
2. anylanguageaccepted byaNFAcanalsobeaccepted bysomeDFA.

P a g e | 43AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

Proof strategy
 Toshowthat anylanguageaccepted byaNFAisalso accepted bysomeDFA,wedescribeanalgorithm that
takes any NFA and converts it into a DFA that accepts thesamelanguage.
 The algorithm is called the “subset constructionalgorithm”.
 Wecanusemathematicalinduction(onthelengthofastringacceptedbytheautomaton)toprovethat the
DFA that is constructed accepts the same language as theNFA.

Subset construction algorithm


 What does it do? Given a NFA, it constructs a DFA that accepts the samelanguage.
 What is the key idea? The equivalent DFA simulates the NFA by keeping track of the possible states it
could be in. Each state of the DFA corresponds to a subset of the set of states of the NFA -- hence, the
name of thealgorithm.
 If the NFA has n states, the DFA can have as many as 2n states (why?), although it usually hasmanyless.

Steps of subset construction algorithm


 The initial state of the DFA is the set of all states the NFA can be in without readinganyinput.
 For any state {qi ,qj…,qk} of the DFA and any input a, the next state of the DFA is the set of all states of
the NFA that can result as next states if the NFA is in any of the states qi ,qj,…,qk when it reads a. This
includes states that can be reached by reading a followed by any number of λ-transitions. Use this rule
to keep adding new states and transitions until it is no longer possible todoso.
 The accepting states of the DFA are those states that contain an accepting state oftheNFA.

Example

Here is a NFA that we want to convert to an equivalent DFA.

P a g e | 44AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

The start state of the DFA is the set of states the NFA can be in before reading any input. This includes the
start state of the NFA and any states that can be reached by a ε -transition.

For state {0,1}, we create a transition for each possible input, a and b. In the process, we create state {2}.

For state {2}, we create a transition for each possible input, a and b. In the process, we create another state,
{1,2}.

P a g e | 45AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
For state {1,2}, we create a transition for each possible input, a and b. At this point, a transition is defined for
every state-input pair.

Thelaststep istomarkthefinalstatesoftheDFA.

14. GiveDeterministicfiniteautomataacceptingthefollowinglanguageoverthealphabetnumberof 1’s


is a multiple of 3. (5 MARKS) (NOV2015)
Let we represents the symbol 1=a.
We need that the number of a's will be only multiple of 3, e.g words like aaa, baaab, bababa, bbbbaaaaaa ,…
etc, so we will put the accept state on place such that the number of a's mod (3) = 0
e.g 0 mod (3) = 0, 3 mod(3) = 0, 6 mod(3)=0,..

P a g e | 46AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
15. ProvetheequivalenceofNFA’swithorwithoutε-move. (10MARKS) (APR2017)

P a g e | 47AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERINGCOLLEGE

19. Convert the following regular expression toDFA:(a+b)*(a+b).(10MARKS)(NOV2016)(APR-22) (OCT-


22)
Step1: Converting Regular expression (a+b)* (a+b) into ε-NFA using Thomson’s Construction Rule.

Step 2: Converting ε-NFA into DFA


ε-closure(0) ={0,1,2,4, 7,8,10} A

Let this state be A


a-transition (A) =ε-closure(3,9)={1,2,4,3,6,7,8,9,10,12} B
b-transition (A) = ε-closure(5,11)={1,2,4,5,6,7,8,10,11,12} C

Let this state be B


a-transition (B) =ε-closure(3,9)={1,2,4,3,6,7,8,9,10,12} B
b-transition (B) = ε-closure(5,11)={1,2,4,5,6,7,8,10,11,12} C

Let this state be C


a-transition (C) =ε-closure(3,9)={1,2,4,3,6,7,8,9,10,12} B
b-transition (C) = ε-closure(5,11)={1,2,4,5,6,7,8,10,11,12} C

Step 3: DFA transition table


Input Symbols
States
a b
A B C
B B C
C B C

P a g e | 48AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

Step 4: DFA transition diagram

20. Construct a DFAequivalent totheregularexpression 10+(0+11)0*1. (5MARKS)(APR2017)


Step1: Converting Regular expression 10 + (0 + 11) 0*1 into ε-NFA using Thomson’s construction rule.

Step 2: Converting ε-NFA into DFA


ε-closure(0)={0,1,4,5,7} A

P a g e | 49AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

Step 3: DFA transition diagram

P a g e | 50AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
Accepting the Union, Intersection, or Difference of Two
Languages
Union process in DFA
Designing a DFA for the set of string over {a, b} such that string of the language start and end with
different symbols. There two desired language will be formed:
L1 = {ab, aab, aabab, .......}
L2 = {ba, bba, bbaba, .......}
L1= {starts with a and ends with b } and L2= {starts with b and ends with a}.
Then L= L1 ∪ L2 or L=L1 + L2

State Transition Diagram for the language L1:

This DFA accepts all the string starting with a and ending with b. Here, State A is initial state and
state C is final state.

State Transition Diagram for the language L2:

This DFA accepts all the string starting with b and ending with a. Here, State A is initial state and
state C is final state.
Now, Taking the union of L1 and L2 language which gives the final result of the language which starts
and end with different elements.

P a g e | 51AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
State Transition Diagram of L1 ∪ L2:

Thus as we see that L1 and L2 have been combined through union process and this final DFA accept all
the language containing strings starting and ending with a different symbols.

Note: From above example we can also infer that regular languages are closed under union(i.e Union
of two regular languages is also regular).

Intersection process of two DFAs


Designing a DFA for the set of string over {0, 1} such that it ends with 01 and has even number 0f 1’s.
There two desired language will be formed:

L1= {01, 001, 101, 0101, 1001, 1101, ....}


L2= {11, 011, 101, 110, 0011, 1100, .....}
L = L1 and L2 = L1 ∩ L2

P a g e | 52AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
State Transition Diagram for the language L1 :
This is a DFA for language L1

It accepts all the string that accept 01 at end.


State Transition Diagram for the language L2 :
This is a DFA for language L2

It accepts all the string that accept with even number of 1’s.

P a g e | 53AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

State Transition Diagram of L1 ∩ L2 :


Intersection of L1 and L2 can be explained by language that a string over {0, 1} accept such that it ends
with 01 and has even number of 1’s.
L = L1 ∩ L2
= {1001, 0101, 01001, 10001, ....}

Thus as we see that L1 and L2 have been combined through intersection process and this final DFA
accept all the language that has even number of 1’s and is ending with 01.

Union: F = {(q1, q2)|q1 ∈ F1or q2 ∈ F2}


Intersection: F = {(q1, q2)|q1 ∈ F1and q2 ∈ F2}
Difference:F={(q1, q2)|q1∈F1andq2ƒ∈F2}

Example :Consider two languages L1,L2 as follows

P a g e | 54AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

P a g e | 55AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE

P a g e | 56AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
QUESTIONS

2 MARKS
1. Construct NFA equivalent to the regular expression: (0+1)01. (APR 2015) (Ref.Qn.No.49,
Pg.no.18)
2. Difference between DFA and NFA? ( APR 2015, 2016, 2017) (NOV 2015) (Ref.Qn.No.27,
Pg.no.11)
3. State the relations, among regular expression, deterministic finite automaton, non-deterministic
finite automaton and finite automaton with epsilon transitions. (APR 2015) (Ref.Qn.No.52,
Pg.no.18)
4. What are Finite Automata? Give an example. (NOV 2015) (Ref.Qn.No.18,Pg.no.8)
5. Give the applications of finite automata? (APR 2016, NOV 2017) (Ref.Qn.No.41,Pg.no.15)
6. Define DFA. (NOV 2016) (Ref.Qn.No.23,Pg.no.10)
7. List out the applications of automata theory? (APR 2017) (Ref.Qn.No.17,Pg.no.8)
8. WhatisRegularLanguage?(APR2017)(Ref.Qn.No.50,Pg.no.18)
9. Define Induction principle. (APR 2017)(Ref.Qn.No.51,Pg.no.18)

10 MARKS

APRIL 2015 (REGULAR)


1. Consider thefollowingε-NFA. (Ref.Qn.No.13Pg.no.50)
δ Ε a b

p {r} {q} {p, r}

q Φ {p} φ

r* {p, q} {r} {p}

a) Compute ε-closure of each state. (3MARKS)


b) Give the set of all strings of length 3 or less accepted by automaton.(2MARKS)
c) Convert the given automaton to DFA. (5 MARKS)
(OR)
2. (a) Prove: A language L is accepted by some ε-NFA if and only if L is accepted bysomeDFA.
(5 MARKS) (Ref.Qn.No.14, Pg.no.50)
(b). Explain about the Moore and Mealy Machines. (5 MARKS) (Ref.Qn.No.9, Pg.no.40)

P a g e | 57AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
NOVEMBER 2015 (ARREAR)
1. (a).ConstructaNFAthatacceptthesetofallstrings{a,b}endingwith“aba”assubstringand
constructs DFA. (5 MARKS) (Ref.Qn.No.15,Pg.no.53)
(b). Briefly discuss about Chomsky normal form. (5MARKS) (Ref UNIT-II)
(OR)
2. (a) Prove the equivalence of NFA and DFA using subset construction. (5MARKS)
(Ref.Qn.No.14&16,Pg.no.51&53)

(b). Give Deterministic finite automata accepting the following language over the alphabet number
of 1’s is a multiple of 3. (5 MARKS) (Ref.Qn.No.17, Pg.no.56)

APRIL 2016 (REGULAR)


1. Discuss the conversion of NFA to DFA. (Ref.Qn.No.14,Pg.no.51)
(OR)
2. Explain briefly about Moore and Mealy Machines. (Ref.Qn.No.9,Pg.no.40)

NOVEMBER 2016 (ARREAR)


1. Convert the following regular expression to DFA: (a+b)* (a+b). (Ref.Qn.No.19,Pg.no.58)
(OR)
2. Minimize the givenDFA:
Q/ Σ 0 1
A B F
B G C
C A C
D C G
E H F
F C G
G G E
H G C

Also check whether the minimized DFA accepts the string “000101”.

P a g e | 58AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE


SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE
APRIL 2017 (REGULAR)
1. ProvetheequivalenceofNFA’swithorwithout ε-move.(Ref.Qn.No.18,Pg.no.57)
(OR)
2. a) Construct a DFA equivalent to the regular expression 10 + (0 + 11) 0*1. (5 MARKS)
(Ref.Qn.No.20,Pg.no.59)
b) Write down the applications of finite automata. (5 MARKS) (Ref.Qn.No.10, Pg.no.44)

NOVEMBER 2017 (ARREAR)


1. Consider the following NFA into a DFA and describe the language itaccepts.
0 1

p {p, q} {p}

q {r, s} {t}

r {p, r} {t}

*s Φ φ

*t Φ φ

(OR)
2. Prove the following: “A language L is accepted by some DFA if and only if L is accepted bysomeNFA”.
(Ref.Qn.No.14, Pg.no.51)
MAY 2018
1. Convert the following regular expressions to DFA (0+1)*(0+1)(10 Marks)
(OR)
2. Provethat“ifthereisalanguageL,suchthat L=L(A)forsomeDFAA.then thereis aregular
Expression. R such that L=L(R).(10Marks)
MAY 2019
1. Explain the steps for minimizing the states of a DFA(10Marks)
(OR)
2. Explain the method for designing a NFA from a regularexpression.(10Marks)

P a g e | 59AUTOMATA LANGUAGES AND COMPUTATIONS DEPARTMENT OF CSE

You might also like