0% found this document useful (0 votes)
9 views147 pages

Lm-Flat

The document is a handout on Formal Languages and Automata Theory for II Year II Semester Computer Science and Engineering students at Gudlavalleru Engineering College. It outlines the vision, mission, program educational objectives, course objectives, outcomes, and a detailed syllabus covering topics such as finite automata, context-free grammars, and Turing machines. Additionally, it includes prescribed textbooks, reference materials, and a lecture schedule for the course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views147 pages

Lm-Flat

The document is a handout on Formal Languages and Automata Theory for II Year II Semester Computer Science and Engineering students at Gudlavalleru Engineering College. It outlines the vision, mission, program educational objectives, course objectives, outcomes, and a detailed syllabus covering topics such as finite automata, context-free grammars, and Turing machines. Additionally, it includes prescribed textbooks, reference materials, and a lecture schedule for the course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 147

FormalLanguagesandAutomataTheory 1

GUDLAVALLERUENGINEERINGCOLLEGE
(AnAutonomousInstitutewithPermanentAffiliationtoJNTUK,Kakinada)

SeshadriRaoKnowledgeVillage,Gudlavalleru–521356.

DepartmentofComputerScienceandEngineering

HANDOUT
on
FORMALLANGUAGESANDAUTOMATATHEORY

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 2

Vision
To be a Centre of Excellence in computer science and
engineering education and training to meet the challenging
needs of the industry and society.

Mission

➢ To impart quality education through well-designed curriculum


in tune withthegrowingsoftwareneedsoftheindustry.

➢ To serve our students by inculcating in them problem solving,


leadership, teamwork skills and the value of commitment to
quality, ethicalbehavior&respectforothers.

➢ Tofosterindustry-academiarelationshipformutualbenefitandgrowth.

ProgramEducationalObjectives

PEO1:Identify, analyze, formulate and solve Computer Science and


Engineering problems both independently and in a
team environmentbyusingtheappropriatemoderntools.

PEO2:Manage software projects with significant technical, legal,


ethical, social,environmentalandeconomicconsiderations.

PEO3: Demonstrate commitment and progress in lifelong learning,


professional development, leadershipand Communicate
effectively with professional clients and the public .

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 3

HANDOUTONFORMAL LANGUAGESANDAUTOMATATHEORY

Class&Sem.:IIB.Tech–IISemester Year :2018-19


Branch :CSE Credits:3
=========================================================================
1. BriefHistoryand ScopeoftheSubject
Computersciencehastwomajorcomponents:
1) thefundamentalideasandmodelsunderlyingcomputing,
2) Engineering techniques for the design of computing systems,
both
hardwareandsoftware,especiallytheapplicationoftheorytodesign.
Thissubjectisintendedasanintroductiontothefirstarea,thefundame
ntal ideas underlying computing.
Theoretical computer science had its beginnings in a number of
diverse fields: biologists studying models for neuron nets,
electrical engineers developing switching theory as a tool to
hardware design, mathematicians
workingonthefoundationsoflogic,andlinguistsinvestigatinggramm
arsfor natural languages. Out of these studies came models that
are central to theoretical computer science.
The notions of finite automata and regular expressions (Units 1,
2 and 3) were originally developed with neuron nets and
switching circuits in mind.
Recently,theyhaveservedasusefultoolsinthedesignoflexicalanalyz
ers, the part of a compiler that groups characters into tokens-
indivisible units such as variable names and keywords. A number
of compiler-writing
systemsautomaticallytransformregularexpressionsintofiniteauto
matafor use as lexical analyzers. A number of other uses for regular
expressions and finite automata have been found in text editors,
pattern matching, various text-processing and file-searching
programs, and as mathematical concepts
IIYear–II-Semester 2018-19 CSE
FormalLanguagesandAutomataTheory 4

withapplicationtootherareas, suchaslogic.
The notion of a context-free grammar and the corresponding
pushdown automaton (Units 4 and 5) has aided immensely the
specification of programminglanguagesandinthedesignofparsers-
anotherkeyportionof

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 5

acompiler.Formalspecificationsofprogramminglanguageshaverepl
aced extensive and often incomplete or ambiguous descriptions
of languages. Understanding the capabilities of the pushdown
automaton has greatly simplified parsing. In early compilers,
parser design is a difficult problem, and many of the early
parsers were quite inefficient and unnecessarily restrictive. Based
on context-free-grammar-based techniques, parser design
isnolongeraproblem,andparsingoccupiesonlyafewpercentofthetim
e spent in typical compilation.
In Unit 6, we deal with Turing machines and one of the
fundamental problems of computer science; there are
algorithms for computing
functions.Therearefunctionsthataresimplynotcomputable;thatis,t
here isnocomputerprogramthatcaneverbewritten.

2. Pre-Requisites
• MathematicalFoundationofComputerScience
3. CourseObjectives:
• Tointroducetheclassificationofmachinesbytheirpowertorecogn
ize languagesandtosolveproblemsincomputing.
• To familiarizehow to employ deterministic and non-
deterministic machines.
CourseOutcomes:
CO1:comparetheautomatabasedontheirrecognizingpowe
r. CO2: design finite automata for regular languages.
CO3:reduceDFAbyapplyingminimizationalgorithm.
CO4: write regular expressions for regular languages or for DFA by
applying Arden’s theorem.
CO5:generategrammarforCFL’s.
CO6: use algorithm to simplify
grammar.CO7:designPDA‘sforcontextfreel
IIYear–II-Semester 2018-19 CSE
FormalLanguagesandAutomataTheory 6

anguages.
CO8:designTuringMachineforthephrase-structuredlanguages.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 7

4. ProgramOutcomes:
EngineeringGraduateswillbeableto:
1. Engineering knowledge:Apply the knowledge of mathematics,
science, engineering fundamentals, and an engineering
specialization to the solution ofcomplexengineeringproblems.
2. Problem analysis:Identify, formulate, review research literature,
and analyze complex engineering problems reaching substantiated
conclusions using first principles of mathematics, natural
sciences, and engineering sciences.
3. Design/development of solutions:Design solutions for complex
engineering problems and design system components or
processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
4. Conduct investigations of complex problems:Use research-based
knowledge and research methods including design of experiments,
analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
5. Modern tool usage:Create, select, and apply appropriate
techniques, resources, and modern engineering and IT tools
including prediction and modeling to complex engineering
activities with an understanding of the limitations.
6. The engineer and society:Apply reasoning informed by the
contextual knowledgetoassesssocietal,health,safety,legal
andculturalissuesand the consequent responsibilities relevant to
the professional engineering practice.
7. Environment and sustainability:Understand the impact of the
professionalengineeringsolutionsinsocietalandenvironmentalcon
texts, and demonstrate the knowledge of, and need for sustainable
development.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 8

8. Ethics:Apply ethical principles and commit to professional ethics


and responsibilitiesandnormsoftheengineeringpractice.
9. Individualandteamwork:Functioneffectivelyasanindividual,andasa
memberorleaderindiverseteams,andinmultidisciplinarysettings.
10. Communication:Communicate effectively on complex engineering
activities with the engineering community and with society at
large, such as, being able to comprehend and write effective
reports and design documentation, make effective presentations,
and give and receive clear instructions.
11. Project management and finance:Demonstrate knowledge and
understanding of the engineering and management principles
and apply these to one’s own work, as a member and leader in a
team, to manage projects and in multidisciplinary environments.
12. Life-
longlearning:Recognizetheneedfor,andhavethepreparationand
ability to engage in independent and life-long learning in the
broadest contextoftechnologicalchange.

5. MappingofCourseOutcomeswithProgramOutcomes:
1 2 3 4 5 6 7 8 9 10 11 12
CO1 H H H
CO2 H L H
CO3 H L H
CO4 M H
CO5 H M M
CO6 M
CO7 M H L M
CO8 M H L M

6. PrescribedTextBooks
1. John E.Hopcroft, Rajeev Motwani& Jeffrey D.Ullman J.D.,
“Introduction to Automata Theory Languages and Computation”,
3rd edition, Pearson Education.
2. LewisH.R.,Papdimitriou,“ElementsofTheoryofComputation”,2 ndedi
tion, PHI.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 9

7. ReferenceBooks
1. DanielI.A.Cohen,JohnWiley,“IntroductiontolanguagesandtheTheoryof
Computation”.
2. Sipser,Thomson,“IntroductiontoTheoryofComputation”,2 ndedition.
3. Mishra and Chandrashekaran, “Theory of computer science - Automata,
Languages, and Computation”, 2ndedition, PHI.
4. K.KrithivasanandR.Rama;IntroductiontoFormalLanguages,AutomataTheorya
nd Computation; Pearson Education, 2009.

8. URLsandOtherE-LearningResources
1. BasisforaMathematicalTOC:http://www-formal.stanford.edu/jmc/basis1.pdf
2. Finite Automta:
http://www.cs.odu.edu/~toida/nerzic/390teched/regular/fa/intr_2_fa.html
3. PDA:https://brilliant.org/wiki/pushdown- automata/
4. TuringMachine:http://plato.stanford.edu/entries/turing-machine

9. DigitalLearningMaterials:

• http://nptel.ac.in/courses/106104028/
• http://nptel.ac.in/courses/106104148/
• http://nptel.ac.in/courses/106106049/

10. LectureSchedule/LessonPlan

No.ofPeriods
Topic
TheoryTutorial

UNIT–1:Fundamentals

Strings,Alphabet,Language,Operationsonstrings 1

Operationsonlanguages,FiniteStateSystem 1 1

FiniteAutomatonModel 1

Acceptanceofstringsandlanguages 1

Deterministicfiniteautomaton 2
2
Nondeterministicfiniteautomaton 2

Transitiondiagrams,languagerecognizersandapplicationsofFiniteAutomata 2

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 10

Total 10+3(T)

UNIT–2:Finite Automata

NFAwithεtransitions–significance,acceptance ofalanguagebyaε–NFA 1

EquivalencebetweenNFAwithandwithoutεtransitions 2

Minimizationof FSM 2 1

NFAtoDFA conversion 1

equivalencebetweentwoFSM‘s 1

Finiteautomatawithoutputs-Mooremachine,Mealymachines 1

MooretoMealyCoversion-examples 1 1

MealytoMooreconversion-examples 1

Total 10+2(T)

UNIT– 3:RegularLanguages

RegularSets,IdentityRules 1
1
Regularexpressions 2

ConstructionoffiniteAutomata fora givenregularexpressions 1

ConstructionofregularexpressionforagivenfiniteAutomata 1
1
Pumpinglemmaofregularsets 1

Closurepropertiesofregularsets,applicationsofregularlanguages. 1

Total 7+2(T)

UNIT–4:Grammar Formalism

Chomskyhierarchyoflanguages 1

Regulargrammars-rightlinearandleftlineargrammars-examples 1
1
EquivalencebetweenregularlineargrammarandFA 1

EquivalencebetweenFAandregulargrammar 1

Contextfreegrammar-examples 2

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 11

Derivation-Rightmostandleftmostderivationofstrings,sententialforms,
2 1
Derivation trees

Total 8+2(T)

UNIT– 5:ContextFreeGrammars

Ambiguityincontext freegrammars 1

MinimizationofContextFreeGrammars 1

Chomskynormal form 1

Greibachnormalform 2
1
PumpingLemmaforContextFreeLanguages 1

EnumerationofPropertiesofCFL(proofsnotrequired),applicationsof CFLs
1

Pushdownautomata,modelofPDA 1

DesignofPDA 2 1

ApplicationsofPDA 1

Total 11+2(T)

UNIT– 6:TuringMachine

TuringMachine,model 1
1
DesignofTM 2

TypesofTuringMachines 1

Computablefunctions 1
1
Recursivelyenumerablelanguages,Recursivelanguages 1

Decidabilityofproblems 1

Undecidabilityofpostscorrespondenceproblem 1

Total 8+2(T)

TotalNo.ofPeriods: 54 13(T)

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 12

FORMALLANGUAGESANDAUTOMATATHEORY

UNIT-I

Objective:
• Tointroducetheclassificationofmachinesbytheirpowertorecogn
ize languagesandtosolveproblemsincomputing.
• Tofamiliarizehowtoemploy deterministicandnon-deterministic
finite automata.
Syllabus:
Strings,alphabet,language,operations,finitestatemachine,finiteauto
maton model, acceptance of strings and languages, deterministic
finite automaton and non deterministic finite automaton, transition
diagrams and language recognizers.
LearningOutcomes:
Studentswillbeableto:
• Understand the basic definitions like alphabet, string, language
and their operations.
• Understand themodelof FA.
• DesignDFAandNFAforthegivenregularlanguage.
• TestthedesignedDFAandNFAforthesetofstringsthatbelongstoL
and for the set of strings that doesn’t belongs to L.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 13

LearningMaterial
Alphabet:
Analphabetisafinite,nonemptysetofsymbols.Itisdenotedby∑.
Example:
∑={0,1} is binary alphabet consistingof the symbols 0 and1.
∑={a,b,c...z}islowercaseEnglishalphabet.

PowersofanAlphabet
If Σ is an alphabet, we can express the set of all strings of a certain length from
thatalphabetbyusingtheexponentialnotation.ItisdenotedbyΣk-
thesetof strings of length k.
Example:
Σ0 = {ε},regardlessofwhatalphabetΣis. εistheonlystringoflength0. If Σ = {0,
1} then,
Σ1={0,1}
Σ2={00, 01,10, 11}
Σ3={000,001,010,011,100,101,110,111}
ThesetofallstringsoveranalphabetΣisdenoted by Σ*. Σ*=Σ0∪Σ1∪Σ2∪.. For
example, {0, 1}* = {ε, 0, 1, 00, 01, 10, 11, 000,.................}
Thesymbol∗iscalledKleenestarandisnamedafterthemathematicianand
logicianStephenColeKleene.
Thesymbol+iscalledPositiveclosurei.e.Σ+=Σ1∪Σ2∪...

Σ∗=Σ+∪{ε
}

String:
Astring(orword)isafinitesequenceofsymbolschosenfromsomealphabet.
The letters u, v, w, x, y and z are used to denote string.
Example:
IfΣ={a,b,c}thenabcbisastringformedfromthatalphabet.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 14

• Thelengthofastringw,denoted|
w|,isthenumberofsymbolscomposing the string.
Example:
Thestringabcb has length 4.
• Theemptystringdenotedbyε,isthestring consistingofzero symbols.
Thus|ε|=0.
Operationsonstrings:
• Concatenationofstrings
Theconcatenationoftwostringsisthestringformedbywritingthefi
rst, followed by the second, with no intervening space.
Concatenation of stringsisdenotedby◦.
Thatis,ifwandxarestrings,thenwxistheconcatenationofthesetw
o strings.
Example:
Theconcatenationofdogandhouseisdoghouse.
Letx=0100101andy=1111thenx◦y=01001011111
• StringReversal
Reversing a string means writing the string

backwards. It is denoted by wR

Example:
Reverseofthestringabcdisdcba.
Note:Ifw=wR,thenthatstringiscalledpalindrome.
• Substring
Asubstringisapartofastring.
Example:
If abcd is string then possible substrings
areε,a,b,c,d,ab,bc,cd,abc,bcd are proper substrings for the given
string
Aprefixofastringisanynumberofleadingsymbolsofthatstring
. A suffix of a string is any number of trailing symbols.
IIYear–II-Semester 2018-19 CSE
FormalLanguagesandAutomataTheory 15

Example:

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 16

String abc has prefixesε, a, ab,and abc; its suffixes areε, c,


bc,and abc.
Aprefixorsuffixofastring,otherthanthestringitself,iscalleda
properprefixorsuffix.
Language:
A (formal) language is a set of strings of symbols from someone
alphabet. It is denoted by L. We denote this language by ∑*.
• Theemptyset,Ø,andthesetconsistingoftheemptystring{ε}arelang
uages.
Example:
If∑={a},then∑*={ε,a,aa,aaa,...}.
If ∑={0,1},then∑*={ε,0, 1,00,01,10, 11,000,...}.
Operationsonlanguages:
• Union
IfL1andL2aretwolanguagesoveranalphabet∑.ThentheunionofL1
andL2isdenotedbyL1UL2.
Example:
L1={0,01,011}andL2={001},thenL1UL2={0,01,011,001}
• Intersection
IfL1andL2aretwolanguagesoveranalphabet∑.Thentheintersection
ofL1andL2isdenotedbyL1∩L2.
Example:
L1={0,01,011}andL2={01},thenL1∩L2={01}
• Complementation
L is a language over an alphabet ∑, then the complementof L
denoted by L', is the language consisting of those strings that
are not in L over the alphabet.
Example:
If∑={a,b}andL={a,b,aa},then
L'=∑*-L={ε,a,b,aa,bb,ab.........}-{a,b,aa}={ε,bb,ab,ba............}

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 17

• Concatenation
Concatenation of two languages L1 and L2 is the language L1 o
L2 ,each element of which is a string formed by combining one
string of L1 with another string of L2.
Example:
L1={bc,bcc,cc}and L2={cc,ccc},then L1oL2 =
{bccc,bcccc,bcccccc,cccc,ccccc}
• Reversal
If L is language, then L Ris obtained by reversing the
corresponding string in L.This operation is similar to the reversal
of astring.
LR ={wR|w∈L}
Example:
IfL={0,011,0111},thenLR ={0,110,1110}
• KleeneClosure
TheKleeneclosure(orjustclosure)ofL,denotedL*,istheset


L*=U
Li
i=0

• PositiveClosure
ThepositiveclosureofL,denotedL+,istheset

L+=U
Li
i=1

Thatis,L*denoteswordsconstructedbyconcatenatinganynumberof
words from L.
L+isthesame,whereε,isexcluded.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 18

