Sie sind auf Seite 1von 7

1/14/2017 ADUniTheoryofComputationProblemSet01Solutions

ARSDIGITAVNIVERSITY
Month8:TheoryofComputation
ProblemSet1SolutionsMikeAllenandDimitriKountourogiannis

1.DFAs

a.Allstringsthatcontainexactly40s.

b.Allstringsendingin1101.

c.Allstringscontainingexactly40sandatleast21s.

d.Allstringswhosebinaryinterpretationisdivisibleby5.

e.(1.4c)Allstringsthatcontainthesubstring0101.

f.(1.4e)Allstringsthatstartwith0andhasoddlengthorstartwith1andhasevenlength.

http://www.aduni.org/courses/theory/courseware/psets/Problem_Set_01_Solutions.html 1/7
1/14/2017 ADUniTheoryofComputationProblemSet01Solutions

g.(1.4f)Allstringsthatdon'tcontainthesubstring110.

h.(1.4g)Allstringsoflengthatmost5.

i.(1.4i)Allstringswhereeveryoddpositionisa1.

2.NFAs

a.Allstringscontainingexactly40soranevennumberof1s.(8states)

b.Allstringssuchthatthethirdsymbolfromtherightendisa0.(4states)

c.Allstringssuchthatsometwozerosareseparatedbyastringwhoselengthis4iforsomei>=0.(6states)

d.(1.5b)Allstringsthatcontainthesubstring0101.(5states)

http://www.aduni.org/courses/theory/courseware/psets/Problem_Set_01_Solutions.html 2/7
1/14/2017 ADUniTheoryofComputationProblemSet01Solutions

e.(1.5c)Allstringsthatcontainsanevennumberof0sorexactlytwo1s.(6states)

f.(1.5e)Thelanguage0*1*0*0(3states)

3.ConvertingNFAstoDFAs

a.ConverttheNFAin2fintoaDFA.

b.1.2ainthetext
c.1.2binthetext

4.DiscreteMathReviewProofs

L1:Thesetofstringswhereeachstringwhasanequalnumberofzerosandonesandanyprefixofwhasatleastasmany
zerosasones.
L2:Thesetofstringsdefinedinductivelyasfollows:ifwisinthesetthen0w1isalsointhesetifuandvareintheset
thensoisuvandtheemptystringisintheset.

a.ProvethateverystringinL2iscontainedinL1

WecananalyzeL2inductivelytoseethatitmaintainsthepropertyofL1foreachcase:

1.Theemptyset.ThisisamemberofL1,sinceitsatisfiesthepropertiesvacuously.
2.0w1.AssumingthatwisinL1,wemaintaintheequalnumberof0sand1sbecauseweaddoneofeach.We
alsomaintaintheprefixcondition,sincethe0isaddedbeforethe1.
3.uv.AssumingthatuandvarebothinL1,simplyconcatenatingthemtogetherwillmaintaintheequalnumber
of0sand1s.Theprefixconditionisslightlymoredifficult.Weconsiderthefollowingprefixes:
a.PREFIX(u).SinceuisinL1,thismustbeinL1.
b.u.Again,sinceuisinL1,thismustbeinL1.
c.uPREFIX(v).Sinceuhasanequalnumberof0sand1s,andvisinL1,thismustmaintaintheprefix
property.

http://www.aduni.org/courses/theory/courseware/psets/Problem_Set_01_Solutions.html 3/7
1/14/2017 ADUniTheoryofComputationProblemSet01Solutions

