12.07.2015 Views

Solutions to Exercises 2

Solutions to Exercises 2

Solutions to Exercises 2

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LTCCCourse onGraph Theory 2011/12<strong>Solutions</strong> <strong>to</strong><strong>Exercises</strong>for Notes21 (⇒) Supposethereexistsapolynomial p(n)ofdegreedsothat|f(n)| ≤ p(n)foralln ≥ 1.To show that this means f(n) = O(n d ) means that we must show that there exist constantsC > 0 and N ≥ 1 so that for all n ≥ N we have |f(n)| ≤ Cn d . Write p(n) = a d n d +a d−1 n d−1 +···+a 1 n+a 0 . Thenweknow a d ̸= 0(since p(n)isofdegreed). Andinfactwemusthave a d > 0,otherwisewewouldhave p(n) −→ −∞ as n → ∞,whichisimpossibleif|f(n)| ≤ p(n) forall n ≥ 1. So we can estimateforall n ≥ 1:|f(n)| ≤ p(n) = a d n d +a d−1 n d−1 +···+a 1 n+a 0≤ a d n d +|a d−1 |n d−1 +···+|a 1 |n+|a 0 |≤ a d n d +|a d−1 |n d +···+|a 1 |n d +|a 0 |n d= (a d +|a d−1 |+···+|a 1 |+|a 0 |)n d .So by setting C = a d +|a d−1 |+···+|a 0 | and N = 1,wefind |f(n)| ≤ Cn d forall n ≥ N.(⇐) Suppose we have f(n) = O(n d ), hence there exist constants C > 0 and N ≥ 1 sothat for all n ≥ N we have |f(n)| ≤ Cn d . So for n ≥ N the polynomial p(n) = Cn dwouldwork. Butthatpolynomialmightnotworkfor n < N. Toovercomethatproblem,setK = max{0,|f(1)|,|f(2)|,...,|f(N −1)|}. (This maximum exists, since we are just takingthemaximumoverafinitese<strong>to</strong>fnumbers.) Thenweknowthat|f(n)| ≤ K foralln < N. Soby setting p(n) = Cn d +K we are guaranteed |f(n)| ≤ p(n) for all n ≥ 1.2 (a) The flow diagramof the firstTuring Machine on page 5ofthe notes looks likethis:0 : 0,+11 : 1,+1q 0q 1# : #,−1# : #,+1q 2# : #,−1q 41 : #,−10 : #,+10 : #,−1# : .,. 1 : .,.1 : #,+10 : 0,−11 : 1,−1# : .,.0 : 0,+11 : 1,+1# : .,.0 : .,.q Yq NAuthor: Jan van den Heuvel c○London School of Economics, 2012