Note:L+containsεifandonlyifLdoes.
Example:
LetL1={10,1}
L*=L0UL1UL2..................={ε,1,10,11,111,1111,......................}
L+=L1UL2UL3...................={1,10,11,111,1111.............}
FiniteAutomaton:
• A finite automaton (FA) consists of a finite set of states and a set
of transitions from state to statethat occuron input symbols
chosenfrom an alphabet ∑.
• For each input symbol there is exactly one transition out of each
state (possibly back to the state itself).
• One state, usually denoted q0is the initial state, in which the
automaton starts. Some states are designated as final or accepting
states.
Formally,afiniteautomatonisdenotedbya5-tuple(Q,∑,δ,qo,F),where

• Qisafiniteset ofstates.
• ∑isafiniteinputalphabet.
• δisthetransitionfunctionmappingQx∑toQi.e.,δ(q,a)isastate for
each state q and input symbol a.
• qo∈Qistheinitialstate.
• F⊆Qis the set of final states. It is assumedhere that there maybe
• morethanonefinalstate.

TransitionDiagram:
• AtransitiondiagramisadirectedgraphassociatedwithanFAinwhicht
he verticesofthegraphcorrespondtothestatesoftheFA.
• Ifthereisatransitionfromstateqtostateponinputa,thenthereisanarc
labelledafromstateqtostatepinthetransitiondiagram.

Stateisdenotedby
IIYear–II-Semester 2018-19 CSE
FormalLanguagesandAutomataTheory 19

Transition is denoted by

Initialstateisdenotedby Fi

nal state is denoted by

TransitionTable:
A tabular representation in which rows
correspond to states,
columnscorrespondtoinputsandentriescorrespondtonextstates.
FiniteAutomataModel:

Blockdiagramofafiniteautomaton

Thevariouscomponentsareexplainedasfollows:
(i) Inputtape:
• Theinput tapeisdividedinto squares,
eachsquarecontainingasingle symbol from the input alphabet
∑.
• Theendsquaresofthetapecontaintheendmarker
¢attheleftendand the endmarker $ at the right end.
• The absence of endmarkers indicates that the tape is of infinite
length. The left-to-right sequence of symbols between the two
endmarkers is the input string to be processed.
(ii) Readinghead:
• The head examines only one square at a time and can move one

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 20

square either to the left or to the right.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 21

• Forfurtheranalysis,werestrictthemovementoftheR-
headonlytothe right side.
(iii) Finite control:The input to the finite control will usually be the
symbol undertheR-
head,saya,andthepresentstateofthemachine,sayq,togive the
following outputs:
• A motion of R-head along the tape to the next square (in
some a null move,i.e.theR-
headremainingtothesamesquareispermitted)
• Thenextstateofthe finitestatemachinegivenbyδ(q,a).
AcceptanceofStringbyaFiniteAutomaton:
The FA accepts a string x if the sequence of transitions corresponding to
the symbols of x leads from the start state to an accepting state and
the
entirestringhastobeconsumed,i.e.,astringxisacceptedbyafiniteautomat
onM
=(Q, ∑,δ,qo,F)

ifδ(q0,x)=qforsomeq ∈
F.

Thisisbasicallytheacceptabilityofastringbythefinalstate.
Note:Afinalstateisalsocalledanacceptingstate.
Transitionfunctionδandforanytwoinputstringsxandy,

δ(q,xy)=δ(δ(q,x), y)

Example:
Consider the finite state machine whose transition functionδis given in
theformofatransition table.HereQ = {q0,q1,q2,q3},∑={0,1},

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 22

F={q0}.Givetheentire sequence of states for the input string 110101.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 23

Input
State
0 1
q2 q3 q1 q0
q0
q1

q2 q0 q3
q3 q1 q2

δ(q0,110101)=δ(q1,10101)
=δ(q0,0101)
=δ(q2,101)
=δ(q3,01)
=δ(q1,1)=q0
q0isfinalstate,thereforegivenstringisacceptedby finite
automata.

Deterministicfiniteautomaton:
Formally,adeterministicfiniteautomatoncanberepresentedbya5-tupleM=
(Q,∑,δ,qo,F),
where
• Qisafiniteset ofstates.
• ∑isafiniteinputalphabet.
• δisthetransitionfunctionmappingQx∑toQi.e.,δ(q,a)isastatefor each
state q and input symbol a.
• qo∈Qistheinitialstate.
• F ⊆Q isthesetoffinalstates.Itisassumed herethattheremay
be more than one final state.
StepstodesignaDFA:
1. Understand the languagefor whichthe DFA has to bedesigned
andwrite the language forthe setof stringsstarting with
minimumstring thatare accepted by FA.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 24

2. Drawtransitiondiagramfortheminimumlengthstring.
3. Obtainthepossibletransitionstobemadeforeachstateoneachinp
ut symbol.
4. Drawthetransitiontable.
5. TestDFAwithfewstringsthatareacceptedandfewstringsthatare
rejected by the given language.
6. RepresentDFAwithtuples.
Examples
1. DesignDFAthatacceptsallstringswhichstartswith‘1’overthe alphabet
{0,1}
Step1:UnderstandthelanguageforwhichtheDFAhastobedesigned
and write the language for the set of strings starting with
minimum string that is accepted by FA.
L={1,10,11,100,110,101,111,..................................................}

Step2:Drawtransitiondiagramfortheminimumlengthstring.

Step 3:Obtainthepossibletransitionsto bemadeforeach stateon each


input symbol.

Step4:Drawthetransitiontable.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 25

Input
State
0 1
q0 q2 q1
q1
q1 q1 q1

q2 q2 q2

Step 5: Test DFA with few strings that are accepted and few
strings that are rejected by the given language.
Casei)Let w=1001∈L
δ(q0,1001)=δ(q1,010)
=δ(q1,10)=δ(q1,0)=q1
q1is final state and the entire string has been consumed i.e.,
given string is accepted by DFA.

Caseii)Letw=0001∉L
δ(q0,0001)=δ(q2,001)
=δ(q2,10)
=δ(q2,0)
=q2
q2is not final state and the entire string has been consumed i.e.,
given string is rejected by DFA.
Step6:RepresentDFAwithtuples.
DFA,M=(Q,∑,δ,qo,F)
whereQ={q0,q1,q2}
∑={0,1}
δ:δ(q0,0)=q2
δ(q0,1)=q1
δ(q1,0)=q1
δ(q1,1)=q1

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 26

δ(q2,0)=q2
δ(q2,1)=q2
q0–initialstate
F–finalstate={q1}

2. DesignDFAthatacceptsallstringswhichcontains‘00’assubstring over the


alphabet {0,1}
Step1:UnderstandthelanguageforwhichtheDFAhastobedesigne
d and write the language for the set of strings starting with
minimum string that is accepted by FA.

L={00,100,000,001,1100,1000,0100,1001,0001,11000,11100,........}

Step2:Drawtransitiondiagramfortheminimumlengthstring.

Step 3 : Obtain the possible transitions to be made for each


state on each input symbol.

Step4:Drawthetransitiontable.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 27

Input
State
0 1
q0 q1 q0

q1 q2 q0

q2 q2 q2
Step 5: Test DFA with few strings that are accepted and few
strings that are rejected by the given language.
Casei)Letw=1001∈L
δ(q0,1001)=δ(q0,001)
=δ(q1,01)
=δ(q2,1)
=q2
q2 is final state and the entire string has been consumed
i.e., given string is accepted by DFA.

Caseii)Letw=1011∉L
δ(q0,1011)=δ(q0,011)
=δ(q1,11)
=δ(q0,1)
=q0

q0is not final state and the entire string has been consumed i.e.,
given string is rejected by DFA.
Step6:RepresentDFAwithtuples.
DFA,M=(Q,∑,δ,qo,F)
whereQ={q0,q1,q2}
∑={0,1}
δ:δ(q0,0)=q1
δ(q0,1)=q0

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 28

δ(q1,0)=
q2
δ(q1,1)=
q0
δ(q2,0)=
q2
δ(q2,1)=
q2
q0–initialstate
F–finalstate={q2}
Nondeterministicfiniteautomaton(NDFA/NFA):
Anondeterministicfiniteautomatonisa5-tuple(Q,∑,δ,qo,F),where
• Qisafinitenonemptysetofstates;
• ∑isafinitenonemptysetofinputs;
• δ isthetransitionfunctionmappingfromQx∑into2Qwhichisthe
power set of Q, the set of all subsets of Q;
• qo∈Qistheinitialstate;and
• F⊆Qisthesetoffinalstates
StepstodesignaNFA:
1. Understand the language for which theNFA has to be designed
and write the language for the set of strings starting with
minimum string that is accepted by FA.
2. Drawtransitiondiagramfortheminimumlengthstring.
3. Obtainthepossibletransitionstobemadeforeachstateoneachinp
ut symbol.
4. Drawthetransitiontable.
5. Test NFA with few strings that are accepted and few strings that
are rejected by the given language.
6. RepresentNFAwithtuples.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 29

Examples:
1. Design NFA that accepts all strings which contains ‘00’ as substring
over the alphabet {0,1}

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 30

Step 1:Understand the language for which the NFA has to be


designed
andwritethelanguageforthesetofstringsstartingwithminimum
string that is accepted by FA
L={00,100,000,001,0100,1100,1000,1001,0001,11000,11100,.
.............................................................................................................}

Step2:Drawtransitiondiagramfortheminimumlengthstring.

Step
3:Obtainthepossibletransitionstobemadeforeachstateoneach
input symbol. 0, 1

Step4:Drawthetransitiontable.

Input
State
0 1
q0 {q0,q1} q0

qq11 q2 -

q2 q2 q2

Step 5: Test NFA with few strings that are accepted and few
strings that are rejected by the given language.
Casei)Let w=0100∈L
δ(q0,0100)=δ({q0,q1},100)
=δ(q0,00)
=δ({q0,q1},0)
={q0,q1,q2}
IIYear–II-Semester 2018-19 CSE
FormalLanguagesandAutomataTheory 31

q2is final state and the entire string has been consumed i.e.,
given string isacceptedbyNFA.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 32

Caseii)Letw=1011∉L
δ(q0,1011)=δ(q0,011)
=δ({q0,q1},11)
=δ(q0,1)
=q0
q0 is not final state and the entire string has been consumed i.e.,
given string is rejected by NFA.
Step6:RepresentNFAwithtuples.
NFA,M=(Q,∑,δ,qo,F)
whereQ={q0,q1,q2}
∑={0,1}
δ:δ(q0,0)={q0,q

1} δ(q0,1) =
q0 δ(q1,0) = q2
δ(q1,1) =Ø
δ(q2,0) = q2
δ(q2,1) = q2
q0–initialstate
F–finalstate={q2}

2. Design NFA that accepts strings which contains either two


consecutive 0’s or two consecutive 1’s.

Step 1: Understand the language for which the NFA has to be


designed
andwritethelanguageforthesetofstringsstartingwithminimum
string that is accepted by FA.
L={00,11,100,001,110,011,111,000,0100,1011,....}
Step2:Drawtransitiondiagramfortheminimumlengthstring.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 33

Step 3: Obtainthepossibletransitions to bemadefor eachstate


oneach input symbol.

Step4:Drawthetransitiontable.

Input
State
0 1
q0 {q0,q3} {q0,q1}

q1 - q2

q2
q2 q2

q3 q4 -
q4 q4
q4

Step 5: Test NFA with few strings that are accepted and few
strings that are rejected by the given language.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 34

Casei)Lettheinput,w=01001 ∈L
δ(q0,0)={q0,q3}

δ(q0,01)=δ(δ(q0,0),1)=δ({q0,q3},1)=δ(q0,1)∪δ(q3,1)={q0,q1}

Similarly,wecompute
δ(q0,010)={q0,q3}, δ(q0,0100)={q0,q3,q4}
and
δ(q0,01001)={q0,q1,q4}
final state
Aftertheentirestringisconsumed,theFAisinthestateq4
. Asq4isthefinalstate,thestringisaacceptedbyFA

Caseii)Letw=010∉L
δ(q0,010)=δ({q0,q3},10)
=δ({q0,q1},0)
={q0,q3}
Thereisnopathtothefinalstateaftertheentirestringisconsumed.
So the string is rejected by FA.
Step6:RepresentNFAwithtuples.
NFA,M=(Q,∑,δ,qo,F)
whereQ={q0,q1,q2,q3,q4}
∑={0,1}
δ:δ(q0,0)={q0,q3}
δ(q0,1)={q0,q1}
δ(q1,0)=Ø

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 35

δ(q1,1)=
q2
δ(q2,0)=
q2
δ(q2,1)=
q2
δ(q3,0)=
q4
δ(q3,1)=
Ø
δ(q4,0)=q4
δ(q4,1)=q4
q0–initialstate
F–finalstate={q2,q4}
Note: The minimal state DFA, accepting all strings over the alphabet
{0, 1} where the nth symbol in every string from the right end is a 1,
has 2nstates.

Languagerecognizers:
A languagerecognizeris a device thatacceptsvalid stringsproduced in
a given language. Finite state automata are formalized types of
language recognizers.
ThelanguageacceptedbyFiniteAutomataMdesignatedL(M)istheset{x|
δ(q0,x)isinF}.
ApplicationsofFA:
• UsedinLexicalanalysisphaseofacompilertorecognizetokens.
• Usedintexteditorsforstringmatching.
• Softwarefordesigningandcheckingthebehaviorofdigital circuits.
LimitationsofFA:
• FA’swillhavefiniteamountofmemory.
IIYear–II-Semester 2018-19 CSE
FormalLanguagesandAutomataTheory 36

• The class of languages recognized by FA s is strictly the regular


set. There are certain languages which are non regular i.e.
cannot be recognized by any FA.
DifferencesbetweenNFAandDFA:
S.No NFA DFA
A nondeterministic finite A deterministic finite
1 automaton
automatonisa5-tuple
canberepresentedbya5-tuple

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 37

M=(Q, ∑,δ,qo,F),where M=(Q,∑,δ,qo, F),where


δ:Qx∑into2Q. δ:Qx∑toQ.

NFA is the one in DFA is a FA in which there


whichthere isonly one path for a specific
2
existsmanypathsforaspecifi input from current state to next
c state.
inputfromcurrentstatetonex
t
state.
3 NFAiseasiertoconstruct. DFAismoredifficulttoconstruct.
4 NFArequireslessspace. DFArequiresmorespace.
Timerequiredforexecutingan Time required for executing an
5
inputstringismore. inputstringisless.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 38

UNIT-I
Assignment-Cum-TutorialQuestions
SECTION-A

ObjectiveQuestions

1. Theprefixofabcis [ ]
A) c B)bc C)b D)ε
2. ∑*=∑ U ε
+ [True|False]
3. Alphabet is . [ ]
A) Finitecollectionofstrings. B) Finite collectionof symbols.
C)Finitecollectionoflanguages. D)Alltheabove.
4. A ofastringisanynumberofleadingsymbolsofthatstring.
5. is a directedgraph associated with an FAin which
thevertices of the graph correspond to the states of the FA.
6. The transition function for NFA is a mapping function given as
.
7. The transition function for DFA is a mapping function given as
.
8. A = {a, b, c}. Power set of A= .
9. FAhas [ ]
A) Unlimitedmemory B)nomemoryat all
C)Limited memory D)noneoftheabove.
10. Numberofstatesrequirestoacceptstringendswith10. [ ]
A) 3 B)2 C)1 D)can’tberepresented.
11. Considerthefiniteautomatoninthefollowingfigure

Whatisthesetofreachablestatesfortheinputstring0011? [ ]
A) {q0,q1,q2} B){q0,q1} C){q0,q1,q2,q3} (D){q3}
12. GiventhelanguageL={ab,aa,baa},whichofthefollowingstringsareinL*?
1) abaabaaabaa 2) aaaabaaaa 3)baaaaabaaaab4)baaaaabaa[ ]
A)1,2and3 B)2,3and4 C)1,2and4 D)1, 3and4

13. Intheautomatonbelow,sisthestartstateandtistheonlyfinalstate.

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 39

Consider the strings u = abbaba, v = bab, and w = aabb. Which of the


following statements is true? [ ]
A) Theautomatonacceptsuandvbutnotw
B) Theautomatonacceptseachofu,vandw
C) Theautomatonrejectseachofu,vand w
D) Theautomatonaccepts u but rejectsv andw
14. Ifthefinalstatesandnon-
finalstatesintheDFAbelowareinterchanged,then which of the
followinglanguagesoverthealphabet{a,b}willbeacceptedbythenewDFA?

A)Setofallstringsthatdonotendwithab [
B) Setofallstringsthatbeginwitheitheranaorab
C) Setofallstringsthatdonotcontainthesubstringab,
D) Alltheabove

15. WhatistheminimumnumberofstatesintheNFAacceptingthelanguage
{a,ab}?
A) 3 B) 2 C)1 D)4 [ ]

16. Thesmallestfiniteautomationwhichacceptsthelanguage{x|
lengthofx isdivisible by 3} has [ ]
A) 2states B)3states C)4statesD)5states
17. ThebelowDFAacceptsthesetofallstringsover{0,1}that [ ]

a) begineitherwith0or1 b)endwith0
c)endwith00 d)containthesubstring00

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 40

18. Consider a DFA over ∑={a,b} accepting allstrings which have number of a’s
divisible by 6 and number of b’s divisible by 8. What is the number
of states that the DFA will have?
[ ]
A) 8 B) 14 C) 15 D) 48

SECTION-B
SUBJECTIVEQUESTIONS

