TÖL203F Reiknirit, rökfræði og reiknanleiki 26. apríl, 2016, 9:00 12:00 Aids: One handwritten A4 page (text on both sides). An Icelandic translation of the problems is on the last four pages. There are 4 problems on the exam of varying diculty. You need to justify your solutions to the problems. Points will be deducted for solutions which are hard to read, hard to understand or poorly justied, even though the answer may be correct. You can answer either in Icelandic or in English. The problem is on 8 numbered pages. Skim all problems before you start and make sure that nothing is missing. Do all your work in the space provided on the exam (using the back sheets if needed). Name:
Problem 1 (25%) a) (13%) Consider the problem of climbing a wall that is constructed out of square blocks of equal size, each of which provides one handhold. Some handholds are more dangerous/complicated than other. From each block the climber can reach three blocks of the row right above: one right on top, one to the right and one to the left (unless right or left are not available because that is the end of the wall). The goal is to nd the cost of the least dangerous path from the bottom of the wall to the top, where danger rating (cost) of a path is the sum of danger ratings (costs) of blocks used on that path. The input to the problem is an m n matrix C where C ij > 0 is the cost associated with square (i, j). Example: For the following 4 5 matrix, the cost of the optimal path (shown in bold) is 12. 2 8 9 5 8 4 4 6 2 3 5 7 5 6 1 3 2 5 4 8 Describe a dynamic programming algorithm with polynomial running time which determines the cost of the least dangerous path from the bottom to the top. 1
b) (12%) Suppose we are given an n n square grid, some of whose squares are colored black and the rest white. Describe and analyze a polynomial time algorithm to determine whether tokens (X) can be placed on the grid so that every token is on a white square; every row of the grid contains exactly one token; and every column of the grid contains exactly one token. Your input is a two dimensional array IsWhite[1... n, 1... n] of booleans, indicating which squares are white. Your output is a single boolean. For example, given the following grid as input, your algorithm should return True. 2
Problem 2 (25%) a) (10%) Which of the following statements are known to be true? Indicate true statements with an X. 3-SAT p 2-SAT. 4-SAT p 3-SAT. SAT NP co NP. If NP = co NP then P = NP. If P = NP then the Polynomial Hierarchy (P H) collapses to P. b) (5%) Suppose that you have access to an oracle who can answer the SUBSET-SUM decision problem, SUBSET-SUM Input: A set S = {s 1, s 2,..., s n } of positive integers and an integer t. Question: Does there exist a subset A {1, 2,..., n} such that i A s i = t? Show that it is possible to nd a partition A which sums to t, if one exists, by asking the oracle a polynomial number of questions. 3
c) (10%) A subset of nodes in an undirected graph G is said to be independent if no two nodes in the set are adjacent (i.e. connected by an edge). Show that the following problem is NP-complete. INDEPENDENT SET Input: A graph G and an integer k. Question: Does G have an independent set of size k or more? 4
Problem 3 (30%) a) (10%) Which of the following statements are known to be true? Indicate true statements with an X. Ackermann's function is primitive recursive. Partial recursive functions are capable of universal computation. Deciding whether a program Π halts in time t is decidable. Deciding whether a program Π halts is decidable. The set of all Turing machines is uncountably innite. b) (10%) Argue that the following statement about programs in the JAVA programming language is undecidable: Is any statement in this program unreachable? 5
c) (10%) Argue that a counter machine with two or more counters is capable of universal computation. You can cite results from the lectures, textbook and homework assignments in your argument. 6
Problem 4 a) (10%) Which of the following statements are known to be true? Indicate true statements with an X. REACHABILITY is in L. REACHABILITY is in NL. NAE-3-SAT L GRAPH-3-COLORING. The theorem of Savitch implies that NSP ACE( log n) SP ACE(log n). The proof that NL=co NL that appears in chapter 8 of the textbook and discussed in class can easily be modied to show that NP = co NP. b) (10%) Explain why NL P. You can cite results from the lectures, textbook and homework assignments in your argument. 7
c) (10%) Show that INTEGER PROGRAMMING is NP-hard by reducing from GRAPH- 3-COLORING (or GRAPH-k-COLORING with k 3, if you prefer). 8
Íslensk þýðing Dæmi 1 a) (13%) Þetta verkefni snýr að því að klífa vegg sem samanstendur af ferningslaga kubbum sem allir eru jafnstórir. Hver kubbur veitir eina handfestu og eru þær mis erðar/hættulegar. Klifrari kemst úr tiltekinni blokk í þrjár blokkir í næstu röð fyrir ofan: þá sem er beint fyrir ofan hann, þá sem er fyrir ofan hann og einn reit til vinstri og þá sem er fyrir ofan hann og einn reit til hægri (nema hann sé kominn út í enda veggjarins). Verkefnið snýst um að nna hættuminnstu leiðina frá neðsta hluta veggjarins til þess efsta. Heildarhætta fyrir tiltekna leið er summa hættu (kostnaðar) fyrir hverja blokk á leiðinni. Inntak verkefnisins er m n fylki C þar sem C ij > 0 er kostnaður (hætta) við blokk (i, j). Dæmi: Fyrir 4 5 fylkið hér að neðan er heildarkostnaður bestu leiðarinnar 12 (leiðin er feitletruð). 2 8 9 5 8 4 4 6 2 3 5 7 5 6 1 3 2 5 4 8 Setjið fram kvikt bestunarreiknirit sem keyrir í margliðutíma til ákvörðunar á kostnaði við hættuminnstu leiðina. b) (12%) Geð er n n reitaborð sem er þannig að hluti reitanna er litaður svartur og afgangurinn hvítur. Lýsið reikniriti sem keyrir í margliðutíma til að ákvarða hvort hægt sé að setja merki (X) á reitina þannig að öll merkin séu á hvítum reit, hver röð inniheldur nákvæmlega eitt merki og hver dálkur inniheldur nákvæmlega eitt merki. Inntakið er fylkið IsWhite[1... n, 1... n] sem geymir Bool gildi sem tilgreina hvaða reitir eru hvítir. Úttakið er eitt Bool gildi. Dæmi: Fyrir netið á bls. 2 á reikniritið að skila SATT.
Dæmi 2 (25%) a) (10%) Setjið X við þær fullyrðingar sem vitað er að eru sannar. 3-SAT p 2-SAT. 4-SAT p 3-SAT. SAT NP co NP. Ef NP = co NP þá P = NP. Ef P = NP þá fellur Polynomial Hierarchy (P H) saman við P. b) (5%) Gerið ráð fyrir að hafa aðgang að véfrétt sem getur ákvarðað SUBSET-SUM verkefnið, SUBSET-SUM Inntak: Mengi S = {s 1, s 2,..., s n } jákvæðra heiltalna og heiltala t. Spurning: Er til hlutmengi A {1, 2,..., n} þannig að i A s i = t? Sýnið hvernig nna megi skiptingu A þannig að summa staka í skiptingunni sé t, ef slík skipting er á annað borð til, með því að spyrja véfréttina ítrekað þ.a. fjöldi fyrirspurna sé margliða í stærð verkefnisins. c) (10%) Hlutmengi hnúta í óstefndu neti G kallast óháð ef engir tveir hnútar í menginu eru aðlægir (þ.e. tengdir með legg). Sýnið að eftirfarandi verkefni sé NPfullkomið. INDEPENDENT SET Inntak: Net G og heiltala k. Spurning: Hefur G óháð mengi með k eða eiri hnútum?
Dæmi 3 (30%) a) (10%) Setjið X við þær fullyrðingar sem vitað er að eru sannar. Ackermann fallið er frumstætt rakið. Hlutrakin föll svara til reiknanlegra falla. Það verkefni að ákvarða hvort forrit Π stöðvi eftir tíma t er ákvarðanlegt. Það verkefni að ákvarða hvort forrit Π stöðvi er ákvarðanlegt. Mengi allra Turing-véla er óteljanlega óendanlegt. b) (10%) Færið rök fyrir því að eftirfarandi fullyrðing um forrit sem skrifuð eru í JAVA forritunarmálinu sé ekki ákvarðanleg: Er einhver skipun í þessu forriti sem verður aldrei framkvæmd? c) (10%) Færið rök fyrir því að teljaravél með tveimur eða eiri teljurum sé fær um alhliða reikninga (e. universal computation). Þið getið vísað í niðurstöður úr fyrirlestrum, kennslubók og heimadæmum í rökstuðningi ykkar.
Dæmi 4 (30%) a) (10%) Setjið X við þær fullyrðingar sem vitað er að eru sannar. REACHABILITY er í L. REACHABILITY er í NL. NAE-3-SAT L GRAPH-3-COLORING. Setning Savitch felur í sér að NSP ACE( log n) SP ACE(log n). Sönnun á því að NL = co NL sem er að nna í kaa 8 í kennslubók og fjallað var um í fyrirlestri má auðveldlega breyta til að sýna að NP = co NP. b) (10%) Skýrið hvers vegna NL P. Þið getið vísað í niðurstöður úr fyrirlestrum, kennslubók og heimadæmum í rökstuðningi ykkar. c) (10%) Sýnið að INTEGER PROGRAMMING sé NP-ertt með yrfærslu frá GRAPH- 3-COLORING (eða GRAPH-k-COLORING með k 3, ef ykkur nnst það þægilegra).