LTCC Course on Graph Theory <strong>Solutions</strong> <strong>to</strong> <strong>Exercises</strong> for Notes 2 — Page 2To get an ideaof what is happening, let’s try <strong>to</strong> follow a few steps. Suppose at the start,on the first square the machine reads a “0”. Then this “0” is erased (since # is writtenon the tape), the state becomes q 1 and the head goes one <strong>to</strong> the right. As long as thereis a “0”or “1”on the tape, the head goes further <strong>to</strong> the right. Until the head reaches theend of the 0,1-string (reads a blank “#”), then it goes back one step <strong>to</strong> the left and <strong>to</strong>state q 3 . If it then reads a “1”, it goes <strong>to</strong> the end-state q N . So a string starting with “0”but endingwith “1”willbe rejected.Ifontheotherhandinstateq 3 itreadsa“0”,thenthat“0”iserased,thestatebecomesq 5and the head goes one <strong>to</strong> the left. As long as there is a “0” or “1” on the tape, the headgoes further <strong>to</strong> the left. Until the head reaches the left-end of the 0,1-string, then it goesback <strong>to</strong> the originalstate q 0 and one step<strong>to</strong> the left.And then the whole process starts fromthe verybeginning.If in the first step a “1” is read, then something similar <strong>to</strong> the above will be done, butnowviastates q 2 and q 4 . Andinparticular,ifthefinalbitisa“0”,thenthemachinewillgo <strong>to</strong> state q N . If the final bit is a “1”, then that “1” is erased. And via q 5 the head goesback <strong>to</strong> the beginning.So all in all, if you look back over what happens above, then the machine compares thefirst and the last bit of the input. If these are the same, then they are both erased, andthe machine continues with the reduced string. If they are different, then the machineimmediatelyrejectsthestring. Thepositivefinalstageq Y isreachedwhennothingislef<strong>to</strong>nthe tape.FromthisitfollowsthatthestringacceptedbythisTuringMachineareexactlyso-calledpalindromes: strings thatread fromleft<strong>to</strong> right and fromright<strong>to</strong> leftarethe same.(b) The second Turing Machine on page 5 of the notes is a lot easier <strong>to</strong> analyse: I’ll leave it<strong>to</strong> you <strong>to</strong> check that this accepts wordsthat contain exactly one “1”.3 These questions are actually harder than they look. I’m not going <strong>to</strong> give full details of theTuring Machine, but some important ideas that can be used. An important issue for bothcases is how <strong>to</strong> keep track of what part of the string has already been copied or doubled,and what part still needs <strong>to</strong> be done. Although it seems tempting <strong>to</strong> use a “counter” <strong>to</strong>indicatewhatpartneeds<strong>to</strong>becopied/doublednext,suchacounterisactuallyquitehard<strong>to</strong>implement. So it’s probably much more convenient <strong>to</strong> use a “marker” <strong>to</strong> indicate where themachine was. Such amarker can justbe asquare onthe tape with the blank symbol #on it.Of course, that means the machine erases what was on that square before. So somehow themachine needs <strong>to</strong> s<strong>to</strong>re that information. Since there are only two possible original symbols(0 or 1), this can be done using appropriate states. So there should be a set of states just forwhen the machine is dealing with a 0, and a set of states for when the machine is dealingwith 1. (This also happens in the machine for Question 1 above, where states q 1 ,q 3 onlyappear when the machine had read a 0 in state q 0 ; while q 2 ,q 4 are states for the case therewas a1onthe tape whilethe machine was instate q 0 .,)


LTCC Course on Graph Theory <strong>Solutions</strong> <strong>to</strong> <strong>Exercises</strong> for Notes 2 — Page 3So in the descriptions of the two Turing Machines below, we divide the state space Q in<strong>to</strong>three parts: Q = Q ′ ∪ Q 0 ∪ Q 1 . Here Q ′ contains some general states (including q 0 andso), while Q 0 and Q 1 are sets of states the machine can be in while it is copying a 0, or a 1,respectively.A Apart from the idea <strong>to</strong> use the blank symbol as a marker, another observation thatmakeslifealoteasierforthisproblemis<strong>to</strong>startworkingfromthebackofthestring.TounderstandthestepsoftheTuringMachineasgivenbelow,youshouldhaveanideahow the tapeis used. So here ishow thetape wouldlooklikeinthe middleofthe computation of making acopy ofthe string00010001011:··· |#|#|1|0|1|1|#|0|0|0|1|0|0|#|1|0|1|1|#|#| ··· .The underlined square is the starting square, while the black blob is the tape head.So the machine has just erased the symbol on the square <strong>to</strong> the right of the tapehead. That square was erased, but since it contained originally the symbol 0, themachine entered in one of the states from Q 0 , and the tape head started <strong>to</strong> move <strong>to</strong>the left.The Turing Machine performs steps as follows,all the time using states from Q 0 :– Thetapeheadgoesleft<strong>to</strong>thebeginningoftheoriginalstring(recognisedbythefirstblank itencounters).– Then it moves back <strong>to</strong> the beginning of the already copied part (again, recognisedby ablank square).– Onceitencountersthatblanksquare,itwritesa0,andstartsmovingrightagain.– The tape head goes right till the beginning of the original string (recognised byablank).– Then furtherrighttillthe markerof the bititwas workingon (again ablank).– Then it writes a 0 <strong>to</strong> replace the blank (so that square is back <strong>to</strong> the originalstate). It also moves one square <strong>to</strong> the left, and the state becomes one of thenon-specific states from Q ′ .– If it now reads a blank symbol, the copying is done, and the machine halts. If itdoesn’treadablanksymbol,itreplacesthecurrentsymbolbytheblanksymbol;and its state becomes a state from Q 0 or Q 1 , depending if the square containeda0or a1.– And now the process starts as fromthe firststepabove.With the description above, it should be possible <strong>to</strong> design a full Turing Machine.Youprobablyneedafewinitialsteps<strong>to</strong>getgoingand<strong>to</strong>makesurethatthemachinehalts immediatelyif the empty string is givenas input.B Several of the ideas from A can be used here as well. Here an extra complicationis <strong>to</strong> make room for the bits that have <strong>to</strong> be added in between. The best way <strong>to</strong> dothis is probably by doing it one by one. I.e., every time when making a copy of thenext bit, first more the remainder of the string one <strong>to</strong> the right (starting at the backagain),and then make the copy inthe freedspace.


LTCC Course on Graph Theory <strong>Solutions</strong> <strong>to</strong> <strong>Exercises</strong> for Notes 2 — Page 4Let’s demonstrate the steps and the main ideas by looking at what the situationcould be in the middle of a computation again. Using the same string 00010001011as example again, a typical situation on the tape in the middle of the computationwillbe something like:··· |#|#|0|0|0|0|0|0|1|1|#|0|0|1|0|1|1|#|#| ··· .So the machine has already doubled the first four bits, and has just erased the fifthbit,andmovedonestep<strong>to</strong>theright. Sincethaterasedsymbolwasa0,themachinewillbe insome state from Q 0 .And next the machine willperformthe followingsteps:– It willmove right<strong>to</strong> the endof the string (recognisedby ablank square).– Itthenwilldoonestepback <strong>to</strong> theleft,readthesymbol,eraseit,moveone step<strong>to</strong>theright,writetha<strong>to</strong>nesymbolonthatsquare,andonestep<strong>to</strong>theleftagain.(These steps arejustmoving one symbol one square<strong>to</strong> the right.)– It continues doing the above until it is back <strong>to</strong> the beginning of the part of theoriginalstring that hasn’t beendoubledyet.– Once it is back at the blank “marker”, there will actually be two blank squaresin a row (since the complete right side of the string has been moved one squarefurther <strong>to</strong> the right). So it can write two 0s in a row. (The machine “knows”these mustbe 0s since itwas using states from Q 0 inall the steps above.)– The machine moves one square further <strong>to</strong> the right, and the state becomes oneof the non-specific states from Q ′ .– If it now reads a blank symbol, the doubling is done and the machine halts. If itdoesn’treadablanksymbol,itreplacesthecurrentsymbolbyablank,andgoesin<strong>to</strong> astate from Q 0 orfrom Q 1 ,according <strong>to</strong> the symbol that was onthe tape.– And now the process starts as fromthe firststepabove.Again, the final Turing Machine probably needs some extra initial steps <strong>to</strong> get it allgoing and <strong>to</strong> make sure it halts if there is nothing on the tape. But apart from that,you shouldbe able <strong>to</strong> designaTuring Machine that doesallof the above.4 (a) By definition, L 1 is in NP, if there exists a nondeterministic Turing Machine N (1) and apolynomial p (1) (n)suchthatforeveryx ∈ L 1 ,thereexistsasequenceofatmost p (1) (|x|)allowedstepssothatN (1) haltsintheacceptingstateofN (1) . Andasimilarconclusion,using a nondeterministic Turing Machine N (2) and a polynomial p (2) (n), can be drawnfromthe claimthat L 2 isin NP.From this we can easily see that also L 1 ∪ L 2 is in NP. Make a new nondeterministicTuring Machine N that is formed by using disjoint states q (1)ifor N (1) and states q (2)ifor N (2) . Now let q 0 and q Y be two new states. Then form N as follows. Starting atstate q 0 , there is one possible transition <strong>to</strong> the initial state q (1)0of N (1) and one possibletransition<strong>to</strong>theinitialstateq (2)0ofN (2) . Also,fromtheacceptingstateq (1)Y ofN(1) thereis one transition <strong>to</strong> the accepting state q Y of N, and the same holds for the acceptingstate of N (2) .


LTCC Course on Graph Theory <strong>Solutions</strong> <strong>to</strong> <strong>Exercises</strong> for Notes 2 — Page 5It’s now straightforward <strong>to</strong> check that if x ∈ L 1 ∪ L 2 , then the nondeterministic TuringMachine N has a sequence of at most max{p (1) (|x|),p (2) (|x|)} + 2 allowed steps sothat N halts in its accepting state. And if x /∈ L 1 ∪ L 2 , then x /∈ L 1 and x /∈ L 2 , so withinput x, N can never reach the accepting state of the N (1) and the N (2) part of N, andhence such an x willneverbe accepted.(b) We use the set-up from (a) again. And in fact we can use almost the same ideas, exceptnow we construct a nondeterministic Turing Machine N as follows: From the initialstateq 0 thereisonetransition<strong>to</strong>theinitialstateq (1)0ofN (1) ;fromtheacceptingstateq (1)Yof N (1) there is one transition <strong>to</strong> the initial state q (2)0of N (2) ; and from the acceptingstate q (2)Y of N(2) there isone transition<strong>to</strong> the generalaccepting state q Y .Again when we give an input x ∈ L 1 ∩ L 2 <strong>to</strong> the resulting nondeterministic TuringMachine N, there is a sequence of at most p (1) (|x|)+ p (2) (|x|)+3 allowed transitionsafter which N has reached its accepting state. And for x /∈ L 1 ∩ L 2 , at least one of thetwo parts will preventthatfromhappening.(c) This time we can’t conclude that L 1 \ L 2 is in NP. The reason is that the fact that x ∈L 1 \ L 2 means that x ∈ L 1 and x /∈ L 2 . But we have no good way <strong>to</strong> deal with thesituation x /∈ L 2 .So in generalwedon’tknow if L 1 \L 2 is inNP ornot.5 Property6states: SupposeL 1 isanNP-completelanguage. IfL 2 isalanguagesothatL 2 isinNPand L 1 ≤ P L 2 ,then L 2 is NP-complete.The fact that La 1 is NP-complete means that L 1 is in NP, and for all L ∈ NP we have thatL ≤ P L 1 . And<strong>to</strong>provethatL 2 isNP-completeweneed<strong>to</strong>provethatL 2 isinNP,andforallL ∈ NPwehave that L ≤ P L 2 .We are already given that L 2 is in NP, so we are left <strong>to</strong> prove that L ≤ P L 2 for all L ∈ NP.For this we obviously need <strong>to</strong> use that L ≤ P L 1 for all L ∈ NP and that L 1 ≤ P L 2 . In fact itfollowsdirectlythat itis enough<strong>to</strong> prove the followingproperty:For anythreelanguages L,L ′ ,L ′′ ,if L ≤ P L ′ and L ′ ≤ P L ′′ , then L ≤ P L ′′ .Using the definition of polynomial-time reducibility, L ≤ P L ′ and L ′ ≤ P L ′′ means thatthere exist functions f 1 , f 2 : {0,1} ∗ −→ {0,1} ∗ , Turing Machines M 1 ,M 2 , and polynomialsp 1 ,p 2 so that– forall x ∈ {0,1} ∗ wehave x ∈ L ifand only if f 1 (x) ∈ L ′ ;– forall x ∈ {0,1} ∗ wehave x ∈ L ′ if and only if f 2 (x) ∈ L ′′ ;– forall x ∈ {0,1} ∗ , M 1 computes f 1 (x) inatmost p 1 (|x|) steps;– forall x ∈ {0,1} ∗ , M 2 computes f 2 (x) is atmost p 2 (|x|) steps.Note that since a Turing Machine can only write one bit of output per time step, we alsohave that forall x ∈ {0,1} ∗ the length of f 1 (x) satisfies |f 1 (x)| ≤ p 1 (|x|).Sonowdefineafunction f : {0,1} ∗ −→ {0,1} ∗ by f(x) = f 2 (f 1 (x)). Thenforall x ∈ {0,1} ∗we havethat x ∈ L ifand only if f 1 (x) ∈ L ′ if and only if f(x) = f 2 (f 1 (x)) ∈ L ′′ .


LTCC Course on Graph Theory <strong>Solutions</strong> <strong>to</strong> <strong>Exercises</strong> for Notes 2 — Page 6Moreover,usingaTuringMachinethatfirstperformstheactionsofM 1 andthentheactionsof M 2 will result in a Turing Machine <strong>to</strong> compute f(x) = f 2 (f 1 (x)) and, for some smallconstant C, uses at most p 2 (p 1 (|x|))+ p 1 (|x|)+C steps <strong>to</strong> do so. Note that if p 1 (n),p 2 (n)are polynomials,thenso is p 2 (p 1 (n))+ p 1 (n)+C.This proves that L ≤ P L ′′ and completesthe answer.6 Let L ⊆ {0,1} ∗ be a language in P, L ̸= ∅ and L ̸= {0,1} ∗ . In particular this means thatthere are y 1 ,y 2 ∈ {0,1} ∗ so that y 1 ∈ L but y 2 /∈ L. We will show that forall L ′ ∈ Pwe haveL ′ ≤ P L,whichwouldshow that L is P-complete.If L ′ is in P, then there is a Turing Machine M and an integer d so that for all x ∈ {0,1} ∗ wehave: if x ∈ L ′ , then M accepts x in O(|x| d ) steps; while if x /∈ L ′ , then M rejects x afterO(|x| d ) steps.Now define the function f : {0,1} ∗ −→ {0,1} ∗ as follows: f(x) ={y 1 , if x ∈ L ′ ,y 2 , if x /∈ L ′ .Since y 1 ∈ L and y 2 /∈ L, it’s obvious that for all x ∈ {0,1} ∗ we have x ∈ L ′ if and only iff(x) ∈ L. Moreover, using the Turing Machine M from above, for all x ∈ L, f(x) can becomputedinpolynomialtime. (Justgiveasoutput y 1 ifMaccepts x,andasoutput y 2 ifMrejects x.) This shows L ′ ≤ P L and completesthe answer.Someextranotes:Although the above answer is (hopefully) easy <strong>to</strong> follow, there are some deeper issues it<strong>to</strong>uches. In particular, the algorithm described assumes we have knowledge of suitable y 1and y 2 . By the formulation of the question, we can be sure suitable y 1 ,y 2 exist. And hencethe algorithmexists.But if we would like <strong>to</strong> implement the algorithm above, we would need <strong>to</strong> know explicitlywhat y 1 and y 2 are. And that couldbe aproblem(or alo<strong>to</strong>fwork).So keep this in mind: The definitions of P and so talk about the existence of certain TuringMachines. Itdoesn’trequirethatyou are actuallyable <strong>to</strong> construct them.7 It is easy <strong>to</strong> see that there is a cycle in G through u if and only if there is an edge uv and apath from u <strong>to</strong> v in the graph G ′ formed by removing the edge uv from G. Using SavitchTheorem 11 from Section 2.11 of the notes, it is fairly easy <strong>to</strong> construct a way <strong>to</strong> do thischeckinginthesameamoun<strong>to</strong>fspaceitrequires<strong>to</strong>checkST-CONNECTIVITY(plusalittlebitextra<strong>to</strong> s<strong>to</strong>re the edge uv we arecurrently dealingwith).


LTCC Course on Graph Theory <strong>Solutions</strong> <strong>to</strong> <strong>Exercises</strong> for Notes 2 — Page 7More explicitly, build a 2-tape Turing Machine that does the following. (Here we againassume that the verticesareindicatedby the numbers 1<strong>to</strong> N.)1. Write the vertices u and v onthe tape and set a = 1.2. Write a onthe tape.3. Readthe input tape <strong>to</strong> check if ua is anedge.If ua is an edge,continue withstep4below.If ua is notan edgeand a = N, then conclude thatthere is no cycle through u and s<strong>to</strong>p.If ua is notan edgeand a < N, then increase a by oneand gobeck <strong>to</strong> step2.4. Use Savitch Algorithm <strong>to</strong> check if there is a path from u <strong>to</strong> a in G, where we will ignorethe edge ua inthe computation.If there is suchapath, thenconclude that thereis acycle through u and s<strong>to</strong>p.If such apath doesnot existand a = N, then that thereis no cycle through u;s<strong>to</strong>p.If such apath doesno existand a < N, then increase a by one and go beck <strong>to</strong> step2.Since step 4 can be done using at most O((log(N)) 2 ) memory space, we can easily see thatthe whole procedurecan bedone using atmostO((log(N)) 2 ) memory space.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!