1. Definestringandalphabet.
2. Explainoperationsonstringsandlanguages.
3. DefinePositiveClosureandKleeneClosure.
4. Define(i)FiniteAutomaton(FA) (ii)Transitiondiagram
5. ExplainthemodelofFA.
6. WritethedifferencesbetweenNFAandDFA.
7. Whatisthedifferencebetweenemptylanguageandnullstring?
8. WhichofthefollowingFiniteAutomatonishavingambiguityandwhy?
i) NFAii)DFA
9. DrawtheFinitestatemachinefor acceptingthelanguages□andØ.
10. Fromthegiventransitiontable.Checkwhetherthefollowingstringsa
re accepted or not.
i) 101101
ii) 000000
Q/∑ 0 1

q0
q2 q1

q1 q3 q0

q2 q0 q3

q3 q1 q2

11. ConstructDFAacceptingthesetofallstringsbeginningwith101.
12. Design a DFA for a language which contains strings of a’s & b’s
and each string ends with aab.
13. DescribethewordswinthelanguageLacceptedbytheautomatonin

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 41

14. Design DFA accepting the set of all strings that begin with 01 and
end with 11.
15. a)DesignaDFAtoacceptthefollowinglanguage.L={w:|w|mod3=0} on
Σ={a}
b) DesignDFAacceptingthelanguagewhosebinaryinterpretationis
divisible by 5 over the alphabet {0, 1}.
16. DesignaDFAtoacceptstringsofa’sandb’shavingevennumberofa’sand
b’s.
17. DesignaDFAthatacceptsallstringsoverΣ={0,1}thatdonotcontain101
asasubstring.
18. DesignNFAthatacceptsthelanguageofstringsoverΣ={0,1}suchthat some
two 0’s are separated by a string whose length is 4i, for some i ≥0.
19. DesignaNFAtoacceptstringsof0’s&1’ssuchthateachstringendswi
th 00.
20. FortheNFAgivenbelow;
i. Checkwhetherthestringaxxaxxaisacceptedornot
ii. Giveatleasttwotransitionpaths

SECTION-C

QUESTIONS AT THE LEVEL OF GATE

1. ConsiderthefollowingDeterministicFiniteAutomata

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 42

Whichofthefollowingistrue? [ ]
A) Itonlyacceptsstringswithprefixas“aababb”
B) Itonlyacceptsstringswithsubstringas“aababb”
C) Itonlyacceptsstringswithsuffixas“aababb”
D) Noneoftheabove
2. The possiblenumberofstatesofadeterministicfiniteautomatonthat
accepts a regular language
L={w1aw2|w1,w2∈{a,b}*,|w1|= 2,w2>=3}is
[GATE2017set-2]
3. Letwbeanystringoflengthnin{0,1}*.LetLbethesetofallsubstringsof
w.Whatisthenumberofstatesinanon-deterministicfiniteautomaton
that accepts L? [ ]
A)n-1 B)n C)n+1 D)2n-1
[GATE2010
]
4. ConsiderthemachineM:

[GATE2005]
ThelanguagerecognizedbyMis: [ ]

a) {wЄ{a,b}*|everyainwisfollowedbyexactlytwob’s}
b) {wЄ{a,b}*|everyainwisfollowedbyatleasttwob’s}
c) {wЄ{a,b}*|wcontainsthesubstring‘abb’}
d) {wЄ{a,b}*|wdoesnotcontain‘aa’asasubstring}
5. Thefollowingfinitestatemachineacceptsallthosebinarystringsinwhich
the number of 1’s and 0’s are respectively [ ]
[GATE2004]

a) divisibleby3and2 b)oddandeven
c)evenandodd d)divisibleby2and3

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 43

6. ConsiderthefollowingdeterministicfinitestateautomatonM.

[GATE2003]
LetSdenotethesetofsevenbitbinarystringsinwhichthefirst,thefourt
h,
andthelastbitsare1.ThenumberofstringsinSthatareacceptedbyMis
[ ]
(A)1 (B)5 (C)7 (D)8
7. ConsidertheNFAMshownbelow.

LetthelanguageacceptedbyMbeL.LetL1bethelanguageacceptedbyth
e NFA M1, obtained by changing the accepting state of M to a non-
accepting state and by changing the non-accepting state of M to
accepting states. Which of the following Statements is true? []
A) L1={0,1}*–L B)L1={0,1}*
C)L1⊆L D)L1=L
8. Constructafinitestatemachinethatacceptsthelanguage,over{0,1}ofall
stringsthatcontainneitherthesubstring00northesubstring11.
[Gate2000]
9. What can be said about a regular language L over {a} whose
minimal finitestate automaton has two states? [ ]
[Gate2000]
A) Lmustbe{an|nisodd}
B) Lmustbe{an|niseven}
C) Lmustbe{an|>=0}
D) EitherLmustbe{an|nisodd},orLmustbe{an|niseven}

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 1

UNIT–II

Objective:
Tofamiliarizehowtoemploynon-deterministicfiniteautomatawithεtransitions
andfiniteautomatawithoutputs.

Syllabus:
FiniteAutomata:
NFAwithεtransitions-significance,acceptanceoflanguages,equivalencebetween
NFA with and without ε transitions, NFA to DFA conversion, minimization of
FSM, equivalence between two FSM‘s, finite automata with output-Moore
and Mealy machines, applications of FA.

LearningOutcomes:
Studentswillbeableto:
• ConvertNFAtoDFAandNFAwithepsilontransitionstoNFAwithout
Epsilon transitions.
• MinimizethegivenDFA.
• TestwhetherthetwoDFA’sareequivalentornot.
• DesignMooreandMealyMachines
NFA withεtransitions:
An ε-NFAisatuple(Q,Σ,δ,qo,F)
where
• Qisasetofstates,
• Σisthealphabet,
• δisthetransitionfunctionthatmapseachpairconsistingofastateanda symbolin Σ
∪ { ε } to a subset of Q,
• q0istheinitialstate,

• F⊂Qisthesetoffinal(oraccepting)states.

Significanceofε-NFA:
Itbecomesverydifficultormanytimesitseemstobeimpossibletodrawdirectly
NFA or DFA.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 2

Example:

Stringacceptancebyε–NFA

Fig:1

TransitionTable:

Q/∑ a b ε

q0 - - {q1,q2}

q1 q3 - -

q2 - q4 -

q3 q1 - -

q4
- q2 -

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 3

Example:

Checkwhetherthestring‘bbb’isacceptedornotfortheaboveautomaton.

ε b b b
q0 q2 q4 q2 q4q1
ε

Asq4isthefinal state, thegivenstringisacceptedbythegivenε–NFA.

ε–NFAtoNFA Conversion:
Step1:Findtheε-closureforallstatesinthegivenε-NFA.

ε-closure (q) denotes the set of all states p such that there is a path from
q to p labelled ε.

Step2:Findtheextendedtransitionfunctionforallstatesonallinputsymbolsfor
thegivenε-NFA.

δ'(q,a)=ε-closure(δ(δ'(q, ε),a))

Step3:Drawthetransitiontableordiagramfromtheextendedtransitionfunctio
n (NFA)

Step4:FisthesetoffinalstatesofNFA,whoseε-closurecontainsthefinalstate
of ε -NFA.

Step5:To check the equivalence of ε-NFAand NFA,thestringaccepted byε-NFA


should be accepted by NFA.

Example:
1.ConvertNFAwithε-movesintoanequivalentNFAwithoutε-moves.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 4

Step 1:Findtheε-closureforall states in thegiven ε-NFA. ε -


CLOSURE(q0)={q0,q1,q2}
ε-CLOSURE(q1)={q1,q2}
ε-CLOSURE(q2)={q2}

Step2:Findtheextendedtransitionfunctionforallstatesonallinputsymbolsfor
thegivenε-NFA.
δ'(q0,0)=ε-closure(δ(δ'(q0,ε),0))
=ε-closure(δ{q0,q1,q2},0)
=ε-closure(δ(q0,0)Uδ(q1,0)Uδ(q2,0))
=ε-closure(q0UØUØ)
={q0,q1,q2}

δ'(q0,1)=ε-closure(δ(δ'(q0,ε),1))
=ε-closure(δ{q0,q1,q2},1)
=ε-closure(δ(q0,1) Uδ(q1,1) Uδ(q2,1))
=ε-closure(ØUq1UØ)
={q1,q2}

δ'(q0,2)=ε-closure(δ(δ'(q0,ε),2))
=ε-closure(δ{q0,q1,q2},2)
=ε-closure(δ(q0,2)Uδ(q1,2)Uδ(q2,2))
=ε-closure(q2UØ)
={q2}

δ'(q1,0)=ε-closure(δ(δ'(q1,ε),0))
=ε-closure(δ{q1,q2},0)
=ε-closure(δ(q1,0)Uδ(q2,0))
=ε-closure(Ø)
={Ø }

δ'(q1,1)=ε-closure(δ(δ'(q1,ε),1))
=ε-closure(δ{q1,q2},1)
=ε-closure(δ(q1,1)Uδ(q2,1))
=ε-closure(q1)
={q1,q2}