b.Forthoseofyouwhoarepayingattention,thisproblemisextemelysimilartothestreamcrossingghostbusters
problemfromalgorithms.TheproofisbyinductiononthelengthofstringsinL1:
1.Thebasecaseistheemptystring.ThisisinL2bydefinition.
2.Fortheinductivestep,supposethatallstringsinL1oflength<=nareinL2.LetwbeastringinL1oflenght
n+1andsupposeitisoftheformA1A2...An+1,whereAiiseither0or1.Letjbethefirstindexwiththe
propertythatA1A2...Ajhasthesamenumberofzerosandones.Therearetwocasestoanalyze.
a.j<n+1.Thennotonlydoesu=A1A2...Ajhavethesamenumberofzerosandones,anyprefixofuwill
haveatleastasmanyzerosasonessinceitisalsoaprefixofw.SouisinL1.Letv=Aj+1Aj+2...An+1.
Thenvmusthavethesamenumberofzerosandonessincebothuandw=uvdo.Also,anyprefixxofv
cannothavemoreonesthanzerosinitsincethenuxwouldbeaprefixofwthathadmoreonesthan
zeros.ThereforevmustbeinL1.Sincebothuandvareoflength<=n,bytheinductionhypothesisthey
areinL2.Thereforew=uvmustbeinL2,bythedefinitionofL2.
b.j=n+1.Thenw=0u1forsomestringu,anduhasthesamenumberofzerosandones,sincewdoes.
Also,noprefixxofucanhavemoreonesthanzeros,sincethen0xwouldeitherhavemoreonesthan
zeroswhichisimpossiblebyhypothesis,or0xwouldhavethesamenumberofonesaszeros,whichis
alsoimpossiblebysincej=n+1.ThereforewecanconcludethatuisinL1,andsinceitisoflength<=n
itisinL2bytheinductionhypothesis.
Thiscompletestheinductivestep,andthereforeL1iscontainedinL2.

5.ClosureProblems

a.ProvethatifL1isregularandL2isregularthensoisL1L2(thesetofallstringsinL1butnotinL2).

L1L2isthesameastheintersectionofL1andthecomplementofL2.Sincethesetofregularlanguagesisclosed
undereachoftheseoperations,L1L2mustberegular.

b.ProvethatifLisregularthenPrefix(L)isregular.Prefix(L)isthesetofallstringswhichareaproperprefixofa
stringinL.

WecanconstructaDFAtodecidePrefix(L)bytakingtheDFAforLandmarkingallstatesfromwhichanaccept
stateisreachableasacceptstates.So,Prefix(L)mustberegular.

c.ProvethatRegularSetsareclosedunderMIN.MIN(R),whereRisaregularset,isthesetofallstringswinRwhere
everyproperprefixofwisinnotinR.(NotethatthisisnotsimplythecomplementofPREFIX).

WecanconstructaDFAtodecideMIN(R)bytakingtheDFAforRandredirectingalloutgoingarrowsfromallthe
acceptstatestoadeadstate.So,MIN(R)mustberegular.

d.ProvethatRegularSetsareNOTclosedunderinfiniteunion.(Acounterexamplesuffices).

Considerthesets{0},{01},{0011},etc.Eachoneisregularbecauseitonlycontainsonestring.Buttheinfinite
unionistheset{0i1i|i>=0}whichweknowisnotregular.Sotheinfiniteunioncannotbeclosedforregular
languages.

e.Whataboutinfiniteintersection?

Weknowthat

{0i1i|i>=0}={0}U{01}U{0011}U...,

TakingcomplementsandapplyingDeMorgan'slawgivesus

{0i1i|i>=0}c={0}c^{01}c^{0011}c^...,

WhereweareusingUtodeonteunionand^todenoteintersection.Recallthecomplementofaregularlanguageis
regular,andhencethecomplementofanotregularlanguageisnotregular.Sowecanconcludethatthelefthandside
oftheequationisnotregular,andeachtermintheintersectionisregular.Thereforeinfiniteintersectiondoesnot
preserveregularity.

f.extracreditLet(Q,Sigma,delta,q,F)beadeterministicmachinethatacceptsL.ThenamachinethatacceptsHalf(L)
is