δ(q1,2)=ε-closure(δ(δ'(q1,ε),2))

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 5

=ε-closure(δ{q1,q2},2)

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 6

=ε-closure(δ(q1,2)Uδ(q2,2))
=ε-closure(q2)
={q2}
δ(q2,0)=ε-closure(δ(δ'(q2,ε),0))
=ε-closure(δ(q2,2))
=ε-closure(Ø)
={Ø}

δ(q2,1)=ε-closure(δ(δ'(q2,ε),1))
=ε-closure(δ(q2,1))
=ε-closure(Ø)
={Ø}

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

Step3:Drawthetransitiontableordiagramfromtheextendedtransitionfunctio
n (NFA)

Inputs
State
0 1 2
q0 {q0,q1,q2} {q1,q2} q2

q1 Ø {q1,q2} q2

*q2 Ø Ø q2

Step4:FisthesetoffinalstatesofNFA,whoseε-closurecontainsthefinalstate
ofε-NFA.

Inputs
State
0 1 2

q0 {q0,q1,q2} {q1,q2} q2

q1 Ø {q1,q2} q2

q2 Ø Ø q2

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 7

Step5:To check the equivalence ofε-NFAand NFA,thestringacceptedbyε-NFA


should be accepted by NFA.

Stringacceptancebyε-NFA:
Letw=001

0 0 ε 1 ε
q0 q0 q0 q1 q1 q2

Asq2is thefinalstate,thestringisacceptedbythegivenε-NFA.

StringacceptancebyNFA:
Ifw=001
0 0 1
q0 q0 q 0q q1
0 0 1 1 q2

0 q10q2

q2

Asq1 andq2arefinalstates,thestringisacceptedbytheNFA.

NFAtoDFAConversion:

Step1:FirsttakethestartingstateofNFAasthestartingstateofDFA.

Step 2: Apply the inputs on initial state and represent the corresponding
states in the transitiontable.

Step3:Foreachnewlygeneratedstate,applytheinputsandrepresentthe
corresponding states in the transition table.

Step4:Repeatstep3untilnomorenewstatesaregenerated.

Step 5:The states which contain any of the final statesof the NFA are the
final statesoftheequivalentDFA.
Step6: Representthetransitiondiagramfromtheconstructedtable.
Step7:TochecktheequivalenceofNFAandDFA,thestringacceptedbyNFA should
be accepted by DFA.
Step8: Write thetuplerepresentation forthe obtainedDFA.

Note:If the NFA hasnstates, the resulting DFA may have up to


2nstates, an exponentially larger number, which sometimes makes the
construction impractical for large NFAs.

Example:
1.ConstructDFAequivalenttothe NFAM=({q0,q1},{0,1},δ,q0,{q1})
whereδ(q0,0)={q0,q1} δ(q0,1)={q1} δ(q1,0)=Ø δ(q1,1)={q0,q1}

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 8

Step1:FirsttakethestartingstateofNFAasthestartingstateofDFA

Q/∑ 0 1
[q0]

Step 2: Apply the inputs on initial state and represent the corresponding
states in the transitiontable.

Q/∑ 0 1
[q0] [q0,q1] [q1]

Step3:Foreachnewlygeneratedstate,applytheinputsandrepresentthe
corresponding states in the transition table.

Q/∑ 0 1
[q0] [q0,q1] [q1]
[q0,q1] [q0,q1] [q0,q1]
[q1] Ø [q0,q1]

Step4:Stoptheprocedureastherearenomorenewstatesbeinggenerated.
Step 5:The stateswhich contain any of the final statesof the NFA are the
final statesoftheequivalentDFA.
q1isthe final state in NFA. q1is included in the state [q0,q1] and [q1]. So
[q0,q1]and [q1] are the final states of the DFA.

Q/∑ 0 1
[q0] [q0,q1] [q1]

[q0,q1] [q0,q1] [q0,q1]

[q1] Ø [q0,q1]

Step6:Representthe transitiondiagramfromtheconstructedtable.

Step7:TochecktheequivalenceofNFAandDFA,thestringacceptedbyNFA should
be accepted by DFA.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 9

Letw=1110bethestringacceptedbyNFA.
AcceptabilitybyNFA:

1 q1 0 Ø
1 q 0 q0
q0 1 q1 1 q0
1 1 0 q1
1 q1
q 0

0
Ø

AcceptabilitybyDFA:
1 1 1 0
δ([q0],1110)=δ([q1],110) [q0] [q1] [q0,q1] [q0,q1] [q0,q1]

=δ([q0,q1],10)

=δ([q0,q1],0)

=[q0,q1]□F

Step 8:Write the tuplerepresentation fromtheobtained


DFA. DFAM'= (Q,∑, δ,q0,F)
whereQ={[q0],[q0,q1],[q1]}

∑={0,1}

δ-transitionfunction

[q0] - initial state


F={[q0],[q0,q1]}

MinimizationofFiniteAutomata:
Twostatesqlandq2areequivalent(denotedbyq1≡q2)ifbothδ(q1,x)andδ(q2,x)
arefinalstates. orbothof themarenonfinalstatesforall x□∑*.

Twostatesq1andq2arek-equivalent(k≥0)ifbothδ(q1,x)andδ(q2,x)arefinal
statesorbothnonfinalstatesforallstringsxoflengthkorless.Inparticular,an
y two final states are 0-equivalent and anytwononfinal states are also 0-
equivalent.
ConstructionofMinimumAutomaton:
Step 1:(Construction ofπ0)· By definition of 0-equivalence,π0={Q10, Q20}
where Q10is the set of all final states and Q20=Q - Q10.
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 10

Step2:(Constructionofπk+1fromπk).

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 11

• LetQikbeanysubsetinπk.Ifq1andq2areinQik,theyare(k+1)-
equivalent provided δ(q1,a)andδ(q2,a)arek-equivalent.
• Findoutwhetherδ(q1,a)andδ(q2,a)areinthesameequivalence classin
πkforeverya□∑.Ifsoq1andq2are(k+1)-equivalent.
• Inthisway,Qikisfurtherdividedinto(k+1)-equivalenceclasses.Repeat
this for every Qik in πkto get all the elements of πk+1.

Step3:Constructπnforn=1,2,.......untilπn=πn+1.

Step 4:(Construction of minimum automaton). For the required minimum


state automaton, the states are the equivalence classes obtained in step
3. i.e. the elements ofπnThe state table is obtained by replacing a state q
by the corresponding equivalence class [q].

Example:
Constructaminimumstateautomatonequivalenttothefiniteautomaton.

Solution:
Itwillbeeasierifweconstructthetransitiontable.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 12

Step 1: Constructionof

π0 π0= {Q10, Q20}

whereQ10=F={q2} Q20=Q-Q10

∴π0={{q2},{q0,q1,q3,q4,q5,q6,q7}}

Step2:The{q2}inπ0cannotbefurtherpartitioned.So,Q11={q2}.
Compare q0with q1, q3,q4,q5,q6and q7.

Considerqoandq1□Q20.
• The entries under the 0- column corresponding to qo and q1 are q1
and q6; they lie in Q20.

• Theentriesunderthe1-columnareq5andq2.q2□Q10andq5□Q20.
Thereforeqoandq1arenot1-equivalent.

Q/∑ 0 1

q0 q1 q5

q1 q6 q2

Considerq0andq3

Q/∑ 0 1

q0 q1 q5

q3 q2 q6

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 13

The entries under the 0- column corresponding to qo and q3 are q1 and


q2; q1□ Q20and q2□ Q10. The entries under the 1-column are q5 and q6;
they lie in Q20. Therefore qo and q3 are not 1- equivalent

Similarly, qoisnot1-equivalentto q5 and

q7. Consider q0 and q4

Q/∑ 0 1

q0 q1 q5

q4 q7 q5

• The entries under the 0- column corresponding to qo and q4 are q1


and q7; they lie in Q20.
• Theentriesunderthe1-
columnareq5andq5;theylieinQ20.Thereforeqo and q1 are 1-
equivalent.

Similarly,qois 1-equivalent toq6.

{qo.q4,q6}isasubsetinπ1.
So,Q21={q0,q4,q6}

• Repeat the construction by considering q1 and anyone of the


state's q3, q5, q7.Now, q1is not 1-equivalent to q3 or q5 but 1-
equivalent to q7.
Hence,Q31={q1,q7}.

• The elementsleftoverin Q20areq3 and q5. Byconsideringthe


entriesunder the 0-column and the 1-column, we see that q3 and
q5 are 1-equivalent.
SoQ41={q3,q5}.
Therefore, π1={{q2}.{qo,q4,q6}.{q1,q7},{q3,q5}}

Step3:Constructπnforn=1,2,.......untilπn=πn+1.
Calculate2-equivalent,π2.

π2={{q2},{qo,q4},{q6},{q1,q7},{q3,q5}}

Similarlycalculate3-equivalent,π3.
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 14

π3={{q2},{qo,q4},{q6},{q1,q7},{q3,q5}}

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 15

Asπ2=π3,π2givesustheequivalenceclasses.

Step4: Constructionofminimumautomaton.
M'=(Q',{0,1},δ',q0',F')
where Q' = {[q2]. [q0, q4],[q6], [q1,q7],

[q3,q5]} q0' = [q0, q4]


F'= [q2]
δ'isgivenby

EquivalencebetweentwoFSM’s:
Let M and M’ be two FSM’s over∑.We construct a comparison table
consisting of n+1 columnswhere n is the number of input symbols.
Step1:1stcolumnconsistingofa pairofstatesofform (q, q’) whereq belongs toM
and q’ belongs M’.

Step2:If(q,q’)appearsinthesamerowof1stcolumnthenthecorresponding entryin
a column (a belongs to ∑)is(r,r’) where (r,r’) are pairfromq and q’ ona.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 16

Step3:Atableisconstructedby startingwithapair ofinitialstatesq 0,q0’ofM


and M’. We complete construction by considering the pairs in 2 ndand
subsequent columns which are not in the 1 stcolumn.
(i) ifwereachapair(q,q’)suchthatqisfinalstatesofMandq’isnon-final
state of M’ i.e. terminate contruction and conclude that M and
M’ are not equivalent.
(ii) if construction is terminated when no new element appears
in 2ndand subsequent columnswhicharenotin1 stcolumn. Conclude
thatM andM’ are equivalent.

Example:
Checkwhetherthegiventwofiniteautomata’sareequivalentornot.

Solution:
q1isinitial state ofM1and q4isinitialstateofM2,makethema
pairandplaceit in 1strow of the transition table.

Comparisontable

Q/∑ c d

(q1,q4) (q1,q4) (q2,q5)

(q2,q5) (q3,q4)

Hereq3isnon-finalstateandq4isfinalstate.

Therefore, we stop constructing comparison table and conclude that the


two given Finite Automata’s are not equivalent.

MooreMachine
AMooremachineisasixtuple(Q,∑,∆,δ,q0,λ)
where

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 17

• Qisasetofstates,
• Σisthealphabet,
• δis thetransitionfunctionthat mapseachpairconsisting ofastateanda symbol
in Σ to Qi.e. .Q XΣ-> Q
• q0istheinitial state,
• ∆isoutputalphabet
• λisamappingfromQto∆givingtheoutputassociatedwitheachstate

Note:For a Moore machine if the input string is of length n, the output string
is of length n + 1. The first output is λ (qo)for alloutput strings.

MealyMachine
AMealymachineisasixtuple(Q,∑,∆,δ,q0,λ)
where
• Qisasetofstates,
• Σisthealphabet,
• δis thetransitionfunctionthat mapseachpairconsisting ofastateanda symbol
in Σ to Q i.e. .Q XΣ-> Q
• ∆isoutputalphabet
• q0istheinitial state,
• λmapsQx∑to∆i.e.,λ(q,a)givestheoutputassociatedwiththetransition
fromstateqon inputa

Note: In the case of a Mealy machine if theinput string is of length n ,


theoutputstring is also of the same length n.

Example:
• Thegiventransitiondiagramismooremachinebecauseeachstateis
associated with output.

• Inthebelowdiagramq0is representing0output,q1is is representing


1 output and q2is representing 2 output.

λ(q0)=0 λ(q1)=1 λ(q2)=2

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 18

w=011theoutputis0010

q0 0 q0 1 q1 1 q0Transitions

0 0 1 0 Outputs

Example:
• The given transition diagram is mealy machine because output
depends on present state and present input.
• Inthebelowdiagram
λ(q0,0)=0 λ(q1,0)=2 λ(q2,0)=0
λ(q0,1)=1 λ(q1,1)=0 λ(q2,1)= 2

w=011theoutputis010

q0 0 q0 1 q1 1 q0Transitions

0 1 0 Outputs

Example:

1. DesignMooremachinetodeterminetheresiduemod3foreachbinary string
treated as a binary integer.

Mooremachinecalculatingresidue mod 3

MooreTable

Present NextState
Output
State 0 1

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 19

q0 q0 q1 0

q1 q2 q0 1

q2 q1 q2 2

TupleRepresentation:

Q={q0,q1,q2} ∆={0,1,2} ∑={0,1}

q0={q0}

λ:λ(q0)=0 δ: δ(q0,0)=q0 δ(q0,1)=q1

λ(q1)=1 δ(q1,0)=q2 δ(q1,1)=q0

λ(q2)=2 δ(q2,0)=q1 δ(q2,1)=q2

Example:
1. DesignMealymachinetodeterminetheresiduemod3foreachbinary string
treated as a binary integer.

MealyTable:

Present NextState Next State


State 0 Output 1 Output
q0 q0 0 q1 1

q1 q2 2 q0 0

q2 q1 1 q2 2

TupleRepresentation:
Q={q0,q1,q2} ∆={0,1,2} ∑={0,1}

q0={q0}

λ:λ(q0,0)=0 δ: δ(q0,0)=q0 δ(q0,1)=q1

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 20

λ(q0,1)=1 δ(q1,0)=q2 δ(q1,1)=q0

λ(q1,0)=2 δ(q2,0)=q1 δ(q2,1)=q2

λ(q1,1)=0

λ(q2,0)=1

λ(q2,1)=2

MooretoMealyConversion:
IfM1=(Q,∑,∆,δ,q0,λ)isaMooremachine,thenthereisaMealymachineM2 equivalent to
Ml.

Procedure:

• LetM2=(Q,∑,∆,δ,q0,λ')anddefineλ'(q,a)tobeλ(δ(q,a))forallstatesq and input


symbols a.

• ThenMlandM2enterthesamesequenceofstatesonthesameinput,an
d with each transition M2emits the output that Mlassociates with
the state entered.

Example:
Construct a Mealy Machinewhich is equivalent to theMoore machine given
by table below.

Present NextState
Output
State 0 1
q0 q3 q1 0

q1 q1 q2 1

q2 q2 q3 0

q3 q3 q0 0

Solution:
λ'(q,a)tobeλ(δ(q,a))
λ'(q0,0)=λ(δ(q0,0)) λ'(q0,1)=λ(δ(q0,1))
=λ(q3) =λ(q1)
=0 =1
λ'(q1,0)=λ(δ(q1,0)) λ'(q1,1)=λ(δ(q1,1))
=λ(q1) =λ(q2)

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 21

=1 =0
λ'(q2,0)=λ(δ(q2,0)) λ'(q1,1)=λ(δ(q2,1))
=λ(q2) =λ(q3)
=0 =0
λ'(q3,0)=λ(δ(q3,0)) λ'(q3,1)=λ(δ(q3,1))
=λ(q3) =λ(q0)
=0 =0

MealyTable:

Present Next State Next State


State 0 output 1 Output
q0 q3 0 q1 1

q1 q1 1 q2 0

q2 q2 0 q3 0

q3 q3 0 q0 0

MealytoMooreConversion:
If M1= (Q,Σ,Δ,δ, λ, q0) is a Mealy machine, then there is a Moore machine M2

equivalent to Ml.
Procedure:
• Determine the number of different output associated with qi in the
next state column.
• Wesplitqiintodifferentstatesaccordingtodifferentoutputassociate
dwith it
For example: q2is associated with two different outputs 0 and 1, so
we split q2into q20 and q21.

Example:
ConstructMooremachineforthegivenmealymachine.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 22

Solution:
• We get two states (q1 and q2) that are associated with different
outputs (0 and 1). so we split both states into q 10, q11and q20, q21.

• Whole row of q1iscopied to q10, q11and whole row of q2is copied to


q20 and q21of the sample transition table of mealy machine.

• The outputs of the next state columns of q 1and q2are depend on


the
previousoutput.Forex.inthefirstrow,q1becomesq11becausetheoutofq

1 is 1in thefourthrow,q2becomes q21because the output ofthe q 2is


1and in the subsequent column q2becomesq20because the output
of q2in that column was 0. and so on

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 23

UNIT-II
Assignment-Cum-TutorialQuestions
SECTION-A

ObjectiveQuestions

1. WhatisthecomplementofthelanguageacceptedbytheNFAshownbelow?
[ ]

2. NFAwithεcanincreasetheprocessingtimeofNFA [True/False]
3. ofastateisthesetofstatesthatcanbereachedbyε- transitions.
4. Thenumberofstates inDFAis thenumberofstatesinNFAforthe
samelanguage. [ ]
(A)greaterthan (B)lessthan (C)equalto (D)none
5. Given a Non-deterministic Finite Automaton (NFA) with states p and r
as initial states and final states respectively and transition table as

given below:
TheminimumnumberofstatesrequiredinDeterministicFiniteAutomaton
(DFA) equivalent to NFA is [ ]
(A) 5 (B) 4 (C)3 (D)2
6. Theoutputin machineisassociatedwithtransition. [ ]
(A)Moore (B) Mealy (C)both (D)DFA
7. The twostates q 1 andq 2 are saidtobe ifboth δ (q 1,a)and

(q2,a) reach final states or both of them reach non final states for all
a∈ ∑.
8. For a Moore machine if the input string is of length n, the output
string is of length n + 1. [True/False]
9. InaMealymachineiftheinputstringisoflengthn,theoutputstringisof
length .
(A)n (B)n+1 (C)2n (D)n+2
10. Chooseincorrectstatement. [ ]
(A) MooreandMealymachinesareFSM’swithoutputcapability.
(B) AnygivenMooremachinehasanequivalentMealyMachine.
(C) AnygivenMealymachinehasanequivalentMooreMachine.
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 24

(D) MooreMachineinnota FSM.

11. AllMooreMachinehaveanequivalentFiniteAutomata. [True/False]


12. Whichofthefollowingstatementistrue? [ ]
(A) AMealymachinehasnoterminating state
(B) AMooremachinehasnoterminatingstate
(C) ConvertingfromMealyintoMooremachineandviceversaispossible
(D) Allofthese
13. TheoutputalphabetinMooremachinecanberepresentedformallyas
(A)∆ (B)∑ (C)δ (D)λ [ ]
14. Considerthetable [ ]

NextState
Present
State
state output state output
q0 q0 0 q1 1
q1 q2 2 q0 0
q2 q1 1 q2 2

Iftheinitialstateisq0.Whatistheoutputsequenceforthestring101?
(A)0012 (B)122 (C)112 (D)0122

SECTION-B
SUBJECTIVEQUESTIONS
1. Considerthefollowingfiniteautomatonwith□-
movesObtainequivalent automaton without □-moves.

2. ConstructNFAforthesetofstringsin(0+1)*suchthatsometwo0’sare
separated by a string whose length is 4i, for some i≥0.
3. ConstructaNFAwithout ∈forthefollowingNFAwith∈.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 25

4. Defineε-closure.Findtheε-closuresoftheeachstateinthefollowingε-NFA.

5. ConstructanequivalentDFAforaNDFAM=({q1,q2,q3},q1,q3)whereδis
givenby
δ(q1,0)={q2,q3}, δ(q1,1)={q1},
δ(q2,0)={q1,q2}, δ(q2,1)=∅
δ(q3,0)={q2}, δ(q3,1)={q1,q2}

6. ConstructanequivalentDFAforthefollowingNFA

7. VerifywhetherthefollowingFAisequivalent?

8. FindtheequivalencebetweenM1&M2

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 26

9. Constructtheminimumstateautomatonequivalenttothetransitiondiagram

10. ConstructaminimumstateautomatonequivalenttoagivenautomatonM
whosetransitiontableisdefinedbytable

11. Explainaboutthefiniteautomatawithoutputsindetail.
12. ConstructaMealymachinewhichisequivalenttotheMooremachine
defined by table

13. ConstructaMooremachineequivalenttotheMealymachineMdefinedby

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 27

14. Designa Mealymachinethatusesitsstates


torememberthelastsymbolread and emits output ‘y’ whenever
current input matches to previous one, and emits n otherwise
15. Design a Moore machine to determine the residue mod 4 for each
binarystring treated as integers.
16. Construct aMooremachine that takesset ofall strings over {a,b} as
input and prints ‘1’ as output for every occurrence of ‘ab’ as a
substring.
17. Construct a Mealy machine which can output EVEN or ODD
according as the total number of 1’s encountered is even or odd.
The input symbols are 0 and 1.
18. Give Mealy and Moore machines for the following process: For
input from (0+1)*, if the input ends in 101, output A; If the input
ends in 110 output B; otherwise output C.

SECTION-C
QUESTIONS AT THE LEVEL OF GATE

1. Let denotethetransitionfunctionand
denotetheextendedtransition functionoftheε-
NFAwhosetransitiontableisgivenbelow:

[GATE2017(Set2)]

Then (q2,aba)is [ ]
(A)∅ (B){q0,q1,q3} (C) {q0,q1,q2} (D){q0,q2,q3}

2. Adeterministicfiniteautomation(DFA)DwithalphabetΣ={a,b}isgivenbelow

[GATE2011]
WhichofthefollowingfinitestatemachinesisavalidminimalDFAwhich
accepts the same language as D? [ ]

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 28

3. Considerthefollowingfinitestateautomaton [ ]

The minimum state automaton equivalent to the above FSA has the
followingnumber of states [GATE 2007 ]
(A)1 (B)2 (C)3 (D)4
4. The followingdiagramrepresentsa finite state machinewhich
takesasinput a binary number from the least significant bit.
[GATE 2005]

Whichoneofthefollowingistrue? [ ]
(A)Itcomputes1’scomplementoftheinputnumber
(B)Itcomputes2’scomplementoftheinputnumber
(C)Itincrementstheinputnumber
(D)Itdecrementstheinputnumber

5. The finite state machine described by the following state diagram


with A as starting state, where an arc label is x/y and x stands for
1-bit input and y stands for 2-bit output [ ][GATE 2002]

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 29

(A) Outputsthesumofthepresentandthepreviousbitsoftheinput
(B) Outputs01whenevertheinputsequencecontains11
(C) Outputs00whenevertheinputsequencecontains10
(D) Noneoftheabove
6. Givenanarbitrarynon-
deterministicfiniteautomaton(NFA)withNstates,the
maximumnumberofstatesinanequivalentminimizedDFAisatleast
(A)N2 (B) 2N (C)2N (D)N! [ ] [GATE2001]

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 1

UNIT-III

Objective:
Tofamiliarizehowtoemployregularexpressions.
Syllabus:
Regular sets, regular expressions, identity rules, construction of
finite Automata for a given regularexpressions and its inter
conversion, pumping lemma of regular sets, closure properties of
regular sets (proofs not required),applications of regular
languages.
LearningOutcomes:
Studentswillbeableto:
• understandtheregularsetsandhowtorepresenttheregularexpr
essions.
• constructfiniteAutomataforagivenregularexpressionandviceversa.
• listclosurepropertiesofregularlanguages.
• understandthedifferentapplicationsofregularlanguages.

LearningMaterialRegul
ar set:
A language is a regular set (or just regular) if it is the set accepted
by some finite automaton.
Example:
L= {0, 1, 10, 00, 01, 11, 000, 101,.................} is a regular set
representing any no of 0’s and any no of 1’s.

Regularexpression:
Thelanguages acceptedby finiteautomata are easily described by
simple expressions called regular expressions.

Let Σbean alphabet.Theregular expressions overΣand the sets that they


denote are defined recursively as follows.

1) Øisaregularexpressionanddenotestheemptyset.

2) εisaregularexpressionanddenotestheset{ε}.
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 2

3) ForeachainΣ,aisaregularexpressionanddenotestheset{a}.

4) IfrandsareregularexpressionsdenotingthelanguagesRandS,
respectively, then

(r+s),(rs),and(r*)areregularexpressionsthatdenotethesetsRUS,RS,
and R*, respectively.

SomeExampleson Regularexpressions

1. Writeregularexpressionsforeachofthefollowinglanguagesover
∑={0,1}.

a) Thesetrepresenting{00}.
00
b) Thesetrepresentingallstringsof0'sand1's.
(0+1)*
c) Thesetofallstringsrepresentingwithatleasttwoconsecutive0’s.
(0+1)*00(0+1)*
d) Thesetofallstringsendingin011.
(0+1)*011
e) The set of all strings representing any number of 0's followed
by any number of 1’s followed by any number of 2's.
0*1*2*
f) Theset of all stringsstartingwith011.
011(0+1)*
2. Writeregularexpressionsforeachofthefollowinglanguagesover
∑={a, b}.

a) Thesetofallstringsendingwitheitheraorbb.
(a+b)*(a+bb)
b) Theset of strings consisting of even no. of a’s followed by
odd no. of b’s.
(aa)*(bb)*b
c) Thesetofstringsrepresentingevennumberofa’s.
(b*ab*ab*)*+b*

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 3

IdentityRulesRelatedtoRegularExpressions

Givenr,sandtareregularexpressions,thefollowingidentitieshold:
• ∅*=ε
• ε*=ε

• r+=rr*=r*r

• r*r*=r*

• (r*)*=r*

• r+s=s+r

• (r+s) +t=r+(s+ t)

• (rs)t=r(st)

• r(s+t)=rs+rt

• (r+ s)t=rt+st

• (ε+r)*=r*

• (r+s)*= (r*s*)*=(r*+ s*)*=(r+s*)*

• r+∅=∅+r=r

• rε=εr=r

• ∅L=L∅=∅

• r+r=r

• ε+rr*=ε+r*r=r*

ConstructionofFiniteautomataforagivenregularexpression

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 4

EquivalenceofFiniteAutomataandRegularExpressions
• Thelanguagesacceptedbyfiniteautomataarepreciselythe
languages denotedby regularexpressions.
• Foreveryregular expressionthereisanequivalentNFAwithε-
transitions.
• ForeveryDFAthereisaregularexpressiondenotingitslanguage.

Letrbearegularexpression.ThenthereexistsanNFAwithε- transitions that


accept L(r).
Zerooperators:
Theexpressionrmustbeε,Ø,oraforsomeainΣ.TheNFA’sforzero
operatorsare

Oneormoreoperators:
Letrhaveioperators.Therearethreecasesdependingontheformofr.
Case1:Union(r=rl+r2.)
ThereareNFA’sM1=(Q1,∑1,δ1,q1,{f1})andM2=(Q2,∑2,δ2,q2,{f2})
withL(M1)=L(r1)andL(M2)=L(r2).

Construct
M=(Q1∪Q2∪{q0,f0},∑1∪∑2,δ,q0,{f0})whereδisdefinedby

i) δ(q0,ε)={q1,q2}

ii) δ(q, a) = δ1(q,a) forqin Q1-{f1} andain ∑1∪{ε}

iii) δ(q, a) = δ2(q,a) forqin Q2-{f2} andain ∑2∪{ε}

iv) δ(f1,ε)=δ1(f2,ε)={f0}

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 5

L(M)=L(M1)∪L(M2)

Case2:Concatenation(r=r1r2).

Let M1 and M2 be as in Case 1 and construct M = (Q1∪Q2,∑1∪∑2,


δ, q1, {f2})

whereδisdefinedby

i) δ(q, a) = δ1(q,a) forqin Q1-{f1} andain ∑1∪{ε}

ii) δ(f1,ε)={q2}

iii) δ(q,a)=δ2(q,a)forqinQ2andain∑2∪{ε}

L(M)={xy|xisinL(M1)andyisinL(M2)}andL(M)=L(M1)L(M2)

Case3:Closure(r= r1*)

LetM1=(Q1,∑1,δ1,q1,{f1})andL(M1)=r1.

ConstructM=(Q1∪{q0,f0},∑1,δ,q0,{f0}),whereδisdefinedby

i) δ(q0,ε)=δ(f1,ε)={q1,f0}

ii) δ(q, a) = δ1(q,a) forqin Q1-{f1} andain ∑1∪{ε}

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 6

Example:
1.ConstructanNFAfortheregularexpression01*+1

Regularexpressionisoftheformr1+r2,wherer1=01*andr2=1.
The automaton for r2is

Expressr1asr3andr4,wherer3=0andr4=1*

The automaton for r3is

r4isr5*wherer5=1 The

NFA for r5is

ToconstructanNFAforr4=r5* usetheconstructionofclosure.The
resulting NFAfor r4 is

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 7

Then,for r1=r3r4usetheconstructionofconcatenation.

Finally,usetheconstruction ofuniontofindtheNFAforr= r1+r2

ConstructionofregularexpressionsforthegivenfiniteAutomata:Arde
n’s Theorem
LetPandQbetworegularexpressionsoverΣ,andifPdoesnotcontain
epsilon,thenR=Q+RPhasauniquesolutionR=QP*.
Procedure:
Assumethegivenfiniteautomatashouldnotcontainanyepsilons.
Step1:FindthereachabilityforeachandeverystateingivenFinite
automata.
Reachabilityofastateisthesetofstateswhoseedgesenterintothatstate.
Step2:Fortheinitialstateoffiniteautomata,addepsilontothe
reachability equation.
Step3:SolvetheequationsbyusingArden’sTheorem.
Step4:Substitutetheresultsofeachstateequationintothefinalstate
equation,to get the regularexpression forthe given DFA.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 8

Example:
1.Constructregularexpressionforthegivenfiniteautomaton.

ThegivenFiniteAutomataisnothavingany□’s(epsilons).

Step1:FindthereachabilityforeachandeverystateingivenFinite
automata.
Reachabilityofastateisthesetofstateswhoseedgesenterintothatstate.
q0=q00 1
q1=q01+q10+q21 2
q2=q11+q20 3
Step2:Fortheinitialstateoffiniteautomata,addepsilontothe
reachability equation.
q0=q00+□
Step3:SolvetheequationsbyusingArden’sTheorem.
Afterapplyingarden’stheoremforequation3
q2=q110* 4
Substituteequation4inequation2
q1=q01+q10+q110*
q1=q01+q1(0+10*) 5
Applyarden’stheoremonequation5
q1=q01(0+10*)*___________6
Applyarden’stheoremonequation1
q0=q00+□
q0=□0* 7
Substituteequation7inequation6
q1=□0*1(0+10*)*_____________8
Step4:Substitutetheresultsofeachstateequationintothefinalstate
equation, to get the regularexpression for the given DFA.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 9

q2=□0*1(0+10*)*10*
Therefore,theregularexpressionforthegivenDFAis0*1(0+10*)*10*.

PumpingLemmaforRegularSets:
• Pumping lemma, which is a powerful tool for proving certain
languages non-regular.
• It is also useful in the development of algorithms to answer
certain questions concerning finite automata, such as
whether the language accepted by a given FA is finite or
infinite.
Lemma
LetLbearegularset.Thenthereisaconstantnsuchthatifzisanyword
inL, and|z|> n, we maywrite z=uvwinsuch awaythat|uv|≤ n, v ≥
1,
andforalli>0,uviwisinL.Furthermore,nisnogreaterthanthenumber
ofstatesofthesmallestFAacceptingL.
Example:
The set L = {0i2|i is an integer, i≥1],which consists of all strings of 0’s
whoselength isaperfectsquare,isnotregular.
AssumeLisregularandletnbethe
integerinthepumpinglemma. Let z = 0n2.
Bythe pumpinglemma,0n2maybewrittenasuvw,where 1≤|v|≤nand
uviwisinLforalli.Leti=2,n2<|uv2w|<n2+n<(n+1)2.
That is, the length of uv2w lies properly between n2and (n +1)2,
and is thus not a perfect square.
Thus uv2w is not in L, a
contradiction.
WeconcludethatLisnotregular.
ClosurePropertiesof RegularSets:
• Theregular sets areclosed under
union,concatenation,andKleene closure.
• Theclassofregularsetsisclosedundercomplementation.Thatis,i

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 10

fL is a regular set and L ⊆ ∑*, then ∑* - L is a regular set.


• Theregularsetsareclosedunderintersection.
• Theclassofregularsetsisclosedundersubstitution.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 11

• The class of regular sets is closed under homomorphism and


inverse homomorphism.
• Theclassofregularsetsisclosedunderquotientwitharbitrarysets.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 12

UNIT-III
Assignment-Cum-TutorialQuestions
SECTION-A

ObjectiveQuestions
1. Thelanguagesacceptedbyfiniteautomataareeasilydescribedbysi
mple expressions called .
2. A language is a ifit is theset accepted by
somefinite automaton.
3. WhatisthesolutionforequationR=Q+RP(ifPandQareREandPdoes
notcontainε)? [
(a)R=QP* (b)R=QP (c)R=PQ* (d)R=P*Q*

4. ∅+R= .
5. ∅*= .
6. ε*= .
7. ε+rr*=r* [True/False]
8. Pumpinglemmaisgenerallyusedforproving [ ]
(a) agivengrammarisregular
(b) agivengrammarisnotregular
(c) whethertwogivenregularexpressionsareequivalent
(d) noneoftheabove

9. Regularsetsareclosedunder [ ]
(a) Union (b)concatenation
(c)Kleeneclosure (d)Alloftheabove

10. a+bdenotestheset . [ ]
(a){a,b} (b){ab} (c){a} (d){b}

11. Thesetofallstringsof{0,1}havingexactlytwo0’sis [ ]
(a)1*01*01* (b){(0+1)*} (c){11+0}* (d){00+11}*
12. Theregularexpressiontorepresentallstrings withlengthatmost2over
{a,b}is .
(a)ε (b) ε+(a+b)+(a+b).(a+b) (c)(a+b) (d)(a+b).(a+b)
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 13

13. Whichoneofthefollowinglanguagesoverthealphabet{0,1}is
described by the regular expression: (0+1)*0(0+1)*0(0+1)*? [
]
(a) Thesetofall stringscontainingthesubstring00.
(b) Thesetofallstringscontainingatmosttwo 0’s.
(c) Thesetofallstringscontainingatleasttwo0’s.
(d) Thesetofallstringsthatbeginandendwitheither0or1.
14. Consider the languages L1 = □and L2 = {0}. Which one of the
following represents L1 L2 * + L1* [ ]
(A){□} (B)Ø (C)0* (D){□,0}
15. WhatistheregularexpressionforthegivenDFA?

(a)(0+1)* (b)0(0+1)* (c)0 (d)(0+1)*0

16. Whichofthefollowinglanguagesarenotregular? [ ]
(a)L=an|n>=1(b)L=anbm|n,m>=1 (c)anbn|n>=1 (d)a2n|n>=0
17. WhatistheregularexpressionforthegivenDFA? [ ]

(a)0*1+ (b) 0*1* (c)1*0* (d) 1*0+

SECTION-B
SUBJECTIVEQUESTIONS
1. Defineregularsetandregularexpression.
2. StateArden’sTheorem.
3. ListtheclosurepropertiesofRegularLanguages.
4. Explainpumpinglemmaforregularlanguageswithanexample.
5. Writetheregularexpressionforallstringsendingin1101overthe
alphabet {0, 1}.
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 14

6. Designaε-NFAfortheregularexpressiona*bc|ab*|c*.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 15

7. ConstructNFAwithε-movesfortheregularexpression10+(0+11)0*1
8. ConstructFiniteautomatafortheregularexpression1(01+10)*00.
9. Whatispumpinglemmaforregularsets?Showthatthelanguage
L={anbncn|n>=1} isnotregular.
10. Constructfiniteautomationtoaccepttheregularexpression(0+1)*
(00+11)(0+ 1)*.
11. Usingpumpinglemma,showthefollowinglanguageisnotregu
lar: L= {w □{0,1}*|the number of 0’s in w is a perfect
square}
12. ConstructtheregularexpressionforthefollowingDFA.

13. ConstructregularexpressionforthefollowingDFA.

14. ConstructregularexpressionforthegivenDFA.

SECTION-C
QUESTIONS AT THE LEVEL OF GATE
1. ThenumberofstatesintheminimumsizedDFAthatacceptsthe
language defined by the regular expression (0+1)*(0+1)(0+1)* is
.
[GATE2016Set-B]
2. Whichoftheregularexpressionsgivenbelowrepresentthefollowing
DFA? [ ] [GATE 2014 Set-1]
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 16

I) 0*1(1+00*1)*
II) 0*1*1+11*0*1
III) (0+1)*1

(a)IandIIonly (b)IandIIIonly

(c)IIandIIIonly (d) I, IIand IIIonly

3. Consider the languages L1 = Ø and L2 = {a}. Which one of the


following represents L1 L2 * UL1* [] [GATE2013]
(a){□} (b)Ø (c)a* (d){□,a}
4. Let L = {w∈(0 + 1)*|w has even number of 1s}, i.e. L is the set of
all bit
stringswithevennumberof1s.Whichoneoftheregularexpressions
below represents L? [][GATE 2010]
(a)(0*10*1)* (b)0*(10*10*)*
(c)0*(10*1*)*0* (d)0*1(10*1)*10*
5.Thelanguage accepted bythis automatonisgiven bytheregular
expression [ ][GATE2007]
(a)b*ab*ab*ab* (b)(a+b)* (c)b*a(a+b)* (d)b*ab*ab*

6. ConsiderthelanguageL=(111+11111)*.Theminimumnumberofst
atesin any DFA accepting this language is: [][GATE 2006]
(a)3 (b)5 (c)8 (d)9

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 1

UNIT-IV

Objective:
Tounderstandregulargrammarsandcontextfreegrammars.

Syllabus:
Chomsky hierarchy of languages, Regular grammars- right linear
and left linear grammars, Equivalence between regular linear
grammar and FA and its inter conversion, Context free grammar,
derivation trees, Sentential forms, right most and left most
derivation of strings

LearningOutcomes:
Studentswillbeableto:
• understandChomskyhierarchyoflanguages.
• understand and construct the regular grammarfor the given
regular language or regular expression.
• convertRegularGrammarintoequivalentDFAandviceversa.
• constructContextfreegrammarforthegivenlanguage.
• constructrightmost,leftmostderivationandderivationtreesfo
rthe given string and grammar.
LearningMaterialChomsky
hierarchyoflanguages:
ThefourclassesoflanguagesareoftencalledtheChomskyhierarchy,aft
er Noam Chomsky, who defined these classes as potential models
of natural languages.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 2

Chomskyclassifiesthegrammarintofourtypes:
Production
Grammar Languages Automaton
rules

Recursively
enumerable Turing
Type0 αβ
/ Phrase machines
Structured

Context- Linear- αβ
Type1
sensitive bound |α|<=|
automata β|

Push-down
Type2 Context-free Aα
automata

A w
Finite-state
Type3 Regular automata AwB

ABw

RegularGrammar:
A right-orleft-lineargrammariscalledaregulargrammar.
Right-LinearGrammar:
If all productions of a grammar are of the form AwB or Aw, where
A and B arevariables and w is a (possiblyempty) string of
terminals, then we say the grammar is right-linear.
Example:
Representthelanguage0(10)*bytheright-lineargrammar.
The language generated by the given Regular
Expression is L = {0, 010, 01010, 0101010,
......................................................}
Right-LinearGrammar:

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 3

S0A

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 4

A10A|ε

Left-LinearGrammar:
IfallproductionsareoftheformABworAw,wecallitleft-linear.
Example:
Representthelanguage0(10)*bytheleft-lineargrammar.
The language generated by the given Regular
Expression is L = {0, 010, 01010, 0101010,
......................................................}
Left-
LinearGramm
ar: SS10 |0
Equivalenceofregulargrammarsandfiniteautomata:
Alanguageisregularif andonlyifithasaleft-lineargrammarandifand only
if it has a right-linear grammar.
ConstructionofaRegularGrammarforagivenDFA:
LetM=({q0,q1...qn},∑,δ,qo,F).WeconstructGasG=({A0,A1,...............,
An},∑,P,A0)
wherePisdefinedbythefollowingrules:
(i) AiaAjisincludedinPifδ(qi,a)=qj∉F.
(ii) AiaAjandAiaareincludedinPifδ(qi,a)=qj∈F.
Note:WecanconstructonlyrightlineargrammarforthegivenDFA.
If we want to constructleft linear grammarfor the given DFA, reverse
the edges of the given DFA and interchange initial and final states.
Example:
1. Construct regular grammar (right linear grammar) for the given
DFA.

GivenM=({q0,q1},{a,b},δ,qo,{q1})
ConstructG=({A0,A1},{a,b},P,A0)wherePisgiven by

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 5

(i) AiaAjisincludedinPifδ(qi,a)=qj∉F.
δ(q0,a)=q0∉F⇒A0aA0

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 6

(ii) AiaAjandAiaareincludedinPifδ(qi,a)=qj∈F.
δ(q0, b) = q1∈ F ⇒A0bA1 and A0b
δ(q1, a) = q1∈ F ⇒A1aA1 and A1a
δ(q1,b)=q1∈F⇒A1bA1andA1b
∴Pisgivenby
A0aA0, A0bA1, A0b
A1aA1, A1a, A1bA1, A1b
StepstoconvertFiniteAutomatatoLeftLinearGrammar:
Step 1: Reverse all the edges of the givenautomata and interchange
initial state and final states.
Step2:RepresenttheproductionsusingLeftLinearGrammar.
Example:
2. ConstructleftlineargrammarforthegivenDFA.

Step 1:Reverse all theedges of the given automataand


interchange initial state and final states.

Step2:RepresenttheproductionsusingLeftLinearGrammar.
BBa BAa
BBb Ba
ConstructionofaDFAforagivenRegularGrammar:
LetG=({A0, A1,........,An},∑,P,A0).WeconstructaDFAMwhose
(i) statescorrespondtovariables.
(ii) initialstatecorrespondstoA0.
(iii) transitionsinMcorrespondtoproductionsinP.Asthelast
productionappliedinanyderivationisoftheformAia,the
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 7

correspondingtransitionterminatesatanewstate,andthisisthe unique
final state.
WedefineMas({q0,q1...qn,qf},∑,δ,qo,{qf})whereδisdefinedas follows:
(i) EachproductionAiaAjinducesatransitionfromqitoqjwith
label a,
(ii) EachproductionAkainduces atransitionfromqktoqfwith
label a.
Example:
1. G=({A0,A1},{a,b},P,A0)wherePconsistsofA0aA1,A1bA1, A1a,
A1bA0. Construct a DFA M accepting L(G).

A0aA1 induces a transition from q0 toq1 with label a.


A1 bA1 inducesatransitionfromq1toq1withlabelb.
A1bA0 induces a transition from q1 toq0 with label
b. A1a induces a transition from q1 to qf with label
a.

M=({q0, q1, qf} , ∑,δ, qo, {qf}),whereq0andqfcorrespondtoA0andA1


respectively and qf is the new final state introduced.

2. ConstructFinite Automataforthe grammarwhich consists of the


productions
AaB|bA|b B aC |
bB
CaA|bC|a

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 8

Context-FreeGrammar:
Acontext-freegrammar(CFGorjustgrammar)isdenotedG=(V,T,P,S), where
• VandTarefinitesetsofvariablesandterminals,respectively.
• P is a finite set of productions; each production is of the form
A,αwhere A is a variable and α is a string ofsymbols from (V ∪
T)*.
• Sisaspecialvariablecalledthestartsymbol.

The language generated by G[denotedL(G)]is {w|wis in T*and


}. That is, a string is in L(G) if:
1) Thestringconsistssolelyofterminals.
2) ThestringcanbederivedfromS.
WecallLacontext-freelanguage(CFL)ifitisL(G)for some CFGG.
Note:ClanguageisanexampleforContextFreeLanguage.
Examples:
1. WriteCFGforthelanguageL={anbn|n>=1}.
L={ab,aabb,aaabbb,aaaabbbb,aaaaabbbbb,...........}
G=({S},{a,b},P,S)
P: S->aSb|ab
(Or)
S->aSB
S -> aB
B -> b