http://www.aduni.org/courses/theory/courseware/psets/Problem_Set_01_Solutions.html 4/7
1/14/2017 ADUniTheoryofComputationProblemSet01Solutions
(QxQxP(Q),Sigma,delta',{(q,r,{r})},{(r1,r2,S)inQxQxP(Q)|r1=r2andScontainsanelementofF})

whereP(Q)isthepowersetofQ,i.e.allsubsetsofQ.,and
delta'(r1,r2,S,a)=(delta(r1,a),r2,Sa)

andSadenotesthesetofstatesthatcanbereachedfromsomestateinSinonestepwithinputa.Tosimplifythe
notation,weareallowingmultiplestartstates{(q,r,{r})}.Thiscouldbealsoachievedbyintroducinganewstate
andintroducingepsilonmoves.ThereasonthatthisacceptsHalf(L)isthatthetermr2in(r1,r2,S)remembersthe
midpointofapotentialstringinL,andSrepresentsthestatesonecanreachfromr2inthenumberofstepsittakesto
getfromthestartqtor1.Whenr1=r2,thenScontainsallthepathsthatonecangettointwiceasmanystepsasit
tooktogetfromqtor1.

AnintuitiveexplanationTheHalf(L)problemisgivenastringwisthereastringxofthesamelengthaswsuchthat
wxisinthelanguageL.Thisishardtosolvedirectly,sowebreakitintoanumberofsubproblemsofthefollowing
form:FixamachineMthatgeneratesLandpickastaterinthatmachine.

TheproblemHalf(L,r)isthen:Givenastringw,isthereastringxofthesamelengthaswsuchthatwxisinthe
languageLandafterreadinginw,themachineMisinthestater.

WecanreducesolvingHalf(L)tosolvingHalf(L,r)foreachstaterinthemachineMandoringtheresult.Thereason
thisisgoodisthattheproblemHalf(L,r)decomposesnaturallyintotwoothersimpleproblems:

IfwemakethemachineM'bymakingallacceptstatesinMberejectstates,andbymakingstateranacceptstate,
doesM'acceptthestringw?

and

IfwemakethemachineM''bymakingstaterthestartstate,andchangingall0transitionsto0,1transitionsand
similarlyall1transitionsto0,1transitions,doesthemachineM''acceptthestringw?

Whatwehavedoneinthesecondcaseistoingnorewhatthevalueofanycharacterinthestringis.Thisishowto
makeamachinetoacceptallstringsthathavethesamelengthasstringsacceptedbyagivenmachine.Puttingallthis
togethershouldresultinasimilarmachinetowhatisgivenforasolutionhere,withpossiblysomemissing
extraneousstates.

6.RegularExpressions

a.(10+0)*(1+10)*
(10+0)*willgenerateallstringsthatdonotcontainapairof1s,and(1+10)*,thestringsthatdonotcontainapairof
0s.So,theconcatenationwillgenerateallstringsinwhicheveryoccurrenceof00precedeseveryoccurrenceof11.

b.0*(1+000*)*0*
Wecangenerateastringwhichdoesnotcontaintheoccurrence101bymakingsurethatany0inthemiddle(between
two1s)ofthestringmustbepairedwithanother0.

c.(e+0)(10)*(e+0)(10)*(e+1)(10)*(e+1)+(e+0)(10)*(e+1)(10)*(e+0)(10)*(e+0)
Thebothtermsarejustalternating1'sand0s,eg(e+0)(10)*(e+1)whereyouareallowedtoinertatmostoneextra1
or0inbetween.Weneedtwoterms,dependingonwhetherthedouble1orthedouble0comesfirst.

7.ConvertingFiniteAutomatatoRegularExpressions

a.(1.16a)(a*+ba*b)*ba*
b.(1.16b)[(a+b)(a+bb)*ba]*[e+(a+b)(a+bb)*b]

8.RegularExpressionIdentities

a.r(s+t)andrs+rtareequivalentbecausethefirstdescribesastringfromrfollowedbyeitherastringfromsora
stringfromt,andtheseconddescribesastringfromrfollowedbyastringfromsorastringfromrfollowedbya
stringfromtandthesetwoareclearlythesamething.

b.(r*)*andr*areequivalentbecausethefirstdescribestheconcatenationofanarbitrarynumberoftermsthat
themselvesareconcatenationsofarbitrarynumbersoftermsinr.Thisisthesameasr*whichistheconcatenationof
anarbitrarynumberoftermsinr.

http://www.aduni.org/courses/theory/courseware/psets/Problem_Set_01_Solutions.html 5/7
1/14/2017 ADUniTheoryofComputationProblemSet01Solutions

c.(r+s)*andr*s*arenotequivalentbecauseifs1isastringinsandr1isawordinrthens1r1isin(r+s)*butnotr*s*
butnotthelatter.

9.FinalStates

a.EveryNFAcanbeconvertedintoanequivalentNFAwithonlyasingleacceptstatebycreatinganewacceptstate
withepsilonmovesfromeachoftheoldacceptstates.

b.ThisdoesnotworkforDFAs.TheDFAsofproblems1g,1h,and1iareallgoodcounterexamples.

IngeneraliftheminimumDFAforaregularlanguagehasmorethanonefinalstate,thenthelanguagecannotbe
generatedbyaDFAwithonefinalstate.Thisisbecauseminimizationcannotincreasethenumberoffinalstates.

c.Claim:TheregularlanguagesthatcanberepresentedbyaDFAwithonefinalstateareoftheformRS*,whereRand
sareregularprefixfreelanguages.

Proof:Weneedthefollowinglemmafirst:AprefixfreeregularlanguageMcangeneratedbyamachinewithone
finalstate.SupposewehaveDFArepresentationofMthathasmultiplefinalstates.Thenalloutgoingtransitions
fromthosefinalstatesmustgotodeadstatessinceMisprefixfree.ButwhenwemimizetheDFA,allthedeadstates
willbecomeequivalent,andthereforeallthefinalstateswillbecomeequivalenttoo.

Wealsoneedthefollowinglemma:TheKleenestar,M*,ofprefixfreeregularlanguageMcanbegeneratedbya
machinewithonefinalstate.FromthepreviouslemmaweknowthereisaDFAthatgeneratesMthathasonefinal
state.WecanmakeM*bytakingtheminimalDFAthatacceptsMandremovingthetransitionsfromthefinalstate
andcollapsingittogetherwiththeinitialstate(whilekeepingitafinalstate).

FromthesetolemmasitisclearthatRS*canbegeneratedbyamachinewithonefinalstateifRandSareprefix
free,becausewecanjustconcatenatethemachinesforRandS*.

Conversely,ifLisgeneratedbyaDFAMwithonefinalstate,thenL=Min(L)(Min(L'))*,whereL'isthelanguage
ofthemachineM'hasthesamestates,transitions,andfinalstateasM,andwherewechoosethefinalstateofMtobe
thestartstateofM'.SincetheMinofalanguageisalwaysprefixfree,Lisoftheformweclaim.

10.OptionalExtraProblems

a.Convert[00+11+(01+10)(00+11)*(01+10)]*toaFiniteAutomaton.

WejustreversetheprocedureforconvertinganNFAtoaregularexpressionbyrippinginstates.

(note:therightmoststateintheseconddiagramcorrespondstothebottomrightstateinthethirddiagram.)

b.(1.25)LetB={w|thebottowrowofwisthesumofthetoptworows}.ThereverseofBcanbedecidedbytheNFA
below,andsincethesetofregularlanguagesisclosedunderreversal,Bmustberegularaswell.

http://www.aduni.org/courses/theory/courseware/psets/Problem_Set_01_Solutions.html 6/7
1/14/2017 ADUniTheoryofComputationProblemSet01Solutions

TheNFAbelowdeterminesifastringofcolumnscomposesalegaladditionequationwherethetoptworowssumto
thethird.Thetwostatescorrespondtowhetherthepreviouscolumnledtoacarryoutornot,andthelegaltransistions
foreachstatecorrespondtocolumnswhichmaintainthecorrectnessoftheequation.Ifaninvalidcolumnisadded,no
validoutgoingarrowisfoundandthecomputationdies(thusrejectingtheinput).

c.(1.41)LetD={w|wcontainsanequalnumberofoccurrencesof01and10}.Thislanguagecanbedecidedbythe
DFAbelow,andsomustberegular.

TheDFAworksbecausethenumberof01transistionsmustalwayswewithinoneofthenumberof10transistions,so
weneedonlyrememberwhichtransistioncamefirst(toppathvs.bottompath),andwhetherwehaveseenaneven
numberoroddnumberoftransistions(leftstatevs.rightstate).

http://www.aduni.org/courses/theory/courseware/psets/Problem_Set_01_Solutions.html 7/7