2. WriteCFGforthelanguageL={anbm|n,m>=1}.
L= {a,b,ab,aab,.........abb,aabb, aaabbb,
aaaabbbb, aaaaabbbbb, }
G = ({S, A, B}, {a, b},
P, S) P: S -> AB
A->aA|a
B->bB|b

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 9

3. WriteCFGforthelanguageL={aa,ab,ba,b
b} G = ({S, A}, {a, b}, P, S)
P: S->AA
A->a|b
4. WriteCFGforthelanguageL={an|n>=0}.
L={ε,a,aa,aaa,aaaa,aaaaa,aaaaaa,...............................}
G=({A},{a},P,A)
P: A->aA|ε
5. WriteCFGfortheregularexpression(a+b)*.
L={ε,a,b,aa,ab,ba,bb,aaa,abb,aba,................................}
G=({S},{a,b},P,S)
P: S->aS|bS|ε
6. Write CFG to generate all strings of {a, b} whose length is
atleast 2. L= { aa, ab , ba, bb, aaa,abb,aba,....}
G =({S,A,B},{a,b},P,S)
P: S -> AAB
A->a|b
B->aB|bB|ε
7. Write CFG to generate all strings of {a, b} whose length is
atmost 2. L= { ε, a,b, aa, ab , ba, bb}
G=({S,A},{a,b},P,
S) P: S -> AA
A->a|b|ε
8. WriteCFGto generatepalindromes over {a,b}.
L={ε,a,b,aa,bb,aba,bab,aaaa,abba,.....................}
G=({S},{a,b},P,S)
P: S->aSa|bSb
S -> a |b |ε
9. WriteCFGtogenerateequalnumberofa’sandb’s.
L={ab,ba,aabb,abab,bbaa,baba,.............................}
G=(V,T,P,S),where V={S,A,B},T={a,b},SandP. P:
S -> aB A ->bAA
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 10

S->bA B->b
A->a B->bS
A->aS B->aBB

Sentential Form:
Astringofterminalsandvariablesαiscalledasententialformif

Derivation:
Derivation isthe processof
applyingproductionsrepeatedlytoexpand non- terminals in terms
of terminals or non-terminals, until there are no more non-
terminals.
A derivation can be either Leftmost derivation or Right
mostderivation.
Leftmostderivation:
If at each step in a derivation a production is applied to the
leftmost variable,thenthederivationissaidtobeleftmost.
Example:
ConsiderthegrammarG=({S,A},{a,b},P, S),wherePconsistsof
S aAS |a
ASbA|SS|ba
Thecorrespondingleftmostderivationis
S=>aAS=>aSbAS=>aabAS=>aabbaS=>aabbaa.
Rightmostderivation:
Aderivationinwhichtherightmostvariableisreplacedateachstepis
said to be rightmost.
Example:
ConsiderthegrammarG=({S,A},{a,b},P, S),wherePconsistsof
S aAS |a
ASbA|SS|ba
Thecorrespondingrightmostderivationis
S=>aAS=>aAa=>aSbAa=>aSbbaa=>aabbaa.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 11

Note:“If w is in L(G) for CFG G, then w has at least one parse tree,
and corresponding to a particular parse tree, w has a unique
leftmost and a unique rightmost derivation.”
DerivationTrees(or)Parsetree:
The derivations in a CFG can be represented using trees.Such
trees representing derivations are called derivation trees.
LetG=(V,T,P,S)beaCFG.Atreeisaderivation(orparse)treeforGif:
1) Everyvertexhasalabel,whichisasymbolofV∪T∪{ε}.
2) ThelabeloftherootisS.
3) IfavertexisinteriorandhaslabelA,thenAmustbe inV.
4) IfnhaslabelAandverticesn1,n2,n3,...,nkarethesonsofvertex
n, in order from the left, with labels X1, X2, ......., Xk,
respectively, then AX1X2 .......Xkmust be a production in P.
5) Ifvertex n has labelε, then n is a leaf and is the only son
of its father.
Example:
Consider the grammar G =({S, A}, {a, b], P, S), where P consists of
S aAS |a
ASbA|SS|ba
Constructaderivationtreeforthestring“aabbaa”
A derivation tree is a natural description of the derivation of a
particular
sententialformofthegrammarG.Ifwereadthelabelsoftheleavesfroml
eft to right, we have a sentential form. We call this string the
yield of the derivation tree.

S=>aAS=>aSbAS=>aabAS=>aabbaS=>aabbaa.
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 12

Note:Someleavescouldbelabelledbyε.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 13

UNIT-IV
Assignment-Cum-TutorialQuestions
SECTION-A

ObjectiveQuestions
1. TheClanguageis [ ]
a) Acontextfreelanguage b)Acontextsensitivelanguage
c)Aregularlanguage d)None

2. Everyregulargrammariscontextfreegrammar. (True|False)

3. Thefiniteautomataacceptsthefollowinglanguage: [ ]
a) Contextfreelanguage b)regularlanguage
c)Contextsensitivelanguage d)alloftheabove

4. Context-freegrammar canberecognizedby [ ]
a) FiniteAutomata b)LinearboundedAutomata
c)PushdownAutomata d)both(b)and(c)

5. ThelanguageacceptedbyaTuringMachine: [ ]
a) Type0 b)Type1 c)Type2 d)Type3

6. Matchthefollowing
1. Context FreeLanguage a.TuringMachine [ ]
2. RecursivelyEnumerable b.FiniteAutomata [ ]
3. RegularLanguage c.LinearBoundedAutomata [ ]
4. ContextSensitiveLanguage d.PushDownAutomata [ ]

7. Foreveryrightlineargrammar,therewillbe anequivalentFA.
[True/False]
8. RecursivelyEnumerablelanguageisalsocalledas .

9. Acontextfreegrammaris [ ]
a) Type0 b)Type1 c)Type2 d)Type3

10. WhichwordcanbegeneratedbyS->d|bA,A->d|ccA [ ]
a) bccccd b)aabccd c)ababccd d)abbbd

11. Whichofthefollowingstringsisinthelanguagedefinedbygrammar
S0A, A1A|0A|1 [ ]
a)01100 b)00101 c)10011 d)11111

12. Recognize the CFL for the given CFG. [


] S-
>aB| bA,
A-> a|aS|bAA,
B->b|bS|aBB
a) stringscontainequalnumberofa'sandequalnumberofb's.
b) stringscontainoddnumberofa'sandoddnumberofb's.
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 14

c) stringscontainoddnumberofa'sandevennumberofb's.
d) stringscontainevennumberofa'sandevennumberofb's
13. Given the following productions of a grammar:
[ ] SaA| aBB AaaA |ε
B bB| bbC C B
Whichofthefollowingistrue?
a) Thelanguagecorrespondingtothegivengrammarisasetofeven
number of a’s.
b) Thelanguagecorrespondingtothegivengrammarisasetofodd
number of a’s.
c) Thelanguagecorrespondingtothegivengrammarisasetofeven
number of a’s followed by odd number of b’s.
d) Thelanguagecorrespondingtothegivengrammarisasetofodd
number of a’s followed by even number of b’s.

14. AregulargrammarforthelanguageL={anbm|nisevenandmis
even}is [
a)SaSb|X;XbXa|ε b)SaaS|X;XbSb|ε
c)SaSb|X;XXab|ε d)SaaS|X;XbbX|ε

15. Whichoftheregularexpressionscorrespondstothisgrammar?
SAB|AS Aa|aA Bb
a)(aa)*b b)aa*b c)(ab)* d) a(ab)*[

16. Identifythe language generatedbythe followinggrammar


[
]
SaS|bS|abA
AaA|bA|ε
a) L=x|abisasubstringofx,x∈{a,b}*
b) L=x|aisasubstringofx,x∈{a,b}*
c) L=x|bisasubstringofx,x∈{a,b}*
d) L=x|baisasubstringofx,x∈{a,b}*

17. TheCFGSaS|bS|a|bisequivalenttotheregularexpression
a) (a*+b)*b)(a+b)* c) (a+b)(a+b)* d)(a+b)(a+b) [ ]

18. TheregulargrammarforthegivenFAis [ ]

a) AaA | bB | a c)AaA|bB|b
BbA|aB|b BbA|aB|a
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 15

b) AaA | bB | ε d)AbA|aB|a
BbA|aB|ε BaA|bB|b

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 16

SECTION-B
SUBJECTIVEQUESTIONS
1. ShowtheVenndiagramofChomskyhierarchylanguageandtheir
counterpart automata.
2. DefineRegulargrammarwithanexample.
3. DefineContextFreeGrammarwithanexample.
4. What issententialform?Explainwithan example.
5. Explainderivation treewith anexample.
6. DefineLMDandRMD.
7. Showthatid+id*idcan be generatedby twodistinct derivation
treesfor the grammar
EE+E|E*E|(E)|id
8. DesignCFGforoddpalindromes?
9. LetGbethegramma
r S aB |bA
Aa |aS |bAA Bb|
bS|aBB.
Forthestringaaabbabbbafinda
i. Leftmostderivation
ii. Rightmostderivation
iii. ParseTree
10. Obtaintheright lineargrammarforthefollowingFA.

11. ObtainaRight LinearGrammarforthelanguageL={a nbm|n>=2


, m>=3}

12. Obtaintheleftlineargrammarfor(11+01)*101.
13. ConvertthefollowingDFAtoRegulargrammar

14. Isthefollowinggrammarambiguo
us? S AB|aaB
A>a|Aa Bb

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 17

15. Find the language generated by the following


grammar. SSS Saa Sε

Sa ⃒b ⃒Є}
16. DrawaderivationtreeforthestringabaabafortheCFGgivenbyG where
P = {SaSa SbSb

17. Obtainarightlineargrammarandleftlineargrammarforthefollo
wing FA.

SECTION-C
QUESTIONS AT THE LEVEL OF GATE

1. G1:SaS|B,Bb|bB [GATE2016]

G2:SaA|bB;AaA|B|□,BbB|□

Which one of the following pairs of languages is generated byG1


andG2, respectively? [ ]

a) {ambn|m>0orn>0}and{ambn|m>0andn>0}

b) {ambn|m>0andn>0}and{ambn|m>0orn>=0}

c) {ambn|m>=0orn>0}and{ambn|m>0andn>0}

d) {ambn|m>=0andn>0}and{ambn|m>0orn>0}

2. S aSa | bSb | a | b [ ] [GATE 2009]


Thelanguagegeneratedbytheabovegrammaroverthealphabet{a,
b}is the of
a) allpalindromes
b) alloddlengthpalindromes
c) stringsthatbeginand
d) allevenlengthpalindromesendwiththesamesymbol

3. Consider the CFG with {S,A,B} as the non-terminal


alphabet{a,b} as the terminal alphabet,S as the start symbol
and the following set of production rules: [GATE 2007]
SaB SbA
Bb Aa
BbS AaS

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 18

BaBB SbAA
Whichofthefollowingstringsisgeneratedbythegrammar? [ ]
a) aaaabb b)aabbbb c)aabbab d)abbbba
4. HowmanyderivationtreesarethereforthegrammarinQuestion3?
a) 1 b)2 c)3 d)4 [ ]

5. [GATE2006]

6. Considertheregulargrammar: [GATE2005]
S→Xa|Ya
X→Za
Z→Sa|□
Y→Wa
W→Sa
where Sis the starting symbol,the setofterminalsis {a}andthe
setof non- terminals is {S, W, X, Y,
Z}.
Wewishtoconstructadeterministicfiniteautomaton(DFA)torecognize
the same language. What is the minimum number of states
required for the DFA? []
a) 2 b)3 c)4 d)5

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 1

UNIT-V

Objective:
To understand and design push down automata’s for a given Context
free language.
Syllabus:
Ambiguity in context free grammars, minimization of Context Free
Grammars, Chomsky normal form, Greibach normal form,
pumping lemma
forContextFreeLanguages,closurepropertiesofCFL(proofsnotrequir
ed), applications of CFLs
Pushdownautomata:
Pushdownautomata,modelofPDA,designofPDA.
LearningOutcomes:
Studentswillbeableto:
• understandambiguityincontextfreegrammars.
• minimizethegivencontextfreegrammar.
• apply Chomsky and Greibach Normal Forms on context
free grammars.
• understandanddesignPDAforgivencontextfreelanguages.
LearningMaterial

Ambiguityincontextfreegrammars:
A context-free grammar G is said to be ambiguous if it has two parse
trees for some word.
(or)
Awordwhichhasmorethanoneleftmostderivationormorethanone
rightmost derivation is said to be ambiguous.

Note:A CFL for which every CFG is ambiguous is said to be an inherently


ambiguous CFL.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 2

Example:
G=({S},{a,b,+,*},P.S),wherePconsistsofSS+S|S*S|a|b We
have two derivation trees for a+ a* b

Twoderivationtreesfora+a*b

Minimizationof Context FreeGrammars:

1) Eliminationofuselesssymbols.

2) Eliminationofε–Productions.

3) EliminationofUnitProductions.
EliminationofUselessSymbols:

LetG=(V,T,P,S)beagrammar.AsymbolXisuselessifitisnotinvolvedin
derivation.

(or)

AsymbolXisuselessifthereisnowayofgettingaterminalstringfromit.

Example:
Considerthegramm
ar SAB |a
Aa

We findthatnoterminalstringis derivable from B.We


thereforeeliminateB and the production S  AB.
Thenthegrammaris
Sa

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 3

Aa

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 4

WefindthatonlySandaappearinsententialforms.Thus({S},{a},{Sa},
S) isan
equivalentgrammarwithnouselesssymbols.

Eliminationofε–Productions:
AproductionoftheformAε,whereAisavariable,iscalledanull production.
IfL=L(G)forsomeCFGG =(V,T,P,S),then L-{ ε} isL(G')foraCFG G' with
no useless symbols or ε-productions.
Example:
Considerthegramm
ar A0B1|1B1
B0B|1B|ε
Remove ε-
productionsfromthegrammar. Bεε is the
null production.
Thenewproductionsaftereliminationofεare
A0B1|1B1|01|11
B0B|1B|0|1

EliminationofUnitProductions:
Aproductionof theformABwhoseright-handsideconsists ofa
single variable is called a unit production.
All other productions, including those of the form A a and ε-
productions, are nonunit productions.
Example:
Considerthegramm
ar S0A|1B|C
A0S |00
B1|A
C01
Removeunitproductionfromthegrammar.
SCandBAaretheunitproductions
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 5

The new productionsaftereliminationofunit productionsare


S0A|1B|01
A0S|00
B1|0S|00
C01
C is a useless symbol. So eliminate C
production. The final set of productions are
S0A|1B|01
A0S |00
B1|0S|00
ChomskyNormalForm:(CNF)
Any context-free language without εisgenerated bya grammar in
which all
productionsareoftheformABCorAa.Here,A,B,andC,arevariables
and a is a terminal.
Step1: Simplifythegrammar.
a) Eliminateε–productions
b) Eliminateunitproductions
c) EliminateUselesssymbols.
The given grammar does not containε–productions, unit productions
and useless symbols.
Itisinoptimizedform.

Step 2:Consider a production in P,of the form A-


>X1X2X3.....Xmwhere
m>=2.IfXiisaterminala,introduceanewvariableCaandaproductionCa
-
>a.ThenreplaceXibyCa.

Step 3:Consider a production A->B1B2B3.....Bmwhere m>=3,create


new variablesD1,D2,....Dm-2andreplaceA-
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 6

>B1B2B3...Bmbythesetofproductions
{A->B1D1,D1->B2D2,..........Dm-3->B m-2Dm-2,Dm-2->Bm-1Bm}

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 7

Example:
Considerthegrammar({S,A,B},
{a,b},P,S)thathastheproductions: S bA |aB
AbAA |aS |a
BaBB|bS|b
Findanequivalent grammarinCNF.

Step1: Simplifythegrammar.
a) Eliminateε–productions
b) Eliminateunitproductions
c) EliminateUselesssymbols.
The given grammar does not containε–productions, unit productions
and useless symbols.
Itisinoptimizedform.
Step2:TheonlyproductionsalreadyinproperformareAaandBb.
So we may begin by replacing terminalson the right by variables,
except in the case of the productionsA  a and B b.
SbAisreplacedbySCbAandCbb.
Similarly, AaS is replaced by A CaS and Caa; AbAA is replaced by
ACbAA; S aB is replaced by SCaB;
BbSisreplacedbyBCbS,andBaBBisreplacedbyBCaBB.
Inthenextstage,theproductionACbAAisreplacedbyACbD1andD1
AA,andtheproductionBCaBBisreplacedbyBCaD2andD2BB.
Step3:TheproductionsforthegrammarinCNFare:

S CbA | CaB D1AA

ACaS|CbD1|aD2BB B
CbS |CaD2|bCa a
Cbb

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 8

GreibachNormalForm:
Everycontext-freelanguageLwithoute canbe
generatedbyagrammarfor which every production is of the form A
aα, where A isa variable, a is a terminal, and α is a (possibly empty) string
of variables.
Lemma 1:Define anA-production tobe a production withvariable A
α α2be aproductioninPand
onthe left.LetG=(V,T,P,S)beaCFG.LetA1B
β |β2|……|βrbe the setofallB-productions.LetG1=(V,T,P1,S) be
B1
obtained from G by deleting the production A αα1Bα 2 from P and
addingtheproductionsAαβ 1α1α 2|α1β2α2|……|α1βrα2. Then L(G) =
L(G1).
α 1|Aα2|……|Aαr be the set
Lemma2:LetG=(V,T,P,S)beaCFG.LetAAα
of A-productions for which A is the leftmost symbol of the right-
hand β |β2|……|βsbethe
side.LetA1 remainingA-
productions.LetG1=(V U {B}, T, P1, S) be the CFG formed by
adding the variable B to V and replacingalltheA-
productionsbytheproductions:

ThenL(G1)=L(G).
Example:
ConverttoGreibachnormalformthegramm
ar G=i{A1,A2,A3},{a,b},PA1),
wherePconsistsofthefollowing:

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 9

WenowapplyLemma2totheproductions

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 10

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 11

PumpingLemmaforCFL's:
LetLbe anyCFL. Thenthere isaconstantn, dependingonlyon
L,such that if z is in L and |z|
≥n,thenwemaywritez=uvwxysuchthat

Example:
ConsiderthelanguageL={aibici|
≥1}.SupposeLwerecontextfreeandlet n be the constant.
Considerz=anbncn.Writez=uvwxysoastosatisfytheconditionsofthe
pumping lemma.
Since |vwx|≤n, it is not possible for vx to contain instances of a’s and
c’s, because the rightmost a is n + 1 positions away from the
leftmost c.
Ifvandx consistofa’s only, thenuwy(thestring uv iwxiy withi=0)has n
b’s and n c’s but fewer than n a’s since |vx|≥ 1.
Thus,uwyisnotoftheformaibici.ButbythepumpinglemmavwyisinL,a
contradiction.
Thecaseswherevandxconsistonlyofb’soronlyofc’saredisposedof similarly.
If vx has a’s and b’s, then uwy has more c’s than a’s or b’s, and
again it is not in L.
If vx containsb’sand c’s, a similarcontradiction
results. We conclude that L is not a context-free
language.
ClosurePropertiesofCFL’s:
• Context-
freelanguagesareclosedunderunion,concatenationand Kleene
closure.
• Thecontext-freelanguagesareclosedundersubstitution.
• TheCFL’s are closedunderhomomorphism.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 12

• TheCFL’sarenotclosedunder intersection.
• TheCFL’sarenotclosedunder complementation.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 13

Applicationsofthepumpinglemma:
The pumping lemma can be used to prove a variety of languages not to
be context free, using the same "adversary" argument as for the
regular set pumping lemma.
Pushdownautomata:

Moves:

ModelofPDA:
• Pushdown automaton has a read-only input tape, an input
alphabet a finite state control, a set of final states, and an
initial state as in the case of an FA.
IIYear–II-Semester 2018-19 CSE
Formal LanguagesandAutomata Theory 14

• In addition to these, it has a stack called the pushdown


store. It is a read-
writepushdownstoreaswecanaddelementstoPDSorremove
elements from PDS.
• A finite automaton is in some state and on reading, an input
symbol moves to a new state.
• The pushdown automaton is also in some state and on
reading an input symbol and the topmost symbol inPDS, it
movestoanewstate and writes (adds) a string of symbols in
PDS.

Instantaneousdescription:
Instantaneous description (ID) is the configuration of a PDA at a
given instant. We define an ID tobe atriple (q,w, γ), whereq isa state,
wa string of input symbols,andγastringofstacksymbols.

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 15

AcceptedLanguages:

Example:
DesignaPDAthataccepts{wwR|
win(0+1)*} L = { ε, 0, 1, 00, 11, 0110, 1001,
.............................................................................}
LetM=(Q,∑,Г,δ,q0,Z0,F)bethePDA
ConsiderM = ({q1,q2}, {0,1}, {0, 1,Z0},δ,q1, Z0,Ø)
δ(q1,0,Z0)={(q1,0Z0)}
δ(q1,1,Z0)={(q1,1Z0)}
δ(q1,0,0)={(q1,00),(q2, ε)}
δ(q1,1,0)={(q1,10)}
δ(q1,0,1)={(q1,01)}
δ(q1,1,1)={(q1,11),(q2, ε)}
δ(q2,0,0)={(q2, ε)}
δ(q2,1,1)={(q2,ε)}
δ(q1,ε,Z0)={(q2,ε}
δ(q2,ε,Z0)={(q2,ε)}
DeterministicPDA:
ThePDAisdeterministicinthesensethatatmostonemoveispossiblefro
m any ID.
FormallywesayaPDAMisdeterministicif:

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 16

EquivalenceofPDA'sandCFL's:

CFGtoPDA Conversion
IfLisacontext-freelanguage,thenthereexistsaPDAMsuchthatL=N(M).

Procedure:

LetL=L(G),whereG=(VN,Σ,P,S)isacontextfreegrammar.

WeconstructaPDA Mas

M=((q),Σ,VNUΣ,Z0,q,δ,Ø)

Whereδisdefinedbythefollowingrules:

R1:δ(q,ε,A)={(q,α)|A->αisinP}

R2: δ(q,a,a)={(q,ε)}foreveryainΣ.

Example:

ConstructapdaMequivalenttothefollowingcontextfreegramm

ar: S->0BB

B->0S|1S|0.

Testwhether0104isinN(M).

Solution:

Define pda A as follows:

A=(({q},{0,1},{S,B,0,1},δ,q,Z0,Ø)

δisdefinedbythefollowingrules:

R1:δ(q,ε,S)={(q,0BB)}

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 17

R2:δ(q,ε,B)={(q,0S),(q,0S),(q,0)}

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 18

R3:δ(q,0,0)={(q,ε)}

R4:δ(q,1,1)={(q,ε)}

String Checking

(q,0104,S)

⊢(q,0104,0BB) byRuleR1

⊢(q,104,BB) byRuleR3

⊢(q,104,1SB) byRuleR2since(q,1S)∈α(q,∧,B)

⊢(q,04,SB) byRuleR4

⊢(q,04,0BBB) byRuleR1

⊢(q,03,BBB) byRuleR3

⊢*(q,03,000) byRuleR2since(q,0)∈α(q,∧,B)

⊢*(q,ε,ε) byRuleR3

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 19

UNIT-V
Assignment-Cum-TutorialQuestions
A. ObjectiveQuestions
1. GrammarthatproducemorethanoneParsetreeforsamewordis:
a) Ambiguous b)Unambiguous [ ]
c)Complementation d)ConcatenationIntersection
2. ForeverygrammartherewillanequivalentgrammarinCNF.
[True/False]
3. Thederivationtreesofstringsgeneratedbyacontextfreegramma
rin Chomsky Normal Form are always binary trees [True |
False]
4. Whichofthefollowingconversionisnotpossible(algorithmically)?
a)RegulargrammartoContext-freegrammar [ ]
b)NondeterministicFSAtoDeterministicFSA
c) NondeterministicPDAtoDeterministicPDA
d) Alloftheabove
5. CFL’sarenotclosedintersectionandcomplementation.[True|False]
6. CFL’sareclosedunder [ ]
a) union b)concatenation c)closure d)All
7. ThegrammarGwiththeproductions [ ]
A→AA|(a)|ε isan
a) Ambiguousgrammar b)Unambiguousgrammar
c) Grammar d)None
8. Identifytheuselesssymbolinthegrammargivenbelow. [ ]
S->AB|C A- B->BC C->b
>a
d) C
a)S b)A c)B
9. Findanequivalentreducedgrammarforthegivengrammar.[ ]
S->0|1|ε S->0S0|1S1
a) S->0|1,S->0S0|1S1|0|1 b)S->0|1,S->SS|0S1|1S1
c)S->0|1,S->00|11 d)None

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 20

10. WhichoneofthefollowingisaChomskyNormalFormgrammar?
[ ]
(i)A->BC|a(ii)A->aA|a|b (iii)A->BCD|a,B->a,C->c,D->d
a)(i)only b)(i)and(iii) c)(ii)and(iii) d)(i),(ii)and(iii)

11. WhichoneofthefollowingisnotaGreibachNormalformgrammar?
[ ]
(i)S->a|bA|aA|bB (ii) S->a|aA|AB (iii)S->a|A|aA
A->a A->a A->a
B->b B->b
a) (i)and(ii) b)(i)and(iii) c)(ii)and(iii) d)(i),(ii) and(iii)
12. L={0n12n|n>=1}is [ ]
a) regular b)context-freebutnotregular
c)context-freebutregular d)None

13. RecognizethelanguageacceptedbythePDAwiththefollowing
moves [ ]
δ(q0,a,Z0)=(q0,aZ0) , δ(q0,a,a)=(q0,aa)
δ(q0,b,a)=(q1,ε) , δ(q1,b,a)=(q1,ε)
δ(q1,c,Z0)=(q2,Z0), δ(q2,c,Z0)=(q2,Z0)
a) L={anbncn|n,m>=1} b)L={anbncm|n,m>=1}
c)L={ambncn|n,m>=1} d)L={ambncm|n, m>=1}
14. ThegrammarsG1andG2are
G1:S->0S0|1S1|0|1|ε
G2:isS->as|asb|X,X->Xa|a.
Whichisthecorrectstatement? [ ]
a) G1isambiguous,G2isunambiguous
b) G1isunambiguous,G2isambiguous
c)BothG1andG2areambiguous
d)BothG1andG2areunambiguous

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 21

B. Descriptivequestions
1. Whatisanambiguousgrammar?Explainwith anexample.
2. DefineUselesssymbolandgiveexample.
3. WhatisanNullproductionandUnitproducation?Explainwithan
example.
4. ListtheapplicationsofCFG.
5. ListtheclosurepropertiesofCFL.
6. ExplainpumpinglemmaforCFL’swithanexample.
7. ExplainthemodelofPDA.
8. Showthatthegrammarisambiguou
s. S → 0A |1B
A→0AA|1S|1
B→ 1BB|0S|0
9. ConvertthefollowinggrammarintoG
NF S XA |BB
Bb|SB
X b
10. DesignPDAforL={wcwr|w?(0+1)*}
11. DesignPDAforthelanguageL={anbn+mcm|n,m>=1}
12. WhatisthelanguagegeneratedbythegrammarG=(V,T,P,S)where
P={S->aSb, S->ab}?
13. Forthefollowinggrammar:
S->ABC|BbB,A->aA|BaC|aaa,B->bBb|a|D,C->CA|AC,D->ε
i. Eliminateε-productions.
ii. Eliminateanyunitproductionsinthe resultinggrammar.
iii. Eliminateanyuselesssymbolsintheresultinggrammar.
iv. PuttheresultinggrammarinChomskyNormal Form
14. FindaCFG,withoutεproductions,unitproductionsanduseless
productionsequivalenttothegrammardefinedby
SABaC
ABC
Bb|ε
CD|ε
D d

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 22

15. ObtainthePDAforthegivenregularlanguage:L={wwr|wisin
(0+1)*}.

16. ConvertthefollowingGrammarintoC
NF. S → AbcD / abc
A→aASB/d
B→b/cb
D→d
17. Considerthegrammar({S,A,B},{a,b},P,S)thathasthe
productions:
SbA|aB
AbAA|aS|a
BaBB|bS|b

18. ShowthatL={anbncn⃒n≥0}isnotacontextfreelanguage.
Findanequivalent grammarinCNF.

C. GateQuestions
1. Identifythelanguagegeneratedbythefollowinggrammar,Where
Sis the start variable. [ ] [Gate 2017]
S->XY

X->aX|a

Y->aYb|epsilon

A){ambn|m>=n,n>0} B){ambn|m>=n, n>=0}

C) {ambn|m>n, n>=0} D){ambn|m>n,n>0}

2. Considerthefollowingstatementsaboutthecontextfreegrammar
G={S→SS,S→ab,S→ba,S→Ε} [ ][Gate2006]

Gisambiguous
Gproducesallstringswithequalnumberofa’sandb’s
GcanbeacceptedbyadeterministicPDA.

WhichcombinationbelowexpressesallthetruestatementsaboutG?
a) Ionly b)IandIIIonly
c)I andII only d)I,IIandIII
3. Considerthelanguages: [ ][Gate2005]

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 23

L1={wwR|wbelongs{0,1}*}

IIYear–II-Semester 2018-19 CSE


Formal LanguagesandAutomata Theory 24

L2={w#wR|
wbelongs{0,1}*},where#isaspecialsymbol L 3=
{ww|wbelongs {0,1}*}
WhichoneofthefollowingisTRUE?
a) L1isadeterministicCFL b)L2is adeterministic CFL
c)L3isaCFL,butnotadeterministicCFLd)L3isadeterministicCFL

4. IfL1iscontextfreelanguageandL2isaregularlanguagewhichofthe
following is/are false? [ ] [Gate 1999]
a) L1-L2is notcontextfree b)L1∩L2iscontextfree
c) ~L1 d)~L2

5. Let LD betheset of all languages accepted bya PDA by final


stateand L Ethesetof
alllanguagesacceptedbyemptystack.Whichofthe followingistrue?
[][Gate1999]

a) LD=LE b)LD⊂LE c)LE⊃LD d)Noneoftheabove

6. Context-freelanguagesareclosed under: [ ] [Gate1998]

a) Union,Intersection b) Union,Kleeneclosure
c)Intersection,complement d)Complement,Kleeneclosure

IIYear–II-Semester 2018-19 CSE


FormalLanguagesandAutomataTheory 1

UNITVI

Objective:
TounderstandanddesignTuringMachinesforthegivenrecursivelyenumerablelanguages.

Syllabus:
Turing Machine: Turing Machine, model, Design of TM, Types of Turing Machines, Computable
functions, Recursivelyenumerable languages, church‘s hypothesis.
Computability Theory: Decidability of problems, universal Turing Machine, Undecidability of posts
correspondenceproblem, Turingreducibility, definitionofPandNPproblems, NPcompleteandNP hard
problems.

LearningOutcomes:
Studentswillbeableto:
• understandturingmachineanditsmodel.
• designTuringMachine’sforRecursivelyEnumerablelanguages.
• definePandNPclassofproblems.
• definedecidabilityandundecidabilityofproblems.

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 2

LearningMaterial

TuringMachine:
ATuringmachine(TM) isdenotedby

TheTuringMachineModel:
• The basic model has a finite control, an input tape that is divided into cells, and a tape head
thatscans one cell of the tape at a time.
• The tape has a leftmost cell but is infinite to the right. Each cell of the tape may hold exactly one
of a finite number of tape symbols.
• Initially,thenleftmostcells,forsomefiniten ≥0,holdtheinput,whichis astringof symbols chosen from
a subset of the tape symbols called the input symbols.
• The remaining infinity of cells each hold the blank, which is a special tape symbol that is not an
input symbol.

MovesofTurningMachine

In one move the Turing machine, depending upon the symbol scanned by the tape head and the state ofthe
finite control,
1) changesstate,
2) printsasymbolonthetapecellscanned,replacingwhatwaswrittenthere,and

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 3

3) movesitsheadleftorrightonecell.

Note : The difference between a Turing machine and a two-way finite automaton lies in the former's ability
to change symbols on its tape.

Instantaneousdescription(ID):
• InstantaneousdescriptionoftheTuringmachineMisdenotedbyα1qα2.
• Hereq,thecurrent stateofM, is inQ;α1α2 isthe string inГ*that isthecontentsofthetapeupto the
rightmost nonblank symbol or the symbol to the left of the head, whichever is rightmost. (Observe
that the blank B may occur in α1α2.).
• The tape head is assumed to be scanning the leftmost symbol of α2, or if α2 = ε, the head is
scanning a blank.

AcceptancebyTurningMachine
The language accepted by M, denoted L(M), is the set ofthose words in ∑* that cause M to enter a final state
when placed,justified at the left, on the tape of M, , with M in state q0, and the tape head of M at the
leftmost cell.
Formally,thelanguageacceptedbyM=(Q,∑,Г,δ,q0,B,F)is

Example:

DesignaTMtoacceptthelanguageL={0n1n|n≥1}.

Initially,thetapeofMcontains0n1nfollowed byinfinityofblanks.
Repeatedly, M replaces the leftmost 0 byX, moves right to the leftmost 1, replacing it by Y,, moves left to
find the rightmost X, then moves one cellright to the leftmost 0 and repeats the cycle.
If,however,whensearchingfora1,Mfindsablankinstead,,thenMhaltswithoutaccepting.
If,afterchanginga 1toa Y,Mfindsnomore 0's,then Mchecks thatnomore 1's remain,acceptingif there are none.

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 4

Thefunctionδ

TransitionDiagram

StringVerficationbyTurningMachine

AcomputationofM

TypesofTuringMachines:
i) Two-wayinfinitetape:
A Turing machine with a two-way infinite tape is denoted by M = (Q,∑,Г,δ,q0,B,F). As its name
implies, the tape is infinite to the left as well as to the right. We denote an ID of such a device as for
the one-wayinfinite TM. We imagine, however, that there is an infinityof blank cells bothto the left
and right of the current nonblank portion of the tape.

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 5

ii) MultitapeTuringmachines:
A multitape Turing machine consists of a finite control with k tape heads and k tapes; each tape is
infinite in both directions.. On a single move, depending on the state of the finite control and the
symbol scanned by each of the tape heads,the machine can:
1) changestate;
2) printanewsymboloneachofthecellsscannedbyitstapeheads;
3) moveeachofitstapeheads,, independently,one celltotheleft orright,orkeepit stationary.
Initially, the input appears on the first tape, and the other tapes are blank.

iii) NondeterministicTuringmachines:
A nondeterministic Turing machine is a device with a finite control and a single, one-way infinite
tape. For a given state and tape symbol scanned by the tape head, the machine has a finite number of
choices for the next move. Eachchoice consists ofa new state, atape symbolto print, and a direction
ofhead motion. Notethat the nondeterministicTM is not permittedto makea move inwhichthe next
state is selected fromone choice, and the symbol printed and/or direction of head motion are selected
from other choices. The nondeterministic TM accepts its input if any sequence of choices of moves
leads to an accepting state.

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 6

iv) MultidimensionalTuringmachines:
The device has the usual finite control, but the tape consists of a k-dimensional array of cells infinite
inall2k directions, for some fixedk. Depending onthe stateand symbol scanned, thedevice changes
state, prints a new symbol, and moves its tape head in one of 2k directions, either positively or
negatively, alongoneofthekaxes. Initially, the input isalongone axis, andthehead isat the left end of the
input. At any time, only a finite number of rows in any dimension contain nonblank symbols, and
these rows each have only a finite number of nonblank symbols.

v) MultiheadTuringmachines:
Ak-head Turing machine has some fixed number,,k, of heads. The heads are numbered 1 throughk,,
and a move of the TM depends on the state and on the symbol scanned by each head.. In one move,
the heads may each move independently left,, right, or remain stationary.

vi) Off-lineTuringmachines:
Anoff-lineTuring machine is a multitapeTMwhoseinput tapeisread-only. Usuallywe surroundthe input
byendmarkers, ⊄ onthe left and $ontheright. The Turing machine is not allowed to move the input
tape head off the region between ⊄ and $.
Recursive function: a functionwhichcalls itself directlyor indirectlyand terminates after finite number of
steps.

Totalrecursivefunction
• Afunctioniscalledtotalrecursivefunctionifitisdefinedforallitsarguments.
• Let f(a1,a2.....,a) be a function and defined on function g(b1,b2,....,bm), then f is total function if
every element of f is assigned to some unique element of function g.

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 7

• Fromthedefinitionitisclearthattotalrecursivefunctionisthesubsetofpartialrecursive function.
• AllthosepartialfunctionsforwhichTMhaltsarecalledtotalrecursivefunctions.

Partialrecursivefunction
• Afunctioniscalledpartialrecursivefunctionifitisdefinedforsomeofitsarguments.
• Letf(a1,a2.....,a)beafunctionanddefinedonfunctiong(b1,b2,.............,bm),thenfispartialfunctionif
someelementsoffisassignedtoalmostoneelement offunctiong.
• Partialrecursivefunctionareturingcomputable.Itmeansthatthereexistaturingmachinefor every partial
recursive function.

Recursivelyenumerablelanguages

AlanguagethatisacceptedbyaTuringmachineissaidtoberecursivelyenumerable(r.e.).

• Recursivelyenumerablelanguagesareequivalenttotheclassofpartialrecursivefunctions.

RecursiveLanguage:
A subclass of the r.e.sets,calledthe recursive sets,which are those languages acceptedby atleastone Turing
machine that halts on all inputs.

Church'sHypothesis:
Theassumptionthattheintuitivenotionof"computablefunction"canbeidentifiedwiththeclassof partial recursive
functions is known as Church's hypothesis or the Church-Turing thesis.

Decidableandundecidableproblems:
• Aproblemwhoselanguageisrecursiveissaidtobedecidable.
• A problem is undecidableif thereisnoalgorithmthat takes asinputan instance of the problem and
determines whether the answer to that instance is "yes" or "no."

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 8

Post'sCorrespondenceProblem:
AninstanceofPost'sCorrespondenceProblem(PCP)consistsoftwolists,A=w1,,...,wkandB=x1,...
,xk,ofstringsoversomealphabet∑.ThisinstanceofPCPhasasolutionifthereisanysequenceof
integersi1,i2,...,im,withm≥1,suchthat,wi1,wi2,…,wim=xi1,xi2,… xim
.
Thesequence i1,…,imisasolutiontothisinstanceofPCP.

Example1:
Let∑={0,1}.LetAandBbe listsofthreestringseach,asdefined

InthiscasePCPhasasolution.Letm=4,i1=2,i2=1,i3=1,andi4=3.ThenW2W1W1W3= X2X1X1X3 =101111110.

Example 2: Show that PCP problem with 2 lists


X=(b,bab3,ba)andy=(b3,ba,a)hasasolution.

Givenlistsarex=(b,bab3,ba)y=(b3,ba,a)

TheinstancesofPCPisasfollows
ListX ListY

i Xi Yi

1 a b3

2 bab3 ba

3 ba a

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 9

In this case PCP is as follows


X2x1x1x3=y2y1y1y3=bab3bbba
Thesolutionsequence is2113PCPhasasolution.
Example 3: ProvethatPCPwithtwolistsX=(01,1,1)Y=(0101,10,11)hasnosolution. sol)

Instance of PCP is given as

ListX ListY

i Xi Yi

1 01 0101

2 1 10

3 1 11

Where X1=01 Y1=0101

X2=1 Y2=10

X3=1 Y3=11

Foranyi|Xi|<|Yi|The last Yis havingstringsofgreaterlengths.Sotoget samestring forsame sequences


of x1,x2,x3 and y1,y2,y3 is difficult.

Wecannotgetsolutionsequence.ThereforethegivenPCPishavingnosolution.

TuringReducibility:
LanguageLlisreducedtoL2byfindinganalgorithmthatmappedstringsinL1tostringsinL2and strings not in L1 to
strings not in L2. This notion of reducibility is often called many-one reducibility.
AmoregeneraltechniqueiscalledTuringreducibility,andconsistssimplyofshowingthatL1is recursive in L2.
IfL1ismany-onereducibletoL2,thensurelyL1isTuring-reducibleto L2.

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 10

Pand NPproblems:
The languagesrecognizable indeterministicpolynomialtime forma naturaland important class, theclass
Ui≥1DTIME(ni), which we denote by P. It is an intuitively appealing notion that P is the class ofproblems
that can be solved efficiently.
There are a number of important problems that do not appear to be in P but have efficient
nondeterministic algorithms. These problems fall into the class Ui≥1NTIME(ni), which we denoteby NP.

NPcompleteandNPhardproblems:
Letlbeaclassoflanguages.
Alanguage L is complete for lwithrespect to polynomial-time reductions ifL is in l, andeverylanguage in l
is polynomial-time reducible to L.
LisNP-completeifLiscompleteforNPwithrespecttolog-spacereductions.
Lishardforlwithrespecttopolynomial-timereductionsifeverylanguageinlispolynomial-time reducible to L, but
L is not necessarily in l.
LisNP-hardifLishard forNPwithrespecttolog-spacereductions.

NP
NP

NC

HALTINGPROBLEM

The problem of determining whether a program halts on a given inputis undecidable.This is to say that no
program can correctly code halts.There is no algorithm for deciding halting problem

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 11

Haltingproblemissimplynotsolvable.

Let K0= Turing acceptable language.

Aproblemthat canbesolvedbyanalgorithmiscalledsolvable.
Aproblemthat cannot besolved byanalgorithmcalledunsolvable. An
algorithm that solves a problem is called a decision procedure.
The most famous of the unsolvable problems is the problems described by Ko.It is generally called
halting problem for turing machine to determine for arbitrary given turing machine M and input
w,whether M will eventually halt on input W.

Closurepropertiesofrecursivelanguages

• Union:IfL1andIfL2aretworecursivelanguages,theirunionL1∪L2willalsoberecursive because if TM
halts for L1and halts for L2, it will also halt for L1∪L2.
• Concatenation:IfL1 andIf L2 aretworecursive languages, their concatenationL1.L2 will also be
recursive.
• KleeneClosure:IfL1isrecursive, itskleeneclosureL1*willalsoberecursive.
• Intersectionandcomplement:IfL1andIfL2aretworecursivelanguages,theirintersectionL1∩
L2willalsoberecursive.

Closurepropertiesofrecursivelyenumerablelanguages

• Recursivelyenumerablelanguagesarenotclosedundercomplementation

• IfL isrecursivelyenumerable language, itskleene closure L*willalso be recursivelyenumerable


language.
• If L1 and If L2 are two recursively enumerable languages, their concatenation L1.L2 will also
berecursively enumerable languages.
• IfL1andIfL2aretworecursivelyenumerablelanguages,theirunionL1∪L2willalsobe recursively
enumerable languages.
• IfL1andIfL2aretworecursivelyenumerablelanguages,theirunionL1∩L2willalsobe recursively
enumerable languages.

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 12

Assignment-Cum-TutorialQuestions
A. Questionstestingtheunderstanding/rememberinglevelofstudents
I) ObjectiveQuestions
1. The move functionofTuringMachine is .
2. The languageacceptedbyaTurning machine iscalled language.
3. Recursivelyenumerablelanguagesareequivalenttotheclassof functions.
4. Recursivelyenumerablelanguagesareclosedundercomplementation. [True|False]
5. Thesetofallrecursivelanguagesisasubsetofthesetofallrecursivelyenumerable languages.
[True|False]
6. PhrasestructuredlanguagesareacceptedbyTM. [True|False]
7. ThepowerofNon-deterministicTurningmachineanddeterministicTurningMachinearesame.
[True |False]
8. Aproblemwhose language isrecursive iscalled .
9. Recursivelanguagesare [ ]
a. a).ApropersubsetofCFL b).AlwaysrecognizablebyPDA
b. c).AlsocalledType0languages d).RecognizablebyTM
10. PhrasestructuredlanguagesarealsocalledasType0languages. [True|False]

II) Descriptivequestions
1. DefineTurningMachine.ExplainaboutmodelofTurningMachine

2. Explainabouttypesofturingmachines.

3. Writeshort notesonhaltingproblemofaTuringMachine.

4. DiscussChurch’sHypothesis?

5. WriteshortnotesonPandNPproblemsandgiveexamples.

6. WriteshortnotesonNPCompleteandNPhardproblemsandgiveexamples.

7. DiscussindetailsaboutTuringReducibility.

8. Listpropertiesofrecursiveandrecursivelyenumerablelanguages.

9. What ispostcorrespondenceproblem?Explainwithanexample

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 13

B. Questiontestingtheabilityofstudentsinapplyingtheconcepts.
I) Multiple Choice Questions:
1. WhichofthefollowinglanguagesareacceptedbyaTurningMachine? [ ]
(i) L={anbn|n>=0}
(ii) L={anb2nc2n|n>=0}
(iii) Thesetofpalindromesoveralphabet{a,b}
a)Only(i) b)Only(ii) c)(i)and(iii) d)(i),(ii)and(iii)
2. A single tape Turing Machine M has three states q0, q1 and q2, ofwhich q0 is the starting state. The
tapealphabet ofM is{0, 1, B}and its input alphabet is{0, 1}.ThesymbolB istheblanksymbolusedto
indicate end ofan input string. The transition function ofM is described in the following table

0 1 B

q0 q0,1,R q0,0,R q1,B,L

q1 q1,0,L q1,1,L q2,B,R

Whichofthe followingstatementsistrueaboutM? [ ]
a) Mhaltsaftercomputing1’scomplement ofabinarynumber
b) Mhaltsaftercomputing2’scomplement ofabinarynumber
c) Mhaltsafterreversingofabinarynumber
d) None
3. AsingletapeTuringMachineMhas four statesq0, q1, q2andq3,ofwhichq0 isthestartingstate.The
tapealphabet ofM is{0, 1, B}and its input alphabet is{0, 1}.ThesymbolB istheblank symbolusedto
indicate end ofan input string. The transition function ofM is described in the following table

0 1 B

q q q q1,B,L

q q q

q2 q2,1,L q2,0,L q3,B,R

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 14

WhichofthefollowingstatementsistrueaboutM? [ ]
a.Mhaltsaftercomputing1’scomplementofabinarynumber
b.Mhaltsaftercomputing2’scomplementofabinarynumber
c.Mhaltsafter reversingofabinarynumber
d.None
4.ThegiventablerepresentsaTuringmachinewhichaccepts [ ]

a) evennumberof1’s
b) oddnumberof1’s
c) evennumberof1’sandoddnumberof1’s
d) evennumberof1’soroddnumberof1’s

5. ThetransitionsofaTuringMachinearegivenbelow [ ]
δ (q0,1)=(q0,1,R)
δ(q0,B)=(q1,1,R)
δ(q1,B)=(q2,B,R)
Theinputonthetapeisq011Bthentheoutputonthetapeis [ ]
a) 111Bq2B b)1111Bq2B c) 111Bq1B d)1111Bq1B

II) Problems
1. DesignTMforthelanguageL={anbncn|n>=1}

2. DesignTMforthelanguageL={anbmcn+m|n,m>=1}

3. DesignaTuringmachinethatacceptsthelanguageL={WWR/W□.(0+1)*and

WRisreverseofW}

4. ConsidertheTMdescribedbythetransitiontablegivenbelow.Representtheprocessingof

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 15

a)011b)0011usingID’s.WhichofthestringsareacceptedbyTM?

5. DesignTMforsubtractionoftwonumbers.

6. Showthatthefollowingpostcorrespondenceproblemhasasolutionandgivethesolution.

i ListA ListB
1 11 11
2 100 001
3 111 11

C. GATE/NET/SLET
1. Whichofthefollowingstatementsis/areFALSE? GATECS2013 [ ]
1. Foreverynon-deterministicTuringmachine,thereexistsanequivalentdeterministicTuring
machine.
2. Turingrecognizablelanguagesareclosedunderunionandcomplementation.
3. Turingdecidablelanguagesareclosedunderintersectionandcomplementation.
4. Turingrecognizablelanguagesareclosedunderunionandintersection.
a) 1and4only b)1and3only c)2only d)3only

2. Whichofthe following istrueforthelanguage GATECS2008 [ ]


a) Itisnot acceptedbyaTuringMachine
b) Itisregularbutnotcontext-free
c) Itiscontext-freebutnot regular
d) Itisneitherregularnorcontext-free,butacceptedbyaTuring machine

II.B.Tech-I-Semester A.Y.2018-19 CSE


FormalLanguagesandAutomataTheory 16

3. Let L1 be a recursive language. Let L2 and L3 be languages that are [ ]


recursivelyenumerable but notrecursive.Whichofthefollowingstatementsisnotnecessarilytrue?
(A)L2–L1isrecursivelyenumerable. (B)L1–L3isrecursivelyenumerable
(C)L2∩L1isrecursivelyenumerable (D)L2∪L1isrecursivelyenumerable
GATECS2010
a)A b) c)C d)D

4. IfLandL'arerecursivelyenumerable,thenLis GATECS2008 [
a) regular b)context-free
c)Context-sensitive d)recursive

5. Let L1 be a recursive language, and let L2 be a recursively enumerable but not a recursive
language.Which one of the following is TRUE? GATE-CS-2005 [ ]
L1'-->ComplementofL1 L2'--
>ComplementofL2
a) L1'isrecursiveandL2'isrecursivelyenumerable
b) L1'isrecursiveandL2'isnotrecursivelyenumerable
c) L1'andL2'arerecursivelyenumerable
d) L1'isrecursivelyenumerableandL2'isrecursive

6. Considerthefollowingtypesoflanguages: GATE-CS-2016(Set2)
L1Regular, L2:Context-free,
L3:Recursive, L4:Recursivelyenumerable.
Whichofthefollowingis/areTRUE?
I.L3'UL4isrecursivelyenumerable II.L2UL3isrecursive
III.L1*UL2iscontext-free IV.L1UL2'iscontext-free
a)Ionly b)IandIIIonly c)IandIVonly d)I,IIandIIIonly

7. AsingletapeTuringMachineMhastwostatesq0andq1,ofwhichq0 isthestartingstate.
Thetapealphabet ofM is{0, 1, B}and its input alphabet is{0, 1}. ThesymbolB istheblank symbol
usedtoindicateendofaninput string.ThetransitionfunctionofMisdescribedinthefollowingtable
GATE-CS-2003 [ ]
0 1 B
q0 q1,1,R q1,1,R Halt
q1 q1,1,R q0,1,L q0,B, L
The table is interpreted as illustrated below. The entry(q1, 1, R) in row q0 and column 1 signifies that if M is
instateq0andreads1onthecurrenttapesquare,thenitwrites1onthesametapesquare,moves its
II.B.Tech-I-Semester A.Y.2018-19 CSE
FormalLanguagesandAutomataTheory 17

tape head one position to the rightand transitions tostate q1. Which of thefollowingstatements is true about
M?
a) Mdoesnothalt onanystringin(0+1)+
b) Mdoesnothalt onanystringin(00+1)+
c) Mhaltsonallstringendingina0
d) Mhaltsonallstringendingina1

8. Whichofthefollowingistrue? GATE-CS-2002 [ ]
a) Thecomplementofarecursivelanguageisrecursive.
b) Thecomplementofarecursivelyenumerablelanguageisrecursivelyenumerable.
c) Thecomplementofarecursivelanguageiseitherrecursiveorrecursivelyenumerable.
d) Thecomplementofacontext-freelanguageiscontext-free

9. Define languages L0 and L1 as follows : GATE-CS-2003 [ ]


L0 = {< M, w, 0 > | M halts on w}
L1={<M, w, 1>|Mdoesnothaltsonw}
Here < M, w, i > is a triplet, whose first component. M is an encoding of a Turing Machine, second
component, w, isastring, andthirdcomponent, i, is a bit. Let L=L0 ∪ L1. Whichofthe following is
true?
a) Lisrecursivelyenumerable,butL'is not
b) L'isrecursivelyenumerable,butLisnot
c) BothLandL'are recursive
d) NeitherLnorL'isrecursivelyenumerable

10. NobodyknowsyetifP=NP.ConsiderthelanguageLdefinedas follows:


GATE-CS-2003 [ ]
Whichofthefollowingstatementsistrue?
a) Lisrecursive
b) Lisrecursivelyenumerablebutnotrecursive
c) Lisnotrecursivelyenumerable
d) WhetherLisrecursiveornot willbeknownafterwefindoutifP=NP
II.B.Tech-I-Semester A.Y.2018-19 CSE

You might also like