here - International Olympiad in Informatics
Transcription
here - International Olympiad in Informatics
Olympiads in Informatics, 2016, Vol. 10, 87–98 © 2016 IOI, Vilnius University DOI: 10.15388/ioi.2016.06 87 Understanding Unsolvable Problem Jonathan Irvin GUNAWAN Undergraduate Student School of Computing, National University of Singapore Computing 1, 13 Computing Drive, Singapore 117417 e-mail: [email protected] Abstract. In recent IOIs, there are several problems that seem unsolvable, until we realise that there is a special case to the problem that makes it tractable. In IOI 2014, the problem ‘Friend’ appears to be a standard NP-hard Maximum Independent Set problem. However, the graph is generated in a very special way, hence there is a way to solve the problem in polynomial time. There were several contestants who didn’t identify the special case in this problem, and hence were stuck at the problem. In this paper, we will study a well-known technique called reduction to show that a problem we are currently tackling is intractable. In addition, we introduce techniques to identify special cases such that contestants will be prepared to tackle these problems. Keywords: special case, unsolvable, NP-hard. 1. Introduction The problem ‘Friend’ in IOI 2014 required contestants to find a set of vertices with maximum total weight, such that no two vertices in the set are sharing a common edge. This is a classical Weighted Maximum Independent Set problem. We can show that Weighted Maximum Independent Set problem is NP-hard by reduction from 3-SAT (Cormen et al., 2009). Since the formulation of NP-completeness 4 decades ago, no one has been able to propose a solution to any NP-hard problem in polynomial time. Clearly, it is not expected that a high school student can solve the problem in 5 hours. None of the Indonesian IOI 2014 team solved this problem during the contest. After returning from the competition, I asked the Indonesian team about this problem. None of the team members were aware of the fact that Maximum Independent Set is an NP-hard problem, and thus were stuck trying to solve a general Maximum Independent Set problem. A similar problem also occurred in IOI 2008. The problem ‘Island’ required contestants to find a longest path in a graph with 1,000,000 vertices. The longest path problem is a classic NP-hard problem which can be reduced from the Hamiltonian path problem. If a contestant is not aware that the longest path problem is difficult to solve, the contestant may spend a lot of his/her time just to tackle the general longest path problem, without realising that there is a special case to the given graph. 88 J.I. Gunawan Generally, some contestants spend too much thinking time trying to solve something that is believed to be unsolvable. If only they realise that their attempt is intractable, they may try a different approach and find a special case of this problem. In section 2 of this paper, we will introduce a classic reduction technique often used in theoretical computer science research. In the context of competitive programming, we may find out that a problem which we are attempting is unlikely to be solvable. After realizing that a problem is intractable, we are going to discuss how to proceed to solve the problem in section 3. Finally, in section 4 we will take a look at some common special cases in competitive programming that can be used to solve these kind of problems. Fig. 1. The result of Indonesian team in IOI 2014, taken from http://stats.ioinformatics.org. The red squared column highlights the ‘Friend’ problem. Fig. 2. IOI 2014 tasks statistics, taken from http://stats.ioinformatics.org. ‘Friend’ problem is the second least accepted problem in IOI 2014. It may be because some contestants (at least all the Indonesians) were stuck at trying to solve a general case of Maximum Independent Set. Fig. 3. The result of Indonesian team in IOI 2008, taken from http://stats.ioinformatics.org. The red squared column highlights the ‘Island’ problem. Understanding Unsolvable Problem 89 2. Identifying Intractability of a Problem through Reduction 22 Identifying Identifying Intractability Intractability of aaRedu Pro Pro 22 Identifying of aaProblem through Reduc IdentifyingIntractability Intractability of Problem through 2 Identifying Intractability of aof Problem 2 Identifying Intractability ofR entifying Intractability of a Problem through Reduction 2 2 Identifying Identifying Intractability Intractability of of a a Problem Problem through through We would like to know that the problem that we are attempting is unlikely to have an m through Reduction actability of a Problem through Reduction ifying Intractability of a Problem through Reduction 2 through Identifying Intractability ofthe aproblem Problem through R Intractability of a Problem through Reduction of a Problem Reduction We We would would like like to to know know that that the problem that that we we are are attempting attempting isis u immediate solution. The most way toare apply athe well-known technique called rough Reduction solut We would totoknow that the problem that attempting is unlikely to have an immediate soluti We wouldlike like know that thecommon problem that we are attempting is unlikely to have an immediate solu We would like toiswe know that problem that we are attempting is unlikely We that would like to thatisisthe problem thatcalled we are att actability of awould Problem doto like to know that the problem that we are attempting is Reduction unlikely to have anknow immediate solution. We We would would like like to know know that that the problem problem that we are are attempting attempting unlikely unlikely to toThe have have an an immedi immed have anwe immediate The oblem that areproblem attempting is unlikely tothrough an immediate solution. The most most common common way way iswe iscalled to to apply apply aa and well-known well-known technique technique called redu reduction. Suppose we know that problem X is impossible to solve, we also know know that the that we attempting isthe unlikely to have an immediate solution. The most common way is toto apply ahave technique reduction. Suppose we know that prob We solution. like know that the problem that are is unlikely to have an immedia most common way isare to apply awell-known well-known technique called reduction. Suppose we know thatreduc pro most common way is to we apply aattempting well-known technique called reduction. at the problem that we are attempting isSuppose unlikely to have have an immediate solution. The tanthe problem that we attempting is unlikely to an immediate solution. The most common isknow apply a well-known technique attempting is unlikely to have anproblem immediate solution. 1 to mmon isknow to aare well-known technique called reduction. Suppose we know problem X isproblem immediate solution. The most most common common way way is is to to apply apply aknow aThe well-known well-known technique technique called called reduction. reduction. we we know know Suppose we that problem X is well-known technique called reduction. we that problem Xway isX impossible impossible to to solve, solve, and we we also also that that we we can solve solve problem XX b.tI 11 1by that we can solve X by using problem Y asand a black-box If we can solve way isaway to apply aapply well-known technique called reduction. Suppose we know problem Xcan isSuppose impossible toto solve, and we know that we can solve problem by using problem YSuppose asasawe .th most common way isto tohave apply ato well-known technique called reduction. Suppose we impossible solve, and wealso also know that we can solve problem Xthat by.X using problem Y ablack-box black-box impossible solve, and we also know that we can solve problem X know bysolve using apply well-known technique called reduction. Suppose we know that problem X is pply a well-known technique called reduction. Suppose we know that problem is impossible to solve, and we also know that can p 1 blem that we are attempting is unlikely an immediate solution. The e called reduction. Suppose we know that problem X is 1 1 elve, tothat solve, and we also know that we can solve problem X by using problem Y as a black-box . If we can we know that problem X is impossible impossible to to solve, solve, and and we we also also know know that that we we can can solve solve problem problem X X by by using using problem problem Y Y as as a a blac bla 1Y problem Y as a black-box . If we can ow we can solve problem X by using problem Y as a black-box . If we can solve solve problem problem Y, Y, then then we we can can solve solve problem problem X X as as well. well. Therefore, Therefore, pro pr problem Y , then we can solve problem X as well. Therefore, problem is also imand we that also know that we can solve problem X by using problem Ysolve as a11 .problem black-box we can solve problem Y, then we can solve problem XY as well. Therefore, problem YIf also impossible to impossible toassolve, and we1problem also know that we can Xcan using problem Y as as asolve. black solve problem Y, then we can solve problem X as well. Therefore, problem Yis is also impossible to solve solve Y, then we can solve problem X.by as well. Therefore, problem eeY also know we can solve problem X by using problem Y as a black-box If we can also know that we can solve problem X by using problem as a black-box . If we can solve problem Y, then we solve problem X well. T ell-known technique called reduction. Suppose we know that problem X is 1 problem X by using problem Y a black-box . If we can 2 Identifying Intractability of Problem through Reduc blem Y, then can solve problem X Therefore, Y as is a also impossible toproblem solve. a we black-box . Ifto we can solve problem Y, Y,as then then we can can solve solve problem problem XX as well. well. Therefore, Therefore, problem YY isis also also impossible impossible possible to solve. isasalso impossible solve. Xcan aswe well. Therefore, problem Ywell. iswe also impossible ,Yproblem then solve problem X as well. Therefore, problem Ytoissolve. also to solve. solve problem Y, then we canY solve problem X1 .asIfimpossible well. Therefore, problem Y is also impossible t can solve problem X as well. Therefore, problem Y is also impossible to solve. an solve problem X as well. Therefore, problem is also impossible to solve. w that we can solve problem X by using problem as a black-box we can Therefore, problem Y is also impossible to solve. We are using NP-hard problems forWe illustration. Recall that NP-hard problems have impossible to solve. We are are using using NP-hard NP-hard problems problems for for illustration. illustration. Recall Recall that that NP-hard NP-har We using problems for illustration. Recall that NP-hard problems to bebe solved ininpopt Weare arelike using NP-hard problems for illustration. Recall that NP-hard problems have yet toNP-hard solved We are using problems for Recall that proble Weyet would toNP-hard know that problem thatNP-hard we are attempting isillustration. unlikely to have have an immediate soluti We are using NP-hard problems foryet illustration. Recall problem X as well. Therefore, problem Ythe is also impossible toproblems solve. to be solved in polynomial time for more than 4 decades. MIN-VERTEX-COVER eNP-hard using NP-hard problems for illustration. Recall that NP-hard have yet to be solved in polynomial We We are are using using NP-hard NP-hard problems problems for for illustration. illustration. Recall Recall that that NP-hard NP-hard problems problems have have yet yet to to be be so so ms have yet to be solved in polynomial or illustration. Recall that NP-hard problems have yet to be solved in polynomial time time for for more more than than 4 4 decades. decades. MIN-VERTEX-COVER MIN-VERTEX-COVER is is a a graph graph prob pro 2 Identifying Intractability of a Problem through Reductio 2 Identifying Intractability of a Problem through Redu problems for illustration. Recall that NP-hard problems have yet to be solved in polynomial minimu time for more than 4 decades. MIN-VERTEX-COVER is a graph problem that involves finding a minimum We are using NP-hard problems for illustration. Recall that NP-hard problems have yet to be solv time for more than 4 decades. MIN-VERTEX-COVER is a graph problem that involves finding a minim time for more than 4 decades. MIN-VERTEX-COVER is a graph problem most common way isthat tobeinvolves apply ainfinding well-known technique called reduction. Suppose we know that prob roblems for illustration. Recall that NP-hard problems have yet to be solved in polynomial roblems for illustration. Recall that NP-hard problems have yet to be solved in polynomial time for more than 4graph decades. MIN-VERTEX-COVER isth ll that NP-hard problems have yet to solved polynomial 2 Identifying Intractability of a Problem throu 2 2 Identifying Identifying Intractability Intractability of of 2 a a Problem Identifying Problem through through Intractability Reduction Reduction of is a graph problem a minimum subset of nodes such that for every more than 4 decades. MIN-VERTEX-COVER is a graph problem that involves finding a minimum subset yet to be solved in polynomial time time for for more more than than 4 4 decades. decades. MIN-VERTEX-COVER MIN-VERTEX-COVER is is a a graph problem problem that that involves involves finding finding hat involves finding a minimum subset -VERTEX-COVER is a graph problem that involves finding a minimum subset of of nodes nodes such such that that for for every every edge, edge, at at least least one one of of its its endpoint endpoint is is in in ta tifying Intractability a atProblem through Reduction han 4MIN-VERTEX-COVER decades. MIN-VERTEX-COVER isof aof graph that involves finding aby minimum 1sub MAX-INDEPENDENTof nodes such that for every edge, least one offinding its endpoint the subset. MAX-INDEPENDENT-S time for more than 4also decades. MIN-VERTEX-COVER isisat aXingraph problem that involves finding ofRecall nodes such that for every edge, atproblem least one ofnodes its endpoint is in the subset. MAX-INDEPENDENT nodes such that for every edge, least one ofsubset its endpoint is in the impossible tolike solve, and we know that we can solve problem using problem Yleast as immediate aone black-box .aT I des. is a graph problem that involves finding a minimum subset des. MIN-VERTEX-COVER is a graph problem that involves a minimum subset of such that for every edge, at of its end or illustration. that NP-hard problems have yet to be solved in polynomial is a graph problem that involves finding a minimum subset Intractability of a Problem through Reduction edge, at least one of its endpoint is in the subset. MAX-INDEPENDENT-SET is a graph We would like to know that the problem that we are attempting is unlikely to have an immediate solution. We would like to know that the problem that we are attempting is unlikely to have an immediate solution. We would to know that the problem that we are attempting is unlikely to have an solu such that for every edge, at least one of its endpoint is in the subset. MAX-INDEPENDENT-SET is a es a graph minimum subset of of nodes nodes such such that for for every every edge, edge, at at least least one one of of its its endpoint isissubset in in the theat subset. subset. MAX-INDEPE MAX-INDEPE set.finding MAX-INDEPENDENT-SET isthat athat at least one of its problem endpoint is in the subset. MAX-INDEPENDENT-SET afor graph graph problem problem of of finding finding athat aisendpoint maximum maximum subset of of nodes nodes such such that that for for eT hat for every edge, at least one of its endpoint is in the subset. MAX-INDEPENDENT-SET is a endp of finding a maximum subset of nodes such that every edge, most one of its endpo of nodes such for every edge, at least one of its endpoint is in the subset. MAX-INDEPEN graph problem of finding a maximum subset of nodes such for every edge, at most one of its endp graph problem of finding a maximum subset of nodes such for every e 2 Identifying Intractability of a Problem through Redu We would like to know that the problem that we are attempting is unlikely to have an We We would would like like to to know know that that the the problem problem that that we we are are attempting attempting We would is is like unlikely unlikely to know to to have have that an an the immediate immediate problem that solution. solution. we are The The att solve problem Y, then we can solve problem X as well. Therefore, problem Y is also impossible to solve. ry edge, at least of its endpoint is in the subset. MAX-INDEPENDENT-SET isof athat ry at least its endpoint is the subset. MAX-INDEPENDENT-SET is aat graph problem ofsuch finding maximum subset of nodes su VERTEX-COVER iscommon aof graph problem involves finding aSuppose minimum subset ndpoint is in the subset. MAX-INDEPENDENT-SET isfor aof problem of finding ais maximum subset of nodes such that for every edge, most one of toedge, know that theone problem that are attempting is unlikely tocalled have an immediate solution. The most common way is to apply anodes well-known technique called reduction. Suppose we know that problem X most common way is to apply ain well-known technique reduction. Suppose we know problem most way to apply aat technique called reduction. Suppose weisthat know that pro oblem finding aone maximum subset such that every edge, at one its endpoint in most X-INDEPENDENT-SET is aproblem graph graph problem of ofthat finding finding aawell-known maximum maximum subset subset of of nodes nodes such that for for every every edge, edge, at at most one one dge, atof most one of its endpoint in um subset nodes such that forwe every edge, most one its endpoint ismost in the the subset. subset. Suppose we we already already know know that MIN-VERTEX-COVER MIN-VERTEX-COVER isof isoX of finding aofsubset maximum subset of nodes such that for every edge, at most one of its endpoint is in the subset. Suppose we already know that MIN-VERTEX-COVER is athat NP-hard problem. we ci graph problem of finding a maximum subset of nodes such that for every edge, atTherefore, most one of the subset. Suppose we already know that MIN-VERTEX-COVER is ato NP-hard problem. Therefore, we the subset. Suppose we already know that MIN-VERTEX-COVER is aX NP-h at the problem that we are attempting is unlikely to have an immediate solution. The most common way is to apply a well-known technique called reduction. Suppose we most most common common way way is is to to apply apply a a well-known well-known technique technique most called called common reduction. reduction. way Suppose Suppose is apply we we know a know well-known that that problem problem technique X is 1 1 maximum of nodes such that for every edge, at most one of its endpoint is in 1is maximum subset of nodes such that for every edge, at most one of its endpoint is in the subset. Suppose we already know MIN-VERTEX at least one of its endpoint is in the subset. MAX-INDEPENDENT-SET is a such that for every edge, at most one of its endpoint is in its endpoint is in the subset. Suppose we already know that MIN-VERTEXCOVER is way isimpossible to apply ato well-known technique called reduction. Suppose we know that problem Xcan is impossible to solve, and we also know that we can solve problem X by using problem Y as a black-box . If we solve, and we also know that we can solve problem X by using problem Y as a black-box . If we impossible to solve, and we also know that we can solve problem X by using problem Y as a black-box . t. Suppose we already know that MIN-VERTEX-COVER is a NP-hard problem. Therefore, we show most one of its endpoint is in the the subset. subset. Suppose Suppose we we already already know know that that MIN-VERTEX-COVER MIN-VERTEX-COVER is is a a NP-hard NP-hard problem. problem. There There hard problem. Therefore, we can show ow that MIN-VERTEX-COVER is a NP-hard problem. Therefore, we can show that that MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET is is also also a a NP-hard NP-hard problem problem by by reduc reduc We would likewe toalso know that the problem that we are attempting is aproblems unlikely to have an immediate solu 1problem 1reducing pose we already know that MIN-VERTEX-COVER isknow asolve NP-hard problem. Therefore, can show 1.solved that MAX-INDEPENDENT-SET iswe also awe NP-hard problem by awe proble the subset. Suppose already that MIN-VERTEX-COVER is aas NP-hard problem. Therefo that MAX-INDEPENDENT-SET ismost also asolve NP-hard problem by reducing MIN-VERTEX-COVER probl that MAX-INDEPENDENT-SET isreducing also apo apply a well-known technique called reduction. Suppose we know that problem XNP-hard isaMIN-VERTEX-COVER impossible to solve, and also know that we can solve problem X by using Y apM impossible impossible to solve, solve, and and we also know know that that we can can problem problem impossible X X by to by using solve, using problem problem and Y as know aproblem aalso black-box black-box that we .can IfIf we we solve can can are using NP-hard problems for illustration. Recall NP-hard have yet to be in 1also eady know that MIN-VERTEX-COVER NP-hard problem. Therefore, we can show eady know MIN-VERTEX-COVER isiswe aaproblem NP-hard problem. Therefore, we can show that MAX-INDEPENDENT-SET is also a by NP-hard m subset of such that for every edge, at one of its endpoint is in ato NP-hard problem. Therefore, we can that MAX-INDEPENDENT-SET ainto EX-COVER isnodes a We NP-hard problem. Therefore, we can show olve, wethat also know that we solve problem Xby by using Y as aproblem. black-box .YYIf we can solve problem Y, then we can solve problem Xshow as well. Therefore, problem Ywe isreducing also impossible to solve. solve problem Y, then we can solve X as well. Therefore, Y is also impossible to solve problem Y, then we can solve problem X asaproblem well. Therefore, problem isis also impossible to proble solve X-INDEPENDENT-SET is also acan NP-hard reducing aNP-hard MIN-VERTEX-COVER problem a solve. lem. Therefore, we can show that that MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET is is also also a NP-hard problem problem by by reducing a a MIN-VERTEX-COVE MIN-VERTEX-COV MIN-VERTEX-COVER problem into a also aand NP-hard problem by reducing a MIN-VERTEX-COVER problem into a MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET problem. 1 most common way is to apply a well-known technique called reduction. Suppose we know that pro EPENDENT-SET is also a NP-hard problem by reducing a MIN-VERTEX-COVER problem into a MAX-INDEPENDENT-SET problem. that MAX-INDEPENDENT-SET is also a NP-hard problem by reducing a MIN-VERTEX-COVER MAX-INDEPENDENT-SET problem. MAX-INDEPENDENT-SET problem. e also know that we can solve problem X by using problem Y as a black-box . If we can solve problem Y, then we can solve problem X as well. Therefore, problem Y is also imp solve solve problem problem Y, Y, then then we we can can solve solve problem problem X X as as well. well. Therefore, Therefore, solve problem problem problem Y, then Y Y is is we also also can impossible impossible solve problem to to solve. solve. X as well. T time for more than 4 decades. MIN-VERTEX-COVER is a graph problem that involves finding a minimum T-SET also NP-hard problem byNP-hard reducing a MIN-VERTEX-COVER MIN-VERTEX-COVER problem into problem reducing a aMIN-VERTEX-COVER problem aaaMAX-INDET-SET also aaNP-hard NP-hard problem reducing problem into problem. w that MIN-VERTEX-COVER aby problem. Therefore, show into blem byisis reducing a problem. MIN-VERTEX-COVER problem into a MAX-INDEPENDENT-SET Y, then we can solve problem Xisby as well. Therefore, problem Y iswe alsocan impossible to solve. DEPENDENT-SET TEX-COVER problem into asolve, MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET problem. problem. m. impossible tothat and weproblem also know weimpossible canitssolve problem X the by using problem Y as a black-box1 . NDENT-SET problem. ability of a Problem through Reduction problem. can solve problem XMAX-INDEPENDENT-SET as well. Therefore, Yleast isthat also to solve. of nodes such for every edge, at one of endpoint is in subset. MAX-INDEPENDENTPENDENT-SET problem. T problem. T problem. also a NP-hard problem by reducing a MIN-VERTEX-COVER problem into a Wesolve areWe using NP-hard problems for illustration. Recall that NP-hard problems have yet to be solved in polynom polynom We are using NP-hard problems for illustration. Recall that NP-hard problems have yet to be solved in are using NP-hard problems for illustration. Recall that NP-hard problems have yet to be solved in p We We will will first first prove prove the the following following two two lemmas. lemmas. problem Y, then we can solve problem Xthat asfor well. Therefore, problem Y isatbe also impossible solve We will first prove following lemmas. We will first prove the following two lemmas. Wetwo will first prove the following two lemmas. Wethe are using NP-hard problems illustration. Recall that NP-hard problems have yet We We are are using using NP-hard NP-hard problems problems for for illustration. illustration. Recall Recall that NP-hard NP-hard are using problems problems NP-hard have have problems yet yet to to be for solved solved illustration. in in polynomial polynomial Recall t graph problem of finding aMIN-VERTEX-COVER maximum subset of nodes such that for every edge, most one of itsto endpo We will first prove the following two lemmas. We will first prove the following two lemmas. 2 Identifying Intractability of a Problem through m. 2 Identifying Intractability of a Problem through Red gill NP-hard problems for illustration. Recall that NP-hard problems have yet to be solved in polynomial time for more than 4 decades. MIN-VERTEX-COVER is a graph problem that involves finding a minimum sub time for more than 4 decades. is a graph problem that involves finding a minimum sub time for more than 4 decades. MIN-VERTEX-COVER is a graph problem that involves finding a minimu first prove the following two lemmas. We We will will first first prove prove the the following following two two lemmas. lemmas. two lemmas. that we are attempting is unlikely to havethe anfollowing immediate solution. The Intractability of a Pro prove the following two lemmas. 2 Identifying We will first prove two lemmas. roblems for illustration. Recall that NP-hard problems have yet to be solved in polynomial time for more than 4 decades. MIN-VERTEX-COVER is a graph problem that involves fi time time for more more than than 4 4 decades. decades. MIN-VERTEX-COVER MIN-VERTEX-COVER is is time a a graph graph for problem more problem than that that 4 decades. involves involves finding MIN-VERTEX-COVER finding a a minimum minimum subset subset is the subset. Suppose we already know that MIN-VERTEX-COVER is a NP-hard problem. Therefore, we c for Lemma Lemma 1. 1. If If S S ⊆ ⊆ V V is is an an INDEPENDENT-SET INDEPENDENT-SET of of graph graph G(V, G(V, E) E) 2 Identifying Intractability of a Problem through Reduction following two lemmas. Problem through Reduction following lemmas. than 4technique decades. MIN-VERTEX-COVER isLemma a we graph problem that involves finding a ,the minimum subset of two nodes such that for every edge, at least one ofSone its endpoint is in the subset. MAX-INDEPENDENT-SET of nodes such that edge, at least one of its endpoint is the subset. MAX-INDEPENDENT-SET of nodes such that every edge, at least of of its endpoint isE), in subset. MAX-INDEPENDENT Lemma 1. Ifusing S Vfor anan INDEPENDENT-SET graph G(V, then VV−− Shave Lemma 1. If is is an INDEPENDENT-SET then is isisaayet Lemma 1. Iffor S⊆every ⊆ VisSuppose INDEPENDENT-SET ofgraph graph G(V, E), then S aVERTEX-COVE VERTEX-COV 1. Ifthat ⊆problem V is an INDEPENDENT-SET of graph G(V, E),ofthen nown called reduction. know X isIfin We are NP-hard problems for illustration. Recall that NP-hard problems to be inaas Lemma 1. S ⊆ V is an INDEPENDENT-SET gra We would like to know that the problem that we are attempting is is unlikely to have imme We would like to know that the problem that we are attempting is unlikely to have an immediate des. is a graph problem involves finding a minimum subset of nodes such that for every edge, at least one of its endpoint in the subset. MAX-IN of nodes such such that that for for every every edge, edge, at at least least one one of of its its endpoint endpoint of nodes is is in such in the the that subset. subset. for every MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET edge, at least one of its isisend that MAX-INDEPENDENT-SET is also a NP-hard problem by reducing a MIN-VERTEX-COVER proble 1. IfVMIN-VERTEX-COVER Snodes ⊆ V is an INDEPENDENT-SET of graph G(V, E), then V − S is a VERTEX-COVER of the Lemma Lemma 1. 1. If If S S ⊆ ⊆ V V is is an an INDEPENDENT-SET INDEPENDENT-SET of of graph graph G(V, G(V, E), E), then then V V − − S Sits is isendpoint asolved aan VERTE VERTE V⊆of − S is a VERTEX-COVER of the ENDENT-SET of graph G(V, E), then − S is a VERTEX-COVER of the graph graph G(V, G(V, E) E) two lemmas. 1 that for every edge, at least one of its endpoint is in the subset. MAX-INDEPENDENT-SET is a is an INDEPENDENT-SET of graph G(V, E), then V − S is a VERTEX-COVER of the graph problem of finding a maximum subset of nodes such that for every edge, at most one of its endpoint graph problem of finding a maximum subset of nodes such that for every edge, at most one of iui VERTEX-COVER of the graph graph problem of finding a maximum subset of nodes such that for every edge, at most one of its endp graph G(V, E) Lemma 1. If S ⊆ V is an INDEPENDENT-SET of graph G(V, E), then V − S is a VERTEX G(V, E) graph G(V, E) ability of a Problem through Reduction . at we can solve problem X by using problem Y as a black-box . If we can We would like to know that the problem that we are attempting is nsing of graph G(V, E), then Vare − Sthe issuch VERTEX-COVER of the time forfinding more than 4E) decades. MIN-VERTEX-COVER is aevery graph problem that involves finding aat minim ngraph INDEPENDENT-SET of G(V, E), then − S is aagraph VERTEX-COVER of the G(V, E) G(V, E), then V − Sgraph away VERTEX-COVER ofaMAX-INDEPENDENT-SET We like to know that problem that we attempting is unlikely to have immediate solution. The iswould unlikely to have an immediate The most common way is to apply amaximum well-known technique called reduction. Suppose we most common issolution. to apply aV well-known technique called Suppose we know that ry edge, at one of its endpoint in the subset. is amost graph problem of finding subset of such that for every edge, most graph graph problem problem of of finding ais athe maximum maximum subset subset of of nodes nodes such graph that that problem for for every ofaanodes edge, finding edge, at atendpoint aan most maximum one one ofsubset its its endpoint endpoint of nodes isknow is in su in MAX-INDEPENDENT-SET problem. V, E) aINDEPENDENT-SET VERTEX-COVER of the graph graph G(V, G(V, E) of finding aleast maximum subset of nodes such that for every edge, at most one ofaisreduction. its is of in thewell. subset. Suppose we already know that MIN-VERTEX-COVER is NP-hard problem. Therefore, we can sh the subset. Suppose we already know that MIN-VERTEX-COVER is NP-hard problem. Therefore, we can sh the subset. Suppose we already know that MIN-VERTEX-COVER a NP-hard problem. Therefore, we graph G(V, E) ing Intractability of a Problem through Reduction em X as Therefore, problem Y is also impossible to solve. most common way is to apply well-known technique called reduc Proof. Proof. Let us us assume assume that that VSuppose Vis − −in SSXthe is is not not aaby VERTEX-COVER. VERTEX-COVER. Ther Ther of nodes such that for every edge, at least one of itsthat endpoint subset. MAX-INDEPENDENT of graph G(V, E), then Vthat − SMIN-VERTEX-COVER is anot VERTEX-COVER of the Proof. Let us assume that is aaat VERTEX-COVER. Therefore, there are two common way is to apply athat well-known called reduction. we know that problem XA, is dmost reduction. Suppose we know problem Xis isnot impossible to solve, and we also know that we can solve problem X using problem Y as aBb∈ impossible to solve, and we also know that we can solve using problem Y as acan black-bo aENDENT-SET maximum subset of nodes such that for every edge, most one of endpoint is in the subset. we already know MIN-VERTEX-COVER is atwo NP-hard problem. the thewe subset. subset. Suppose Suppose we we already already know know that MIN-VERTEX-COVER the subset. is Suppose a− aproblem NP-hard NP-hard we problem. problem. already know Therefore, that MIN-VERTEX we we can show show Proof. Let us that VSuppose − S VERTEX-COVER. Therefore, there are B / Proof. Let us assume that V − S technique is not aLet VERTEX-COVER. there are two vertices A, Let us assume that Visits STherefore, isTherefore, not aby VERTEX-COVER. Therefore, that are attempting isassume unlikely to have an solution. The ppose we already know that MIN-VERTEX-COVER is NP-hard problem. can show that MAX-INDEPENDENT-SET isProof. also aand NP-hard problem by reducing MIN-VERTEX-COVER problem int Proof. Let us assume that VMIN-VERTEX-COVER − STherefore, is not a1vertices VERTEX-CO that MAX-INDEPENDENT-SET is also NP-hard problem by reducing aaknow MIN-VERTEX-COVER problem int that MAX-INDEPENDENT-SET isaimmediate also aSaS NP-hard problem by reducing awe probl impossible to solve, and we also that we can solve problem Xend by 1 et us assume that V − S is not a VERTEX-COVER. Therefore, there are two vertices A, B ∈ / V − S Proof. Proof. Let Let us us assume assume that that V V − − is is not not a a VERTEX-COVER. VERTEX-COVER. Therefore, Therefore, there there are are two two vertic vertic there are two vertices A, B ∈ / V − S is not a VERTEX-COVER. Therefore, there are two vertices A, B ∈ / V − S and there there is is an an edge edge connecting connecting A A and and B. B. Since Since A, A, B B ∈ / ∈ / V V − − S, S, we we graph problem of finding a maximum subset of nodes such that for every edge, at most one of its vertices and there is an edge connecting and . Since impossible to solve, and we also know that we can solve problem X by using problem Y as a black-box . If we can m X by using problem Y as a black-box . If we can solve problem Y, then we can solve problem X as well. Therefore, problem Y is also impossib ssume that V − S is not a VERTEX-COVER. Therefore, there are two vertices A, B ∈ / V − S solve problem Y, then we can solve problem X as well. Therefore, problem Y is also impossible to so ready know that MIN-VERTEX-COVER is a NP-hard problem. Therefore, we can show that MAX-INDEPENDENT-SET is also a NP-hard problem by reducing a MIN-VERTEX that that MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET is is also also a a NP-hard NP-hard problem problem that by by MAX-INDEPENDENT-SET reducing reducing a a MIN-VERTEX-COVER MIN-VERTEX-COVER is also a problem problem NP-hard into into proble a a and there is an edge connecting A and B. Since A, B ∈ / V − S, we have A, B ∈ S. As A and B are co We will first prove the following two lemmas. Proof. Let us assume that V − S is not a VERTEX-COVER. Therefore, there are two vertice and there is an edge connecting A and B. Since A, B ∈ / V − S, we have A, B ∈ S. As A and B are c and is an edge connecting A and B. A,A Band ∈ /a VB.−Since S, weA, have ow that the problem that we are attempting isB unlikely to have an immediate solution. The nown technique called reduction. Suppose wethere know that problem XBis isA, DEPENDENT-SET is∈ also athere NP-hard problem by reducing atwo MIN-VERTEX-COVER problem into − is not VERTEX-COVER. Therefore, there are two vertices A, B /is − SSince VV − SSMAX-INDEPENDENT-SET is not aathat VERTEX-COVER. Therefore, there are A, B //∈ VVA − S MAX-INDEPENDENT-SET problem. and there anS. edge connecting B ∈ /A problem. Therefore, there are two vertices A, ∈ /be V − S MAX-INDEPENDENT-SET problem. stration. Recall NP-hard problems have yet solved in polynomial solve problem Y,vertices then we can solve problem X as well. Therefore, pro etCOVER. isBMAX-INDEPENDENT-SET an edge connecting A and B. Since A, B ∈ /to − S, we have A, ∈ As B are connected two vertices A, B /and Vimpossible − S and there isproblem. isto an an edge edge connecting connecting A A and and B. B. Since Since A, B B ∈ /∈ ∈ Vby V − − S, S, we we have have A, A, B B ∈∈Therefore S. S. As As A AThis and and A, ∈B. S. As A and B are connected and Since A, B ∈ /and Vwe − S, we have A, B ∈ S. As A B are connected by by an an edge, edge, we we note note that that S S not not an an INDEPENDENT-SET. INDEPENDENT-SET. Thi ,note we have .V As and and Since are connected an edge, we note the subset. Suppose we already that MIN-VERTEX-COVER isinto aand NP-hard problem. Therefore, we solve problem Y, then can solve problem Xknow as well. Therefore, problem Y isis also impossible to solve. ore, problem Y isNP-hard also solve. edge connecting A B. Since A, B ∈ / V − S, we have A, ∈ S. As A and B are connected T-SET is also a problem by reducing a MIN-VERTEX-COVER problem a MAX-INDEPENDENT-SET problem. MAX-INDEPENDENT-SET problem. MAX-INDEPENDENT-SET problem. 1 B that by an edge, we that S is not an INDEPENDENT-SET. This is a contradiction. V − there is an edge connecting A and B. A, B ∈ / V − S, we have A, B ∈ S. As A and B by an edge, we note that S is not an INDEPENDENT-SET. This is a contradiction. Therefore V by an edge, we note S is not an INDEPENDENT-SET. This is a c is to apply a well-known technique called reduction. Suppose we know that problem X is at we can solve problem X by using problem Y as a black-box . If we can NDENT-SET problem. ecting Aand and B. Since A, B /This VVINDEPENDENT-SET. − S, we have A, B ∈ S. As A and BVSare are connected tifying Intractability of aare Problem Reduction ecting and B. A, ∈ /∈ V − we A, B S. As A and B byaisINDEPENDENT-SET. an edge, we note that SVMIN-VERTEX-COVER is−isisnot an INDEPENDENT stge, not aA VERTEX-COVER. Therefore, there two vertices A, B ∈ /− −is Sconnected ∈ /As Vwe S, we have ∈VB S. As A and Bhave are connected TEX-COVER is aSince graph problem that finding aanot minimum subset Lemma If SWe ⊆ is INDEPENDENT-SET of graph G(V, E), then is aa VERTEX-COVE note that SA, is not an This athrough contradiction. Therefore VSis S isyethave a to be A− B are connected by byB an an edge, edge, we we note note that that S S isis∈ not an an INDEPENDENT-SET. This This aa − contradiction. contradiction. Ther The that 1. is not an INDEPENDENT-SET. This is contradiction. Therefore is contradiction. Therefore − S is aan an INDEPENDENT-SET. isS, ainvolves contradiction. Therefore V areducing VERTEX-COVER. VERTEX-COVER. that MAX-INDEPENDENT-SET is also NP-hard problem by aproblems prob are using NP-hard problems for illustration. Recall that NP-hard problems yet to be note that S is not an INDEPENDENT-SET. This is a contradiction. Therefore V − S a We are using NP-hard problems for illustration. Recall that NP-hard have solved T problem. 1 This VERTEX-COVER. by an edge, we note that S is not an INDEPENDENT-SET. is a contradiction. There VERTEX-COVER. VERTEX-COVER. we also know can solve problem using problem Y connected asisaablack-box .is we can em X as well. Therefore, problem Ythe isThis also impossible is not an INDEPENDENT-SET. This is contradiction. Therefore − SS for isIfaaillustration. SS one is an INDEPENDENT-SET. is contradiction. Therefore VV − We will first prove the following two lemmas. VERTEX-COVER. and B.not Since A, Bathat ∈ /contradiction. VSiswe − S, we have A, Bproblem. ∈XaaS. As and B are We will first prove the following two lemmas. NT-SET. This isWe Therefore Vby − SA isto asolve. will first prove following two lemmas. st of its endpoint in subset. MAX-INDEPENDENT-SET We are using NP-hard problems Recall that NP-hard VERTEX-COVER. graph G(V, E) -COVER. tion. Therefore V − is athe VERTEX-COVER. VERTEX-COVER. MAX-INDEPENDENT-SET Wecan are using NP-hard problems illustration. Recall that NP-hard problems have yet to be solved in involves polynomial NP-hard problems have yet to be solved in polynomial time for more than 4lemmas. decades. MIN-VERTEX-COVER issolve. a problem graph problem that findin ER. time for more than 4are decades. MIN-VERTEX-COVER is aimmediate graph that involves finding min We will first prove the following two lemmas. We We will will first first prove prove the the following following two two lemmas. We will first prove the following two lemmas. VERTEX-COVER. to know that the problem that weisfor attempting is unlikely to have an solution. en we solve problem X as well. Therefore, problem Y is also impossible to Lemma Lemma 2. 2. If If S S ⊆ ⊆ V V is is a a VERTEX-COVER VERTEX-COVER of ofThe graph graph G(V, G(V, E), E),a prob then the t prove the following two lemmas. an INDEPENDENT-SET. This a contradiction. Therefore V − S is a bset of nodes such that for every edge, at most one of its endpoint is in time for more than 4 decades. MIN-VERTEX-COVER is a graph Lemma 2. If S ⊆ V is a VERTEX-COVER of graph G(V, E), then V − S is an INDEPENDENT-SE Lemma 2. If S ⊆ V is a VERTEX-COVER of graph G(V, E), then V − S is an INDEPENDENT-S Lemma 2. If S ⊆ V is a VERTEX-COVER of graph G(V, E), then V of − time for more than 4 decades. MIN-VERTEX-COVER is a graph problem that involves finding a minimum subset ph problem that involves finding a minimum subset of nodes such that for every edge, at least one of its endpoint is in the subset. MAX-INDEP Lemma 1. If S ⊆ V is an INDEPENDENT-SET of graph G(V, E), then V − S is a VERTEX-COVER of Lemma 2. If S ⊆ V is a VERTEX-COVER of graph G∈ of nodes such that for every edge, at least one of its endpoint is in the subset. MAX-INDEPENDE following two lemmas. Lemma 1. If S ⊆ V is an INDEPENDENT-SET of G(V, E), then V − S is a VERTEX-COVER Lemma 2. If is a VERTEX-COVER graph , then an INLemma 1. If S ⊆ V is an INDEPENDENT-SET graph G(V, E), then V − S is a VERTEX-COV nX-COVER way to apply aLet well-known technique called reduction. Suppose we know that problem X SS isofisisthe Proof. usE), assume that VS is not aG(V, VERTEX-COVER. Therefore, there two vertices A, B 2. IfVan Sis ⊆ V is a SS VERTEX-COVER graph E), then Vthat − Sof is an INDEPENDENT-SET Lemma Lemma 2. 2. IfIfthe SSof ⊆ ⊆ VV− is isS aaG(V, VERTEX-COVER VERTEX-COVER of graph graph G(V, G(V, E), E), then then VVare − − an anVINDEPEND INDEPEND stration. Recall that NP-hard problems have yet to be solved in polynomial S isLemma INDEPENDENT-SET of of graph G(V, then V − is an INDEPENDENT-SET of the graph graph G(V, E) E) at MIN-VERTEX-COVER a NP-hard problem. Therefore, we can show of nodes such for every edge, at least one of its endpoint is in t ⊆ is a VERTEX-COVER of graph G(V, E), then V − S is an INDEPENDENT-SET of the Lemma 1. If S ⊆ V is an INDEPENDENT-SET of graph G(V, E), then − S is a Lemma 1. 1. Lemma 1. If If ⊆ ⊆ V V is is an an INDEPENDENT-SET INDEPENDENT-SET of of graph graph G(V, G(V, E), E), If then then S ⊆ V V − − is S S an is is INDEPENDENT-SET a a VERTEX-COVER VERTEX-COVER of of of the the gra graph G(V, E) Lemma 2. If S ⊆ V is a VERTEX-COVER of graph G(V, E), then V − S is an INDEPENDE graph G(V, E) V graph G(V, E) We will first prove the following two lemmas. 1 of nodes such that for every edge, at least one of its endpoint is in the subset. MAX-INDEPENDENT-SET is a t-hard is in the subset. MAX-INDEPENDENT-SET is a S ⊆ V is an INDEPENDENT-SET of graph G(V, E), then V − S is a VERTEX-COVER of the graph problem of finding a maximum subset of nodes such that for every edge, at most one VERTEX-COVER of graph G(V, E), then V − S is an INDEPENDENT-SET of the VERTEX-COVER of graph G(V, E), then Vmaximum − Sproblems isB. an INDEPENDENT-SET ofhave the graph G(V, E) DEPENDENT-SET of the graph graph G(V, E) graph problem of finding aproblem of nodes for every at most oneBofare itscoeV graph G(V, E) G(V, E), then Vathere − S isthat anG(V, INDEPENDENT-SET ofby the graph G(V, E) .subset solve, and we also know we can solve X using problem Ysuch as athat black-box .B Ifedge, weS.can and is an edge connecting A and Since A, B ∈ / V − S, we A, ∈ As A and V, E) problems for illustration. Recall that NP-hard have yet to be solved in polynomial NDEPENDENT-SET of the graph graph G(V, E) E) TEX-COVER is graph problem that involves finding a minimum subset a NP-hard problem by reducing a MIN-VERTEX-COVER problem into a graph of is finding maximum subset nodes such that for e ngraph INDEPENDENT-SET ofaG(V, graph G(V, E), then V −problem SThe is proof agraph VERTEX-COVER of the graph E) graph graph G(V, G(V, E) E) G(V, E)athe graph E)its problem of finding maximum subset ofis nodes such that for every edge, atto one endpoint is for every edge, at most one endpoint in Proof. Proof. The proof is actually actually similar similar to to the the previous previous lemma. lemma. Let Let us usinassu assu the subset. we already know that MIN-VERTEX-COVER is− aof NP-hard problem. The the subset. Suppose we already know that MIN-VERTEX-COVER ismost athat NP-hard problem. Therefore, X-COVER ofMIN-VERTEX-COVER graph G(V, E), then VSuppose S is an INDEPENDENT-SET Y,decades. then can solve problem X as well. Therefore, problem Y isof also impossible solve. Proof. The is actually similar to the previous lemma. Let us assume that V Sof not aVERTEX-COV INDEPENDE by an edge, we note S is not an INDEPENDENT-SET. This is athat contradiction. Therefore V − 4at is graph problem that involves finding aus minimum subset Proof. The proof isof actually similar to the previous lemma. Let assume Sis its is not avertices INDEPEND st one ofwe its endpoint is in subset. MAX-INDEPENDENT-SET issimilar aof Proof. The proof isSuppose actually to the previous lemma. Let us assume tha Lemma 1.proof If the S ⊆ Vthat isa− an INDEPENDENT-SET graph G(V, E), then VV − is aprevious Proof. The proof is actually similar to the previous lemma. Let us assume is the subset. we already know that MIN-VERTEX-COVER is Proof. Let us assume that V − S is not a VERTEX-COVER. Therefore, there are two vertices A, B ∈ / V − Proof. The proof is actually similar to the lemma. Proof. Let us assume that V − S is not a VERTEX-COVER. Therefore, there are two vertices A, B ∈ / V − Proof. Let us assume that V − S is not a VERTEX-COVER. Therefore, there are two A, B proof actually similar to the previous lemma. Let usa assume that V − S isproblem not aA, INDEPENDENT-SET. Proof. Proof. The The proof proof is isus actually actually similar similar to to the the previous previous lemma. lemma. Let Let us us assume assume that V V− − SSthere isisis not not aa− IND IND the subset. Suppose we already know that MIN-VERTEX-COVER isTherefore, alemma. NP-hard problem. we can show VER isSprevious aisis NP-hard problem. Therefore, we can show the Visthe − not aus INDEPENDENT-SET. to lemma. Let us assume that VLet −aA, SA, isassume INDEPENDENT-SET. Therefore, Therefore, there there are two two vertices vertices A, B B ∈reducing ∈Vtwo VaVisTherefore, − − Sthat SA and there there is an an edge edge that MAX-INDEPENDENT-SET also aare NP-hard by aand MIN-VERTEX-CO that MAX-INDEPENDENT-SET isnot also aisthe NP-hard problem by reducing MIN-VERTEX-COVER pr∈ of actually similar to the previous lemma. us that V − S is not a INDEPENDENT-SET. Proof. Let assume that V − S is not a VERTEX-COVER. Therefore, are two Proof. Proof. Proof. Let Let us assume assume that that V V − − S S is is not not a VERTEX-COVER. VERTEX-COVER. Therefore, Let us assume there there that are are two − S vertices vertices is not A, A, a VERTEX-CO B B ∈ / ∈ / V V − S S Therefore, there are two vertices B ∈ V − S and there is an edge connecting A and B. Since A, B VERTEX-COVER. for every edge, at least one of its endpoint is in the subset. MAX-INDEPENDENT-SET a Proof. The proof is actually similar to previous Let us assume that V − S is not a INDE Therefore, there are two vertices B ∈ V − S and there is an edge connecting and B. Since A, B bset of nodes such that for every edge, at most one of its endpoint is in Therefore, there are vertices A, B ∈ V − S and there is an edge conne not a INDEPENDENT-SET. Therefore, there two vertices and graph G(V, E) that Vprevious − San is not aconnecting VERTEX-COVER. Therefore, there are two vertices A, B ∈ /NP-hard VB ysassume similar to the previous lemma. Let us assume that −B. SA, is not aA, INDEPENDENT-SET. that MAX-INDEPENDENT-SET isA, also aS. problem by reduc yye, similar to lemma. Let assume that VV − S is not INDEPENDENT-SET. and there is an edge connecting Aatwo and B. Since A, B V − S, we have A, B ∈A, S. As ASVan and Band are connec Therefore, there are two vertices A, B ∈ Vedge, − S and ther and there is A and B. Since A, B ∈ /a/V V we have B ∈ As A and B are connec ma. Let us assume that Vedge − SB is not aus INDEPENDENT-SET. and there is an edge A and Since B ∈ /S, V − S, we have B ∈− S. As A B are c there are two vertices A, ∈ Vthere − STherefore, and there an edge connecting A and B. Since A, ∈ − S, not aMAX-INDEPENDENT-SET INDEPENDENT-SET. Therefore, Therefore, there are are two vertices vertices A, B B ∈V ∈ V − − S S and and there there is is an an edge edge connecting connecting A A and and B. B. Sin Sin isconnecting also NP-hard problem by reducing aand MIN-VERTEX-COVER problem into aB reducing athe MIN-VERTEX-COVER problem into ais A and B. Since A, ∈ Vthere − S, ,that B ∈ VS − S and there is an edge connecting A and B. Since A, B− ∈ V − S, we we have have A, A, B B ∈ /∈ /∈ S. S. As As A AA, and B B are are connected connected by by an edge, we we note note MAX-INDEPENDENT-SET problem. MAX-INDEPENDENT-SET problem. ng NP-hard problems for illustration. Recall that NP-hard problems have yet to be solved in polynomial eat are vertices A, B ∈ VB − S and there is an edge connecting A and B. Since A, B ∈ V −we S, tcting VMIN-VERTEX-COVER −two is not aan VERTEX-COVER. there are two vertices B ∈ /A, V − S and there is an edge connecting A and B. Since A, B ∈ /S, V − S, have A, B ∈ S. As and and there there is is an edge edge connecting connecting A A and and B. B. Since Since A, A, B B ∈ / ∈ / and V − − there S, S, we we is have an have edge A, B B connecting ∈ ∈ S. S. As As A A A and and and B B B. are are Since connected connected A, ∈ / we have A, B ∈ / S. As A and B are connected by an edge, we note that S is not a VERTEX-COVER. T nding a maximum subset of nodes such that for every edge, at most one of its endpoint is in Therefore, are two vertices S there is an edge connecting A and B. Sinc we have A, B ∈ / S. As B are connected by an edge, we note that S is not a VERTEX-COVER. is edge connecting and . Since , have . As and is a NP-hard problem. Therefore, we can show we have A, B ∈ / S. As A and B are connected by an edge, we note that S n edge connecting A and B. Since A, B ∈ / V − S, we have A, B ∈ S. As A and B are connected ertices A, B ∈ V − S and there is an edge connecting A and B. Since A, B ∈ V − S, emmas. MAX-INDEPENDENT-SET problem. ertices A, B ∈ V − S and there is an edge connecting A and B. Since A, B ∈ V − by an edge, we note that S is not an INDEPENDENT-SET. This is a contradiction. Therefore V − S we have A, B ∈ / S. As A and B are connected by an edg o the previous lemma. Let us assume that V − S is not a INDEPENDENT-SET. by an edge, we note that S is not an INDEPENDENT-SET. This is a contradiction. Therefore V − S here is an edge connecting Aconnected and B. A, B ∈ Vnot − S,of by an edge, we note that S is not an INDEPENDENT-SET. This isnote aINDEPENDENT-SET. Therefore VBi Lemma 2. If S ⊆ Vby isedge, aSince VERTEX-COVER graph G(V, E), then V − Scontradiction. is an INDEPENDENT-SE B ∈ / S. As A and B are by an edge, we note that S is not a VERTEX-COVER. This is a and B. Since A, B ∈ V − S, we we have have A, A, B B ∈ / ∈ / S. S. As As A A and and B B are are connected connected by by an an edge, edge, we we note that that S S is is not not a a VERTEX-C VERTEXMAX-INDEPENDENT-SET problem. is not a VERTEX-COVER. This is a eA, connected by an edge, we note that S is not a VERTEX-COVER. This is a contradiction. contradiction. Therefore Therefore V V − − S S is is an an INDEPENDENT-SET. Proof. Let us assume that V − S is a VERTEX-COVER. Therefore, there are two vertices A, than 4 decades. MIN-VERTEX-COVER is a graph problem that involves finding a minimum subset S. As A and B are connected an edge, we note that S is not a VERTEX-COVER. This is a ecting A and B. Since A, B ∈ / V − S, we have A, B ∈ S. As A and B are connected by an we note that S is not an INDEPENDENT-SET. This is a contradiction by by an an edge, edge, we we note note that that by edge, note that SS is not an an INDEPENDENT-SET. INDEPENDENT-SET. This This isisedge, aan aTherefore contradiction. contradiction. Sshow isisis not Therefore INDEPENDENT V− − SS isis aa is are connected by an edge, we note that problem iscontradiction. notanaBVERTEX-COVER. aTherefore concontradiction. Therefore V Sthat isand an INDEPENDENT-SET. we already know that MIN-VERTEX-COVER isSSan ais NP-hard problem. we can we have A,VERTEX-COVER. B ∈ /not S. As A areisisaTherefore connected by an we that S isan not a VVERTEX-C contradiction. V− − S is INDEPENDENT-SET. and NP-hard problem aiswe MIN-VERTEX-COVER into aSwe contradiction. V −Therefore, INDEPENDENT-SET. eVERTEX-COVER. note that S not an INDEPENDENT-SET. This aVERTEX-COVER. contradiction. V − S is aINDEPENDENT-SE and B are connected by an we note that isB not aan This isnote B are connected by an edge, note not VERTEX-COVER. This is VERTEX-COVER. Therefore VaaThis − S an B ∈ V −note S and is an edge connecting A and B. Since S, VERTEX-COVER. edge, we that Sby isreducing not aTherefore This alemmas. VERTEX-COVER. graph G(V, E) tion. Therefore Visthere − S is an INDEPENDENT-SET. This is aedge, contradiction. contradiction. Therefore Therefore V VA − − SS isis an INDEPENDENT-SET. INDEPENDENT-SET. an INDEPENDENT-SET. We will first prove the following twoA,A, lemmas. and there is an edge connecting and B. Since B∈the ∈ /VV−− S, we have A, B ∈ We will first prove the following two that for every edge, at least one of its endpoint is in the subset. MAX-INDEPENDENT-SET isS.a As A and B are ENT-SET of graph G(V, E), then V − S is a VERTEX-COVER of Therefore V − S an INDEPENDENT-SET. S is not an INDEPENDENT-SET. This is a contradiction. Therefore V − S is a tradiction. Therefore is an INDEPENDENT-SET. VERTEX-COVER. VERTEX-COVER. VERTEX-COVER. VERTEX-COVER. NDENT-SET is also a NP-hard problem by reducing a MIN-VERTEX-COVER problem into a contradiction. Therefore V − S is an INDEPENDENT-SET. Theorem 1. 1. IfIf SS ⊆ ⊆ofVThis V isis aaisfollowing MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET of of graph graph G(V G(V ER. − SSWe an INDEPENDENT-SET. INDEPENDENT-SET. We first prove the two lemmas. − isis an connected by edge, we note is aTheorem VERTEX-COVER. a G(V, -SET. Theorem 1. IfVVfollowing S ⊆note Vthat isthat graph E), then VV−− Sof isgraph Theorem 1. If S ⊆ Vnodes isaaSaMAX-INDEPENDENT-SET MAX-INDEPENDENT-SET of graph then S isa aMIN-VERTEX MIN-VERTE will first prove the two lemmas. Theorem 1.of Ifwill S of ⊆ V is at aE), MAX-INDEPENDENT-SET G(V, E),of t byan an edge, we Snot is that not an INDEPENDENT-SET. This isis aMAX-INDEPENDENT-SET contradiction. Therefore m of finding aV maximum subset of such for every edge, most one of its endpoint is in Lemma 2. S2. ⊆ is a1. VERTEX-COVER of graph G(V, E), then V −MIN-VERTEX-COVER S an INDEPENDENT-SET ofoV Theorem 1. Ifus SG(V, ⊆ V isE), ais Lemma 2. IfIf S ⊆ is a1. VERTEX-COVER graph G(V, then V − S an INDEPENDENT-SET Lemma If SIf ⊆S V⊆ is VERTEX-COVER graph G(V, E), then V − S is an INDEPENDENT-SE NT-SET problem. Proof. The proof is actually similar to the previous lemma. Let assume that V − S is not a INDEPENDE m If S ⊆ is a MAX-INDEPENDENT-SET of graph G(V, E), then V − S is a Theorem Theorem If If S S ⊆ ⊆ V V is is a a MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET of of graph graph G(V, G(V, E), E), then then V V − − S S is is a MINMIN hen V − S is a MIN-VERTEX-COVER NDEPENDENT-SET of graph G(V, E), then V − S is a MIN-VERTEX-COVER of of the the graph graph G(V, G(V, E). E). Lemma 1. If S ⊆ V is an INDEPENDENT-SET of graph G(V, E), then V − S is a VERT Theorem 1. is a MAX-INDEPENDENT-SET of graph , then Lemma 1. If V is an INDEPENDENT-SET of graph G(V, E), then V − S is a VERTEX-C nS 1. INDEPENDENT-SET. ⊆ V is a MAX-INDEPENDENT-SET of graph G(V, E), then V − S is a MIN-VERTEX-COVER Lemma 2. If S ⊆ V is a VERTEX-COVER of graph G(V, E), then V − an INDE Lemma Lemma 2. 2. Lemma 2. If If S S ⊆ ⊆ V V is is a a VERTEX-COVER VERTEX-COVER of of graph graph G(V, G(V, E), E), then then If V V S − − ⊆ S S V is is is an an a VERTEX-COVER INDEPENDENT-SET INDEPENDENT-SET of graph of of the the G of the graph G(V, E). Theorem 1. If S ⊆ V is a MAX-INDEPENDENT-SET of graph G(V, E), then S is a MIN-V of the graph G(V, E). of the graph G(V, E). VERTEX-COVER. uppose we that MIN-VERTEX-COVER isVgraph a− NP-hard problem. Therefore, canofAshow SLemma ⊆graph VMIN-VERTEX-COVER isthen aalready VERTEX-COVER of graph G(V, E), then V1. S is the MAX-INDEPENDENT-SET of graph G(V, E), then MIN-VERTEX-COVER Lemma Ifand ⊆an V .INDEPENDENT-SET isis an graph E)∈ MAX-INDEPENDENT-SET of graph G(V, E), then VV − SSS−of isis aaS MIN-VERTEX-COVER graph G(V, E) the graph G(V, E). graph G(V, E) of G(V, E), then VE) −graph SG(V, is aG(V, MIN-VERTEX-COVER G(V, lemmas. Therefore, there are two vertices A, Bvertices ∈of − anINDEPENDENT-SET edge andofB. Since A, B E). S aG(V, of the graph G(V, E). E). 1. Ifgraph S ⊆know V of is an INDEPENDENT-SET G(V, E), then V −of Sconnecting is aweVERTEX-COVER ofG(V, the G(V, E), VE) − S is athe VERTEX-COVER of the graph E) isgraph MIN-VERTEXCOVER of the graph graph G(V, E) taph aisE). VERTEX-COVER. Therefore, there are Vtwo A, B ∈ / there Vthat −V SV V, VERTEX-COVER of G(V, E), then −Proof. S is an INDEPENDENT-SET the graph G(V, E) graph graph G(V, G(V, E) graph G(V, E) of the graph G(V, E). Proof. We We know know that − − S S is is a a vertex vertex cover cover by by lemma lemma 1. 1. The The on o DEPENDENT-SET is also a NP-hard problem by reducing a MIN-VERTEX-COVER problem into a graph G(V, E) DEPENDENT-SET oflemmas. graph G(V, E), then − S is aknow MIN-VERTEX-COVER ve the following twoWe byby Proof. know that V − SVERTEX-COVER is athe cover lemma 1. only thing for us pro we have A, Bis ∈ /actually S. As AV and BVisthe are connected by an edge, we note that S is not aremains VERTEX-COVER. Proof. We know that S avertex vertex cover 1.aThe The only thing that remains forby usto tothin p graph G(V, E) Proof. We that Vlemma − S is vertex cover by lemma 1.cover The only Lemma 2. If S ⊆ VA, isB a−∈ of graph G(V, E), then V− − Sisthat isa− an INDEPENDENT-S B. Since A, B ∈ / V − S, we have S. As A and B are connected Proof. The proof is actually similar to previous lemma. Let us assume that V − S is not a INDEPENDENT-S Proof. We know that V S vertex lemm Proof. The proof similar to previous lemma. Let us assume that V − S is not a INDEPENDENT-S Proof. The proof is actually similar to the previous lemma. Let us assume that V S is not a INDEPEND ENT-SET of graph G(V, E), then V − S is a VERTEX-COVER of the Proof. We know that is vertex cover by lemma 1. The only thing that remains We know that V − S is a vertex cover by lemma 1. The only thing that remains for us to prove is its Proof. Proof. We We know know that that V V − − SSINDEPENDENT-SET. is a− anot vertex vertex cover cover by by lemma lemma 1. 1.− The The only only thing that that remains remains for for ng that for us to prove is its vertex cover lemma 1. The only that remains us tous prove is its V Vlemma − − S S is islemma. not not minimum minimum vertex vertex cover. cover. Then, Then, t minimality. minimality. Suppose Suppose ENDENT-SET problem. Proof. Let us assume that Visalemma. Sforvertex not athe VERTEX-COVER. Therefore, there are two ver Proof. Let us assume aisProof. VERTEX-COVER. Therefore, there are two vertices Ais w that Vremains − Sby is a vertex cover by lemma The only thing that remains for us to prove is its Proof. The proof is actually similar to previous Let usand that VA, −B SV∈Ther is no Proof. Proof. The The proof proof isis actually actually similar similar to to the the previous previous lemma. Let Let us The assume assume proof that isminimum actually V V − S Snot similar not not aassume athing INDEPENDENT-SET. to INDEPENDENT-SET. the previous lemma. Vcontradiction. −thing S isSV not minimum cover. Then, there is another vertex cover S minimality. Suppose contradiction. Therefore Vfor − is an Proof. We know that − S is vertex cover by The only thing that remains for u− VThe − S is1. not minimum vertex cover. Then, there isvertex another vertex cover VV− − minimality. Suppose INDEPENDENT-SET V − S is not cover. Then, there minimality. Suppose graph G(V, E) oof actually similar to the previous lemma. Let us assume that V − S is athat INDEPENDENT-SET. − STherefore, is1. vertex cover by lemma 1. The only thing that remains for us to prove is its INDEPENDENT-SET. This is avertices Therefore V − S is anot Proof. us assume V −1. Sis is athere VERTEX-COVER. − S aaTherefore, vertex cover by lemma 1. only thing that for us to prove its Therefore, there are two vertices A, B ∈ VSS − S and there an edge connecting A B. Since V V − Sis is not minimum vertex cov minimality. Suppose and there are two A, B ∈ V − S there is an edge connecting A B. Since A, B− ∈ ma The only thing that remains us to prove is its Therefore, there two vertices A, B ∈ V − S there is an edge connecting A B. Since A, B that Let and vertices and − V isisis an INDEPENDENT-SET of graph G(V, E), then Vremains − Sand is ais VERTEX-COVER of for us to prove isare its minimality. Suppose − is not minimum vertex cover. Then, V − S is not minimum vertex cover. Then, there is another vertex cover V − S where ty. Suppose emains for us to prove is its V V − − S is is not not minimum minimum vertex vertex cover. cover. Then, Then, there is is another another vertex vertex cov co minimality. minimality. Suppose Suppose Proof. Let us assume that V − S is not a VERTEX-COVER. Therefore, there are two A, B ∈ / V S the . there are two vertices A, B ∈ / V − another vertex cover V − S where minimum vertex cover. Then, there is another vertex cover V − S where |V |V − − S S | | < < |V |V − S|, S|, which which implies implies that that |S |S | | > > |S|. |S|. By By lemma lemma 2, 2, S S and there is an edge connecting A and B. Since A, B ∈ / V − S, we have A, B ∈ S. As A a and there is an edge connecting A and B. Since A, B ∈ / V − S, we have A, B ∈ S. As A and B V −minimum S is not minimum vertex cover. Then, there is|S|. another vertex cover VA, − S where ppose ySsimilar to the previous lemma. Let us assume that V − S not aedge INDEPENDENT-SET. Therefore, there two vertices A, B V − S and there is an edge connecting A and Therefore, Therefore, there there are two two vertices vertices A, A, B B ∈∈ V Vare − S Sedge and there there Therefore, is is− an an edge edge there connecting connecting are two A A and and B. A, Since Since B ∈set. VA, A, − B B ∈∈− and VVis − − ther S, S, |V − SB |are < |V − S|, which implies that |S |connecting > By lemma 2, S is an independent Sini V − is minimum cover. Then, there isthat another vertex cove minimality. Suppose |V − S |//B <1. |VThe − S|, which implies that |Sby | isan > |S|. By lemma 2, is an independent set. Therefore, S vertex ∈ |V S− |S < |V − S|, which implies that |S |vertices > |S|. By lemma 2, S an and re are two vertices A, ∈ V S there is an A and B. B V − S, is not vertex cover. Then, there is another vertex cover − SSince where and there is an connecting A and B. Since A, B /aTherefore, VS|S|. S, we S is not minimum vertex cover. Then, there is another cover VV − S we have A, B S. As A and B are connected by an edge, we note that S is not aisVVB. VERTEX-COVER. This |V |∈ < |V − S|, which implies |S |aconnected > By le and vertex ertex cover by lemma only thing that remains for us to prove is its we have A, ∈ S. As A B are connected edge, we note that S is not ais VERTEX-COVER. This ∈ − an S ∈ over. Then, there is another cover V − where we have A, B ∈ /S S. As A and B are connected by edge, we note that S is not aais VERTEX-COVER. there is another vertex cover not where , where which implies that cover and Theorem 1. If ⊆ V is a MAX-INDEPENDENT-SET of graph G(V, E), then − S is a MIN-VERTEX < |V − S|, which implies that |S | > |S|. By lemma 2, S is an independent set. Therefore, S not vertex V − S where |V |V − − S S | | < < |V |V − − S|, S|, which which implies implies that that |S |S | | > > |S|. |S|. By By lemma lemma 2, 2, S S an an independent independent set. set. The Th and there is an edge connecting A and B. Since A, B ∈ / V − S, we have A, B ∈ S. As A and B are an the S, we have A, B ∈ S. As A and B are connected dependent set. Therefore, is not a that |S | > |S|. By lemma 2, S is an independent set. Therefore, S is not a maximum maximum independent independent set. set. This This is is a a contradiction. contradiction. Therefore Therefore V V − − st prove the following two lemmas. by edge, we note that S is not an INDEPENDENT-SET. This is contradiction. Th Proof. The proof is actually similar to previous lemma. Let us assume that − S is not INDEPEND by an edge, we note that S is not an INDEPENDENT-SET. This is a contradiction. Therefore − S|, which implies that |S |we > |S|. By lemma Sby isan an independent set. Therefore, is not ertices A,A Band V S and there isB an edge Aedge, and A, Vnot − S, have A, B ∈ /connecting S. As A and BS are connected by an edge, we note that S Viscover. not aisTher VER we we have have A, A, B BB /− ∈ /cover. S. S. As As A A and and B− are are connected connected by an edge, we have we note note that that ∈ /is S. S S∈ is As is not not A and amaximum aSThis VERTEX-COVER. VERTEX-COVER. Ban are This by This isis edg aS aS maximum independent set. This iswe aimplies contradiction. Therefore VB S is minimum vertex |V − S < |V − S|, which that |S |∈ > |S|. By lemma 2, S is independent set. maximum independent set. This is2, avertices contradiction. Therefore V − S isthe the minimum vertex cover. ∈ are t∈ aS. VERTEX-COVER. Therefore, there two A, B /we VSince − SB maximum independent set. This a − contradiction. Therefore − S an the that ∈ /by As are connected by an edge, note that isB. not aA, VERTEX-COVER. This isaconnected aminimum implies that |S | > |S|. By lemma 2, S is an independent set. Therefore, S is not a by an edge, we note S is an INDEPENDENT-SET. This implies that |S | > |S|. 2, S is an independent set. Therefore, S is not a contradiction. Therefore V − S is an INDEPENDENT-SET. maximum independent set. is a contradiction. Ther minimum vertex Then, there is another vertex cover V − S where . By lemma 2, is an independent set. Therefore, is not a incontradiction. Therefore V S is an INDEPENDENT-SET. lemma 2, S is an independent set. Therefore, S is not a contradiction. Therefore V − S is an INDEPENDENT-SET. of the graph G(V, E). m independent set. This is a contradiction. Therefore V − S is the minimum vertex cover. nt set. Therefore, S is not a maximum maximum independent independent set. set. This This is is a a contradiction. contradiction. Therefore Therefore V V − − S S is is the the minimum vertex vertex co co an edge, we note that S is not an INDEPENDENT-SET. This is a contradiction. Therefore V − S is a T. This is a contradiction. Therefore V − S is a minimum vertex cover. a contradiction. Therefore Vedge, − SSSwe is the minimum vertex cover. VERTEX-COVER. Therefore, there are two vertices A, Band ∈ − Sminimum and there isTherefore ancover. edge A and B. vertex Since A, VERTEX-COVER. VER graph G(V, E), then V SisisVTherefore is an INDEPENDENT-SET of the This amaximum contradiction. V SE), the vertex and Bof are connected by an note that SThis is not athen VERTEX-COVER. This avertex Therefore − S isabove an−two INDEPENDENT-SET. contradiction. contradiction. Therefore Therefore Vcontradiction. V − − an an INDEPENDENT-SET. INDEPENDENT-SET. contradiction. S an me that Vis − isBy not aINDEPENDENT-SET. VERTEX-COVER. Therefore, are vertices A, conclude B ∈ /V− V− Sis independent set. isVisVathere contradiction. Therefore Visconnecting S− isthat the minimum covB B. Since B ∈ /isS Vis − S, we have A, S. As A− B are connected isset. − From From the the above theorem, we we conclude that athe aINDEPENDENT-S MIN-VERTEX-CO MIN-VERTEX-CO SThis ⊆ an INDEPENDENT-SET of graph G(V, V Stheorem, athe VERTEX-COVER ofeasily Therefore V −dependent is anminimum .endent This contradiction. Therefore −∈ S is the minimum vertex cover. set. This aVB contradiction. Therefore is is minimum cover. VERTEX-COVER. aaA, contradiction. Therefore − S is the minimum vertex cover. hat |SVis |V > |S|. lemma 2, SS. isis an independent set. Therefore, not a note herefore − SS the vertex cover. From the above theorem, we conclude that a MIN-VERTEX-COVER can be constructed if m vertex cover. From the above theorem, we conclude that a MIN-VERTEX-COVER can be easily constructed ifwc VERTEX-COVER. From the above theorem, we conclude that a MIN-VERTEX-COVER we have A, B ∈ / As A and B are connected by an edge, we that S is not a VERTEX-COVER Theorem 1.We Sknow ⊆ ishave aBVcontradiction. MAX-INDEPENDENT-SET of graph G(V, E), then − SifVconclude iswe acan MIN-VERTEX-COV From the above theorem, we ausconstru MIN-V − Sabove is an theorem, INDEPENDENT-SET. Theorem 1. IfIfwe S ⊆ VVSisthat is MAX-INDEPENDENT-SET graph E), then VVthen − S is aremains MIN-VERTEX-COV Theorem 1. Ifwe ⊆ is− MAX-INDEPENDENT-SET of graph G(V, E), − S isbe athat MIN-VERTE ea)an connecting AMIN-VERTEX-COVER and B. Since A, ∈ /V VSais − S, we have A, B by ∈V of S. As A and B are connected INDEPENDENT-SET. This aa2. Therefore −that S we is aG(V, Proof. V S is a vertex cover lemma 1. The only thing that for to pro the conclude that a MIN-VERTEX-COVER can be easily constructed have a From From the the above above theorem, theorem, we we conclude conclude that a a MIN-VERTEX-COVER MIN-VERTEX-COVER can be easily easily constru be easily constructed if a onclude that a can be easily constructed if have a MAX-INDEPENDENT-SET. MAX-INDEPENDENT-SET. Lemma If ⊆ V is a VERTEX-COVER of graph G(V, E), then V − S is an INDEPEN Lemma 2. If S ⊆ a VERTEX-COVER of graph G(V, E), then V − S is an INDEPENDENT contradiction. Therefore V − S is the minimum vertex cover. oveTheorem theorem, weIfthat that aabove MIN-VERTEX-COVER can beV easily constructed if we a E), Theorem 1. If graph S is ⊆can Vwe is a easily MAX-INDEPENDENT-SET then Vconstruc − Sthen iso Theorem 1. 1. Theorem 1. Ifconclude SScan ⊆ V V isiseasily aTherefore athe MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET of graph G(V, G(V, E), E), IfaififVERTEX-COVER Swe then then ⊆ have V VVisof − − a graph S MAX-INDEPENDENT-SET S isishave aaG(V, MIN-VERTEX-COVER MIN-VERTEX-COVER MAX-INDEPENDENT-SET. From conclude a Sis MIN-VERTEX-COVER can be easily MAX-INDEPENDENT-SET. MAX-INDEPENDENT-SET. contradiction. Vtheorem, − S an INDEPENDENT-SET. fm, ⊆ Vof MAX-INDEPENDENT-SET G(V, E), then − m, we conclude ahave MIN-VERTEX-COVER can be easily constructed 2. Ifgraph Sthat ⊆then V we conclude that a⊆ MIN-VERTEX-COVER be constructed of the graph G(V, E). MAX-INDEPENDENT-SET. the graph G(V, -VERTEX-COVER be constructed ifofLemma we aof of graph G(V, E). eSthat SVis2. isa−minimality. an INDEPENDENT-SET. This ishave a contradiction. Therefore V INDEPENDENT-SET −aaisS another is a of graph Vgraph −G(V, S Sof isisE), not minimum vertex cover. Then, there vertexG(V, cover V −S Suppose DEPENDENT-SET. sily constructed we aof MAX-INDEPENDENT-SET. MAX-INDEPENDENT-SET. Lemma Ifnot S1the ⊆an V is aE). VERTEX-COVER graph G(V, E), VisaG(V, − MIN-VERTEX-COVER SweE). ishave an ofE), the E), then S isif INDEPENDENT-SET of the graph G(V, E) graph G(V, E) previous lemma. Let us assume that V − not a INDEPENDENT-SET. NDENT-SET. MAX-INDEPENDENT-SET of graph then V − S is a MIN-VERTEX-COVER the G(V, E). of of the the graph graph G(V, G(V, E). E). of the graph MAX-INDEPENDENT-SET. We say that problem X is reducible to problem Y assume that VMIN-VERTEX-COVER S Therefore, arehave two2,vertices A,independent B∈ / V − S set. Therefore, S G(V, E).G(V, T. graph G(V, E)there T. is not a VERTEX-COVER. nclude that a Theorem can be easily constructed if we a SG(V, |V −−Sis |an < |V −If connecting S|, which that |S | >A, |S|. By lemma is an graph E) In In the the beginning beginning of of this this section, section, we we assume assume we know know that that MIN-V MIN-V 1. S ⊆ V is aimplies MAX-INDEPENDENT-SET ofS, graph E), then V we − S aus MIN-VERTE V edge − of SProof. and there edge and B. Since B ∈B V1. − Proof. We know that − Sthis is− aA vertex cover by lemma 1. The only thing that remains for us toisprove prove We know that VV − S is aan vertex cover by lemma The only thing that remains for to is Proof. We know that V S is a vertex cover by lemma 1. The only thing that remains for us to pis InProof. beginning of section, we assume we know that MIN-VERTEX-COVER is aisVaNP-hard probl Inthe the beginning of this section, we assume we know that MIN-VERTEX-COVER isis NP-hard prob VER graph G(V, E), then INDEPENDENT-SET of the In the beginning of this section, we assume we know that MIN-VERTE n connecting A and B. Since A, B ∈ / V − S, we have A, ∈ S. As A and B are connected Proof. The proof is actually similar to the previous lemma. Let us assume that − S not aits IN In the beginning of this section, we assume we know The proof is actually similar to the previous lemma. Let us assume that V − S not a INDEPE Proof. We know that V − S is a vertex cover by lemma 1. The only thing that rema Proof. Proof. Proof. We We know know that that V V − − S S is is a a vertex vertex cover cover by by lemma lemma 1. 1. The The We only only know thing thing that that that V − remains remains S is a vertex for for us us cover to to prove prove by lemm is is maximum independent set. This is a contradiction. Therefore V − S is the minimum vertex cover. e beginning of this section, we assume we know that MIN-VERTEX-COVER is a NP-hard problem. It is In In the the beginning beginning of of this this section, section, we we assume assume we we know know that that MIN-VERTEX-COVER MIN-VERTEX-COVER is is a a NP-h NP-h its X-COVER is a NP-hard problem. It is we assume we know that MIN-VERTEX-COVER is a NP-hard problem. It is good good to to know know as as many many NP-hard NP-hard problem problem as as possible. possible. This This is is necessary necessary of the graph G(V, E). ow that V − S is a vertex cover by lemma 1. The only thing that remains for us to prove is its nected by an edge, we note that S is not a VERTEX-COVER. This is a Proof. The proof isThis actually similar to the Let us ning this section, we assume weS know that MIN-VERTEX-COVER isisknow athat NP-hard problem. It is lemma. VINDEPENDENT-SET. − Sthere is− not minimum vertex cover. Then, there is another vertex cover SVassu wh minimality. Suppose V − is not vertex cover. Then, there is vertex V − S wh Suppose V Sare isminimum not minimum vertex cover. Then, there is another vertex cover − minimality. Suppose good to know as many NP-hard problem as This isthere necessary so that ifprevious encounter aA proble is aofminimality. VERTEX-COVER of graph G(V, E), then V − Swe isLet an INDEPENDENT-SET of the In the beginning of this section, assume we that MIN-VERTEX-COVER isnew a− NP-ha good know as many NP-hard problem as possible. necessary so that ifwe we encounter aV new prob good to know as NP-hard problem as possible. This iscover necessary so tha Proof. The proof isto actually similar to the previous lemma. us assume Vis − not aproblem INDEPENDENT-SET. us assume that V − S is not athere we note that S is not an INDEPENDENT-SET. This is ais contradiction. Therefore Vedge − Sthat is aifA Therefore, two A, B ∈ V − Swe and there is an connecting B. sV section, we assume we know that MIN-VERTEX-COVER is NP-hard problem. Itanother is Since section, we assume we know that MIN-VERTEX-COVER aaas NP-hard problem. It is good to know as many NP-hard problem as possible. This Therefore, two vertices A, B ∈ Vmany − S and is an edge connecting and B. A where w MIN-VERTEX-COVER is apossible. NP-hard problem. Itpossible. is − S aencounter vertex cover by lemma 1. The only thing that remains for us to prove is its V − Sany is not minimum cover. Then, there another minimality. Suppose V Vto − − S S is isare not not minimum minimum cover. cover. Then, Then, there there is another VS − S vertex vertex is not cover minimum cover VVis − − vertex Sit Sand where cov minimality. minimality. Suppose Suppose minimality. Suppose know many problem as This isvertices necessary so that iftwo encounter ais new X, we so R isthat aisas NP-hard problem. It is good to know know as as many many NP-hard NP-hard problem problem as possible. possible. This is isanother necessary so that if we we encounter encounter aver ano nS n is vertex vertex tblem if we aThis new problem X, we possible. is necessary so that ifthat we encounter a> new problem X, we can can use use of of the the NP-hard NP-hard problems problems that that we we know, know, reduce reduce it to to probl prob NP-hard vertex This good any necessary V not minimum vertex cover. Then, there is another vertex cover V − S where uppose DEPENDENT-SET. Therefore, there are vertices A, B ∈ V − S and there is an edge many NP-hard problem as possible. This is necessary so that if we encounter a new problem X, we |V − S | < |V − S|, which implies that |S | > |S|. By lemma 2, S is an independent set. Therefore, S is no |V − S | < |V − S|, which implies |S | > |S|. By lemma 2, S is an independent set. Therefore, S is |V − S | < |V − S|, which implies that |S | |S|. By lemma 2, S is an independent set. Therefore, can use any of the NP-hard problems that we know, reduce it to problem X, and thus prove that X is also good to know as many NP-hard problem as possible. This is necessary so that if we encounter a ne can use any of the NP-hard problems that we know, reduce it to problem X, and thus prove that X is also can use any of the NP-hard problems that we know, reduce it to problem X, From the above theorem, we conclude that a MIN-VERTEX-COVER can be easily constructed if w Therefore, there are two vertices A, B ∈ V − S and there is an edge connecting A and B. Since A, B ∈ V − S, n edge connecting A and B. Since A, B ∈ V − S, note VER. we have A, B ∈ / S. As A and B are connected by an edge, we note that S is not a VERTEX hard problem as possible. This is necessary so that if we encounter a new problem X, Proof. We know that V − S is a vertex cover by lemma 1. The only thing that remains for us to pS hard problem as possible. This is necessary so that if we encounter a new problem X, we can use any of the NP-hard problems that we know, reduc we have A, B ∈ / S. As A and B are connected by an edge, we that S is not a VERTEX-COV we assume we know that MIN-VERTEX-COVER is a NP-hard problem. It is his is necessary so that if we encounter a new problem X, we S is not minimum vertex cover. Then, there is another vertex cover V − S where − S | < |V − S|, which implies that |S | > |S|. By lemma 2, S is an independent s |V |V − − S S | | < < |V |V − − S|, S|, which which implies implies that that |S |S | | > > |S|. |S|. By By lemma lemma |V − S 2, 2, | S < S |V is is an an − S|, independent independent which implies set. set. Therefore, that Therefore, |S | > S S |S|. is is not not By a le a ny of the NP-hard problems that we know, reduce it to problem X, and thus prove that X is also NP-hard. |V counter a new problem X, we can can use use any any of of the the NP-hard NP-hard problems problems that that we we know, know, reduce reduce it it to to problem problem X, X, and and thus thus prove prove that that previous lemma. Let us assume that V − S is not a INDEPENDENT-SET. and thus prove that X is also NP-hard. ms that we know, reduce it to problem X, and thus prove that X is also NP-hard. 1contradiction. 1have − S|, which that |S | know, > |S|. By 2, S isedge, an independent SNP-hard. isYYX, not we A, B ∈ /problem S. As and B connected byaan edge, weisthat note NP-hard problems that we reduce to problem X,that and thus prove Xare is also maximum independent set. This islemma contradiction. Therefore VXA − Sthat isTherefore, the vertex cover. maximum independent set. This is aait contradiction. Therefore VX − S the minimum vertex cover. maximum independent set. is aV Therefore Vis − Sto is theis minimum vertex cover. We We say say that problem isset. reducible reducible to to problem problem can use any of the NP-hard problems we know, reduce it problem and thus prove X 11 1not MAX-INDEPENDENT-SET. we have A, Bimplies /we S. As A and BTherefore connected by we note that S is not aminimum VERTEX-COVER. This aV − note that S is∈ aand VERTEX-COVER. contradiction. Therefore − SINDEPENDENT-SET. is an INDEPENDENT-SET. dehe problems that we know, reduce to problem X, and thus prove that X also NP-hard. − S is1− not minimum vertex cover. Then, there another vertex cover minimality. Suppose We say that problem X is reducible to problem Yathat problems that know, reduce ititare to problem X, and thus that X isisis also NP-hard. We say problem X is reducible to problem Y contradiction. VThis Sis isaNP-hard. an lem possible. This isthat necessary so that ifThis we encounter new problem X, we We say that problem XV is reducible to problem Yprove uce itasto problem X, thus prove that X is also 90 J.I. Gunawan From the above theorem, we conclude that a MIN-VERTEX-COVER can be easily constructed if we have a MAX-INDEPENDENT-SET. In the beginning of this section, we assume we know that MIN-VERTEX-COVER is a NP-hard problem. It is good to know as many NP-hard problem as possible. This is necessary so that if we encounter a new problem X , we can use any of the NP-hard problems that we know, reduce it to problem X , and thus prove that X is also NPhard. 3. How to Proceed Suppose we already know that a problem is unsolvable (i.e. any known algorithm will not solve this problem in time). In competition, it is impossible to complain that “This is unsolvable, can you eliminate this problem?” to the judges, since the judges believe How How to to proceed proceed they have a solution. Such a request is absurd when there are already several contestants have that problem. Also,this in aproblem major competition (e.g. ACM International any algorithm will in s unsolvable unsolvable (i.e. (i.e. who any known knownsolved algorithm will not not solve solve this problem in Collegiate Programming Contest World Finals, IOI), it is unlikely that the judges have omplain that complain that "This "This isis unsolvable, unsolvable, can can you you eliminate eliminate this this problem?" problem?" incorrect solution. yy have have aa solution. solution. Such Such aa request request isis absurd absurd when when there there are are already already blem. Also, oblem. Also, inin aa major major competition competition (e.g. (e.g. ACM ACM International International Collegiate Collegiate How to isis unlikely unlikely that that the the judges judges have have incorrect incorrect solution. solution. 3 3.1. Approximation proceed Suppose we already know that a problem is unsolvable (i.e. any known algorithm will not solve this pro time).InInreal competition, it iscannot impossible to optimal complainsolution, that "This is unsolvable, can solution you eliminate this pr life, when we find the we can try to find the to can thethat judges, since the judges believe they a solution. request is absurd try to find the solution that isis close to the optimal all solution, solution, we we can try toclose find thethe solution that close to have the optimal is to optimal solution. More specifically, we Such try to afind a solution that iswhen there are several contestants who have solved problem. Also, insolution a major for competition (e.g. ACM isis not larger αα (where αα > 1) the optimal not than (where a minimisation prob-International C a solution solution that that not larger than than (where >that 1)) times times theoptimal optimal lem. The Contest mostalgorithm common Ithat found textbooks the 2-approxProgramming World approximation it algorithm is unlikely theinjudges haveisincorrect solution. most approximation IFinals, in isis the most common common approximation algorithm I found foundIOI), in textbooks textbooks the MIN-VERTEX-COVER problem, which means that the algorithm will not blem, that algorithm more twice blem, which which means meansimation that the the algorithm will will not not choose choose more than than twice choose more than twice the number of3.1 vertices than the optimal solution. However, apution. problems rarely occur in competitive lution. However, However, approximation approximation problems rarely occur in competitive Approximation proximation problems rarely occur in competitive programming (especially IOI). One eason isis because reason because to to create create this this kind kind of of problem, problem, the the judges judges have have to to In real life, when we cannot find the optimal solution, we can try to find the solution of the reason is because to create this kind of problem, the judges have to knowthat theis close to the y that that the the contestant’s contestant’s solution solution isis indeed indeed α-approximation. α-approximation. However, However, solution. More specifically, we try to find a solution that is not larger than α (where α > 1) times the optimal solution in order to verify that the contestant’s solution is indeed -approximaee (or (or takes takes aa long long time). time). Since Since this this approach approach isis not not really really suitable suitable for for tion. generating the optimal solution is impossible (or takes a long time). solution forHowever, a minimisation problem. The most common approximation algorithm I found in textbook this in this approach approach in detail. detail. Since this approach is not really suitable forwhich competitive I willwill notnot dis-choose more th 2-approximation MIN-VERTEX-COVER problem, means programming, that the algorithm cuss this in detail. the number of approach vertices than the optimal solution. However, approximation problems rarely occur in com 3.2 3.2 Pruning Pruning programming (especially IOI). One of the reason is because to create this kind of problem, the judges know the optimal solution in order to verifyProgramming that the contestant’s solution is indeed α-approximation. H programming problems. In International Collegiate programming problems. In ACM ACM International Collegiate Programming 3.2. Pruning the optimal solution isto impossible takes aof m on the count number m II (Robots (Robotsgenerating on Ice) Ice) required required the contestant contestant to count the the(or number oflong time). Since this approach is not really sui I will n.d.), not discuss approach ICPC Finals problem which isis known to ICPC World Worldcompetitive Finals 2010 2010programming, problem statement statement n.d.), whichthis known to in detail. ossible the isis to prune ossible paths paths isis impossible, impossible, the solution solution for this problem problem toprogramming prune This approach is usefulfor in this some competitive problems. In ACM International Collegiate Programming Contestn.d.). (ICPC) World Finals ICPC World 2010 If at lll possible ICPC World Finals Finals 2010 Solutions Solutions n.d.). If at possible paths paths (ACM (ACM 3.2 Pruning 2010, problem I (Robots on Ice) points, required thewe contestant tothe count theand number of Hamiltonian Paths with visit unvisited then can path visit the the rest rest of of the the unvisited points, then we can prune prune the path and This approach is useful in some competitive programming ACMwhich International Collegiate Prog constraints (ACM ICPC World Finals 2010 problem statement,Inn.d.), is known ery suitable very suitable for for IOI. IOI. Usually, Usually, IOI IOI problems problems require require deep deep analysis analysis from fromproblems. Contest (ICPC) World Finals 2010, problem I (Robots on Ice) required the contestant to count the nu to be a NP-hard problem. While finding all possible paths is impossible, the solution cepted by ccepted by only only "hacking" "hacking" aa complete complete search search algorithm. algorithm. Therefore, Therefore, we we Hamiltonian Paths with constraints (ACM ICPC World Finals 2010 problem statement n.d.), which is k be a NP-hard problem. While finding all possible paths is impossible, the solution for this problem is the exponential algorithm we use to find all possible paths (ACM ICPC World Finals 2010 Solutions n.d nding nding Small Small Constraints Constraints some point we know that it is impossible to visit the rest of the unvisited points, then we can prune the p backtrack immediately. However, it is not(e.g. very N suitable for IOI. Usually, IOI problems require deep analy hh large isis impossible to exponentially large N N that that impossible to solve solve exponentially (e.g. N> > 50). 50). .1 .1 Approximation Approximation 1) theto optimal tion. However, approximation problems rarely occur injudges competitive intimes isthe the isthis because create this kind of problem, the judges have to know the optimal solution in order verify that the solution isinco in know the solution to verify that the contestant’s solution issolution indeed α-approximation. Howev nd oftextbooks problem, judges have to In real life, when we cannot find the optimal solution, we try toto find the that istime). to the optim ming Contest World Finals, IOI), itin isorder Programming unlikely that the Contest World have Finals, incorrect IOI), solution. it(or is unlikely thatfor the judges have generating the optimal solution impossible (or takes acan long time). Since this approach isclose not really suitabl generating the optimal solution is impossible takes acontestant’s long Since this ap deed α-approximation. However, optimal solution is impossible (or takes long time). Since this approach is not really suitable approach isoptimal not really suitable for competitive programming, Iaiswill not discuss this approach in detail. in textbooks is the ason is because to create this kind of problem, the judges have to oose more than twice the contestant’s solution is indeed α-approximation. However, generating the optimal solution is impossible (or takes a long time). Since this af generating the optimal solution is impossible (or takes a long time). Since this approach is not really suitable ndeed α-approximation. However, solution. More specifically, we try to find a solution that is not larger than α (where α > 1) times the optim competitive I will notindiscuss this approach competitive programming, I 3.1 will in notdetail. discuss this approach in detail. approach is Inot suitablethis forapproach gramming, willreally not programming, discuss detail. Approximation oose more than twice that the contestant’s solution is indeed α-approximation. However, occur in competitive akes a long time). Since this approach is not really suitable for competitive willdetail. not discussalgorithm this approach in detail. competitive I problem. will not discuss this approach approach is not suitable for solution for really aprogramming, minimisation The programming, most commonI in approximation I found in textbooks is th 3.1 Approximation 3.1 Approximation 3.2 Pruning occur in in competitive adetail. long Since approach isproblem, not really suitable for ,(or thetakes judges havetime). toInMIN-VERTEX-COVER real life,this when we Understanding cannot find the optimal solution, we can try to find the solution is twic clos pproach 2-approximation which means that the algorithm will not choose than Unsolvable Problem 91 morethat 3.2 Pruning 3.2 Pruning 3.2 solution, Pruning ,his judges have to , the when we cannot find the optimal In real life, we when can try we to cannot find the find solution the optimal that is solution, close to we the can optimal try to find the sol approach in detail. oximation. However, solution. More specifically, we try to find a solution that is not larger than α (where α > 1) ti the number of vertices than the optimal solution. However, approximation problems rarely occur in competitiv This approach is useful in some competitive problems. In ACM 3.2 International PruningCollegiate Prog 3.2programming Pruning oximation. However, More specifically, we try to find a solution solution. that More is not specifically, larger than we α try (where to find α a > solution 1) times that the is optimal not larger than α not really suitable for solution for a minimisation problem. The most common approximation algorithm I found in This approach is useful in some competitive programming problems. In ACM International Collegiate Programm This approach useful in some competitive programming problems. In ACM Intern useful in some competitive programming problems. In ACM International Collegiate Programming for this problem is to prune the exponential we use findkind all possible pathsthe programming (especially IOI). One of the reason this of contestant problem, havenut( M Collegiate Programming Contest (ICPC) World Finals 2010, problemis algorithm Ibecause (Robotsto oncreate Ice)torequired the to judges count the 2 International Pruning This approach is useful in some competitive programming problems. In ACM Inte This approach is useful in some competitive programming problems. In ACM International Collegiate Programmi not really suitable for or a minimisation problem. The most solution common for a approximation minimisation algorithm problem. The I found most in common textbooks approximation is the algor 2-approximation MIN-VERTEX-COVER problem, which means that the algorithm will not choose Contest (ICPC) World 2010, problem I the (Robots on required the contestant count the numb Contest (ICPC) World Finals 2010, problem Iproblem (Robots on Ice) the cont rnational Collegiate Programming (ACM ICPC World 2010 Solutions. n.d.). If atIce) some we know that it isrequired World Finals 2010, problem I Finals (Robots on Ice) required the contestant topoint count the number ofto know the optimal solution in Finals order to verify that contestant’s solution is indeed α-approximation. Howeve he contestant to count the number of 3.2 Pruning Hamiltonian Paths with constraints (ACM ICPC World Finals 2010 statement n.d.), which is k mming problems. In ACM International Collegiate Programming Contest (ICPC) World Finals 2010, problem I (Robots on Ice) required the con Contest (ICPC) World Finals 2010, problem I (Robots on Ice) required the contestant to count the number ternational Collegiate Programming mation MIN-VERTEX-COVER problem, 2-approximation which means that MIN-VERTEX-COVER the algorithm will not problem, choose which more means than twice that algorithm the number of vertices than the optimal solution. However, approximation problems rarely occu impossible to visit the rest of the unvisited points, then we can prune the path and Hamiltonian Paths with constraints (ACM ICPC World Finals 2010 problem statement n.d.), which is know Hamiltonian Paths with constraints (ACM ICPC World Finals 2010 problem state ntestant to count the number of thsstatement with constraints (ACM ICPC World Finals 2010 problem statement n.d.), which is known to generating the optimal solution is impossible (or takes a long time). Since this approach is not really suitable em n.d.), which is known to be a NP-hard problem. While finding all possible paths is impossible, the solution for this problem isf rogramming problems. In ACM International Collegiate Programming obots on Ice) required the contestant to count the number of Hamiltonian Paths with constraints (ACM ICPC World 2010 problem sta Hamiltonian Paths with constraints (ACM ICPC Finals 2010 problem statement n.d.), which is known to count the number er of competitive vertices than the optimal solution. the number However, approximation vertices than problems optimal rarely solution. occur inproblems competitive approximation prob backtrack immediately. itof ispossible not very suitable for IOI. Usually, IOI programming (especially IOI). One of the reason is(ACM because to create this kind of Solutions problem, thp be athe NP-hard While finding all paths is impossible, the solution for this problem issolutio to be aHowever, NP-hard problem. While finding all possible paths isFinals impossible, the tement n.d.), which isproblem. known to roblem. While finding all possible paths isuse impossible, the solution this problem isHowever, to prune programming, Iof will not discuss this approach inthe detail. eontestant solution for this problem isalgorithm to prune ICPC World Finals 2010 n.d exponential we to find allWorld possible paths I (Robots on Ice) required the contestant to count the number of World Finals 2010 problem statement n.d.), which is known to be a NP-hard problem. While finding all possible paths is impossible, the solu be a NP-hard problem. While finding all possible paths is impossible, the solution for this problem is to pru tatement n.d.), which is known to require deep analysis from the contestant. It is rare that we can get Accepted by only ming (especially IOI). One of the reason programming is because (especially to create this IOI). kind One of of problem, the reason the is judges because have to to create this kind know the optimal solution in order to verify that the contestant’s solution is indeed α-approxim ICPC World Finals 2010 Solutions n.d.). the exponential algorithm we use to find all possible paths (ACM ICPC World the exponential algorithm we use to find all possible paths (ACM tion for thiswe problem is we toall prune World Solutionspoints, n.d.). If at we can prune theFip algorithm usepoint to find possible (ACM ICPC World Finals 2010 Solutions n.d.). If atitpaths some know that is impossible to visit the Finals rest of2010 the unvisited then CPC World Finals 2010 problem statement n.d.), which is known to legiate Programming paths is impossible, the solution for this problem is to prune ICPC World the exponential algorithm we use to find all possible paths (ACM ICPC World Finals 2010 Solutions n.d.). the exponential algorithm we use to find all possible paths (ACM ution for this problem is to prune “hacking” a complete search algorithm. Therefore, we will not discuss this technique optimal solution in prune order that know the contestant’s solution solution isorder indeed tocan that the contestant’s solution is Ifintr α-approximation. However, generating thethe optimal solution is impossible (or takes averify long time). Since this approach is analy not some we know that itsome is impossible to visit the of the unvisited then we can prune the path point we know that itrest isinimpossible to visitpoints, the rest ofand the unvisited points, Finals 2010 Solutions n.d.). Ifverify at know that it backtrack ispoint impossible to rest ofthe the unvisited points, then we prune the path points, then we can thevisit path and immediately. However, itoptimal is not very suitable for IOI. Usually, IOI problems require deep 3.2 Pruning legiate Programming ssible paths is impossible, the solution for this problem is to prune count the number of ICPC World Finals 2010 Solutions n.d.). If at ble paths (ACM some point we know that it is impossible to visit the rest of the unvisited points, in detail. some point we know that it is impossible to visit the rest of the unvisited points, then we can prune the path d Finals 2010 Solutions n.d.). If at g then the optimal solution impossible (or generating takes acan the optimal time). Since solution this is approach impossible (or takes reallyfor asuitable long time). fordeep Since thisa competitive programming, Ilong will not discuss this approach inisIOI detail. immediately. However, it IOI. isimmediately. not very suitable for IOI. Usually, problems require analysis backtrack However, it is not very suitable IOI. Usually, IOI probl webacktrack canthe prune the path ediately. However, it deep isisnot very for Usually, IOI problems require deep analysis from OI problems require analysis from contestant. Itand is suitable rare that we get Accepted by only "hacking" anot complete search algorithm. There count the number of ICPC World Finals 2010 Solutions n.d.). If at possible paths (ACM ), which is known to he rest of the unvisited points, then we can prune the path and backtrack immediately. However, it get is not very suitable for Usually, IOI pro backtrack immediately. However, itcan is not very for IOI. Usually, problems require deep analysis fros s, then we can prune the path and This approach is useful in some programming problems. In ACM International Collegiate ve Ican will not this competitive approach in programming, I we will not discuss this approach inIOI. detail. the contestant. ItTherefore, isdiscuss rare that we get Accepted by only "hacking" aIOI complete search algorithm. Therefore the contestant. Itdetail. issuitable that can Accepted by only "hacking" aProgrammin complete blems require deep analysis from It programming, is rare that we get Accepted by only arare complete search algorithm. Therefore, we mplete search algorithm. we will not discuss this technique in"hacking" detail. ), which is known to isit the rest of the unvisited points, then we can prune the path and problem is to prune itable for IOI. Usually, IOI problems require deep analysis from the contestant. It is rare that we can get Accepted by only "hacking" a complete the contestant. It is rare that we can get Accepted by only "hacking" a complete search algorithm. Therefore, w roblems require deep analysis from Contest (ICPC) World Finals 2010, problem I (Robots on Ice) required the contestant to count the number o will notindiscuss this technique in detail. discuss this technique in 3.2 detail. Pruning ethis search algorithm. Therefore, we will not technique detail. 3.3. Finding Small problem is todiscuss prune ry for IOI. Usually, IOIconstraints problems require deep fromin2010 n.d.). If Paths at dSolutions bysuitable only a Therefore, complete search algorithm. Therefore, weFinals will not discuss thisanalysis technique detail. will "hacking" not this technique in3.2 detail. te search algorithm. weConstraints Hamiltonian with (ACM ICPC World problem statement n.d.), which is known t Pruning 3.2 Pruning 3.3 Finding Small Constraints n.d.). Ifand atproblem. epted bythe "hacking" complete Therefore, we nSolutions prune path This aapproach useful algorithm. inall some competitive problems. In for ACM Collegia be aonly NP-hard Whileis search finding possible paths isprogramming impossible, the solution thisInternational problem is to prun 3.3 Finding Small Constraints 3.3 Finding Small Constraints 3.3 Finding Small Constraints ints noach prune the path and is useful in some competitive programming This approach problems. is useful In in ACM some International competitive Collegiate programming Programming problems. In ACM Inte e deep fromContest (ICPC) World Finals 2010, problem I (Robots on Ice) required the contestant to coun ICPC World Finals 2010 Solutions n.d.). IfNa theanalysis exponential algorithm we use to find all possible paths (ACM Suppose there an NP-hard problem with large N that is impossible to solve exponentially (e.g. Suppose thereisis an NP-hard problem large that is impossible to solve expo3.3 Finding Small Constraints 3.3 Finding Small Constraints e deep analysis from ICPC) World Finals 2010, problem I Contest (Robots (ICPC) on Ice) World required Finals the 2010, contestant problem to count I (Robots the number on Ice) required of the co rithm. Therefore, we Hamiltonian Paths with constraints (ACM ICPC World Finals 2010 problem statement n.d.), w Suppose there is an NP-hard problem with large N that is impossible to solve exponentially (e.g. N > Suppose there is an NP-hard problem with large N that is impossible to solve is an NP-hard problem with large N that is impossible to solve exponentially (e.g. N > 50). some point we know that it is impossible to visit the rest of the unvisited points, then we can prune the path an o solve exponentially (e.g. N > 50). nentially we (e.g. Sometimes should also look formay other small Sometimes should also ).look for otherwe small constraints that help. Forconstraints example, a SUBSET-SUM gs Small Constraints Suppose there is an NP-hard problem with large N that is impossible to solv Suppose there is an NP-hard problem with large N that is impossible to solve exponentially (e.g. N > rithm. Therefore, we an Paths with constraints (ACM Hamiltonian Paths with constraints (ACM ICPC World Finals 2010 problem statement n.d.), ICPC which World is Finals known 2010 to problem sta be a NP-hard problem. While finding all possible paths is impossible, the solution for this Sometimes we should also look for other small constraints that may help. For example, a SUBSET-SUM pro Sometimes we should also look for other small constraints that may help. For exam ve exponentially (e.g. N > 50). hould also look for other small constraints that may help. For example, a SUBSET-SUM problem backtrack immediately. However, it isa SUBSET-SUM notand verywill suitable for IOI.isUsually, problems fro5 For example, SUBSET-SUM problem may help. For example, problem considered an NP-hard probding Small Constraints isathat considered an NP-hard problem, not be solvable with NIOI = 100. Whenrequire we aredeep givenanalysis the constr N that is impossible to solve exponentially (e.g. N > 50). Sometimes we should also look for other small constraints that may help. For exw Sometimes we should also look for other small constraints that may help. For example, a SUBSET-SUM proble olve exponentially (e.g. N > 50). 2 hard problem. While finding all possible be a paths NP-hard is impossible, problem. While the solution finding for all this possible problem paths is is to impossible, prune the solu ICPC World Finals 2010 Solu the exponential algorithm we use to find all possible paths (ACM considered anwill NP-hard and will not100. be N 100. When we are given constraint isthat considered an NP-hard problem, and will not solvable with =the 100. When ample, aiscontestant. SUBSET-SUM problem NP-hard problem, and will not beproblem, solvable with Nsmall = When wewith are given thebe constraint that not be solvable with . solvable When we are given the constraint allNusing thewe It is rare that we can get Accepted by only a=problem complete search algorithm. Therefore, When are given constraint alllem, the and elements inside the array are (e.g. [0, "hacking" 100]), this can be that solved O(N X )w D large N that is impossible to solve exponentially (e.g. N > 50). 2 straints that may help. For example, a SUBSET-SUM problem 2 is considered an NP-hard problem, and will not be solvable with N = 100. When is considered an NP-hard problem, and will not be solvable with N = 100. When we are given the constraint th 2 example, a SUBSET-SUM problem ICPC World Finals 2010 Solutions n.d.). If at ICPC World ential algorithm we use to find all possible the exponential paths (ACM algorithm we use to find all possible paths (ACM some point we know that it is impossible to visit the rest of the unvisited points, then we can pru all the elements inside the array are small (e.g. [0, 100]), this problem can be solved using O(N X ) Dyna all the elements inside the array are small (e.g. [0, 100]), this problem can be so nsan we given the constraint that the elements inside the array are small (e.g. ), this problem can be solved using inside the array are small (e.g. [0, 100]), this problem can be solved using O(N X ) Dynamic will not discuss this technique in detail. beare solved using O(N X ) Dynamic Programming, where X is the upper bound of the elements inside the array. Even though the running tim 2 can be lltsolvable constraints that example, arest SUBSET-SUM problem with Nupper 100. When we are given the constraint that 2 where all thepoint elements array are small (e.g. [0, 100]), this problem all the elements the array are small (e.g. [0, this problem can solved using O(N Xconstraint. ) Dynam en weknow are given the constraint that we that it=may isX impossible to visit some the of we the know unvisited itvery points, is impossible then we to can visit prune the rest the of path the and unvisited points backtrack immediately. However, it not suitable for IOI. Usually, IOI problems require de Programming, X isof the upper bound ofinside the elements inside array. Even though the running time o Programming, where Xisthat is the bound of thebe elements inside the array. Even help. Dynamic Programming, where 100]), isthe the upper bound of the elements inside solved using O(N )inside Dynamic where X is the bound ofFor the elements inside array. Even though thestill running time offor the y. Even though the running time the algorithm is exponential to the size of the input, the algorithm is fast enough the given 2 constraint that 2can ot be solvable with N = 100. When we are given the ally (e.g. N > 50). 0, 100]), this problem be solved using O(N X ) Dynamic Programming, where X is the upper bound of the elements inside the array. Eve Programming, where X is the upper bound of the elements inside the array. Even though the running time of e solved using O(N X ) Dynamic immediately. However, it is not very backtrack suitable for immediately. IOI. Usually, However, IOI problems it is not require very suitable deep analysis for IOI. from Usually, IOI pro the array. Even though the running time of the algorithm is exponential to the size of the contestant. It is rare that we can get Accepted by only "hacking" a complete search algorithm algorithm is exponential to the size of the input, the algorithm is still fast enough for the given constraint. Ano algorithm is exponential to the size of the input, the algorithm is still fast enough fo n though the running time of the onential size the this input, the algorithm is still enough the too given constraint. nough forto the given constraint. Another way to of apply technique is when the fast value of N for is Constraints not large (e.g. NAnother < 40). For example, whilt 3.3 Finding 2 Small ally (e.g. N > 50). e.g. [0, 100]), this problem can be solved using O(N X ) Dynamic BSET-SUM problem elements inside the array. Even though the running time of the N"hacking" algorithm is exponential to the size of the input, the algorithm still fast enough algorithm is exponential to the size of the input, the algorithm is still fast enough for the constraint. Anoth N ven though the running time of the the input, the algorithm is still fast enough for the given constraint. Another way N/2 stant. It is rare that we can get Accepted the contestant. by only "hacking" It is rare a that complete we can search get Accepted algorithm. by Therefore, only we) (e.g. a complete will discuss technique inin detail. way to apply this technique isis)to when therun value of Nsecond, tooFor large <isuse 40). For example, while O4 way apply this technique isnot when the value ofNN not too large N < the givenalgorithm Another isfor isconstraint. when the value of Nthis not too large (e.g. Nis < 40). example, while O(2 )tois Ntechnique < 40). For example, while O(2 fornot N = 36 is unlikely to one we can, for(e.g. instance, agiven O(2 Meet In The BSET-SUM problem f the elements inside the array. Even though the running time of the N/2 n the constraint that e algorithm is still fast enough for the given constraint. Another N N/2 way to apply this technique is when the value of N is not too large (e.g. N <a way to apply this technique is when the value of N is not too large (e.g. N < 40). For example, while O(2 N/2 hscuss for the given constraint. Another there is an NP-hard problem with large N that is impossible to solve exponentially (e.g. N > 50 apply this technique is when the of is not too large (e.g. ). For exN/2 this technique in detail. will not discuss this technique in detail. for N = 36 is unlikely to run in one second, we can, for instance, use a O(2 ) Meet In The M algorithm for N = 36 is unlikely to run in one second, we can, for instance, use <ce, 40). For example, while O(2 ) = 36Suppose is unlikely to run in one second, we can, for instance, use a O(2 ) Meet In The Middle use aalgorithm O(2 ) Meet In The Middle for solving a problem like SUBSET-SUM. While O(2 ) is still exponential to N , it is much fas 2 algorithm N N/2 N n the constraint that the algorithm is still fast enough for the given constraint. Another N/2 N/2 geut, O(N X ) Dynamic N is not too large (e.g. N < 40). For example, while O(2 ) N/2 N/2 algorithm for = unlikely to one can, instance, use ample, while While algorithm for isis unlikely to run run in second, we can, for = 36 isa unlikely run one second, we can, for instance, use aa O(2 )solution. In The Midd < For)to example, while O(2 )than Sometimes also look for other small constraints that For example, athan proble N NSUBSET-SUM algorithm solving problem like SUBSET-SUM. While O(2 )help. still exponential to ,Meet much faster algorithm for solving a36problem likemay SUBSET-SUM. While O(2 )itfor isis still exponent a 40). O(2 Meet InN The Middle lving aalgorithm problem like SUBSET-SUM. O(2 )Nissolve still exponential to N ,isof itin isN much faster xponential N ,we itfor isshould much faster Nto that itin can is twice the range using O(2 )N 3.3 Finding Small Constraints 2N/2O(2 ), and the range of N/2 N N/2 N/2 gese O(N X ) Dynamic ue of N is not too large (e.g. N < 40). For example, while O(2 ) N N N and running time of the ond, we can, for instance, a O(2 ) Meet The Middle N for use a Meet In The Middle algorithm for solving a problem like algorithm for solving a problem like SUBSET-SUM. While O(2 ) is still expone algorithm for solving a problem like SUBSET-SUM. While O(2 ) is still exponential to N , it is much faster thN N a O(2 ) Meet In The Middle is considered an NP-hard problem, will not be solvable with N = 100. When we are given the constraint tha ), the range oftwice NO(2 that canthe solve isusing twice range of solve N Finding using a O(2 )range solution. and of N that can is twice the of N using a O(2 toofO(2 N)N ,solution. itthat is and much faster than range it can solve isFinding the),itrange of range NConstraints a the O(2 )it solution. gntial a O(2 3.3 Small 3.3 Small Constraints N/2 N/2 Nit N Nfaster 2 running time of the second, we can, for instance, use a O(2 ) Meet In The Middle ne(2 constraint. Another Suppose there is an NP-hard problem with large N that is impossible to solve exponentially SUBSET-SUM. While is still exponential to , it is much than .eWhile O(2 ) is still exponential to N , is much faster than N O(2 ), and the range of N that it can solve is twice the range of N using a O( O(2 ), and the range of N that it can solve is twice the range of N using a O(2 ) solution. nential to N , it is much faster than all the elements inside the array are small (e.g. [0, 100]), this problem can be solved using O(N X ) Dynam ) solution. N/2 3.4 Finding Special Cases N N nthere constraint. Another isWhile an NP-hard large Suppose isimpossible an NP-hard to solve problem exponentially with large (e.g. N N is>a impossible 50). time toofsol range of toN that itmuch can solve isinside twice the range of though that using SUM. O(2 ), problem isand still exponential N that , there it is faster than ample, while O(2 )where Sometimes we should also look for other small constraints that may help. For example, a SUBSE ice the range of NN using aXthe O(2 ) solution. O(2 )Programming, solution. iswith the upper bound ofis the elements the array. Even the running th 3.4 Finding Special Cases 3.4 Finding Special Cases 3.4 Finding Special Cases es N solution. N ample, while O(2 ) sMeet should also look for other small Sometimes constraints we that should may help. also look For for example, other small a SUBSET-SUM constraints that problem may help. For ex iswe twice the range of N using a O(2 ) solution. In TheThis Middle is considered an size NP-hard and will not be solvable with N = 100. When we are given th algorithm is is exponential the of 3.4 theproblem, input, the algorithm is still fast enough for the given constraint. Anoth the most to suitable approach inFinding IOI, and thus is the main focus of this paper. To solve IOI 200 Finding Special Cases Special 3.4 Cases In The Middle red an NP-hard problem, and willIsland not isinside be considered solvable with an NP-hard NNapproach. = 100. When and we are willfind given not be the solvable constraint with N = 100. When tMeet issuitable much faster than all the elements the array are small (e.g. [0, 100]), this problem can bethat solved using O( This is the most suitable approach in IOI, and thus isproblem, the main focus of paper. To solve 2008 IsN This isthe the most suitable approach in IOI, and thus is the main focus of this pa ting approach in IOI IOI, and thus is main focus of paper. To solve 2008 Island way to apply this technique is the value of isthis not too large (e.g. NIOI < 40). For example, while O(2 this paper. To solve 2008 and IOI 2014 Friend, wewhen need to use this We must athis special constraint inIOI the probl Special Cases 2 This isin the most suitable approach inthis IOI, and thus main focus ofcan this N/2 This issolve the most suitable approach IOI, and thus isthe the main focus of this paper. To solve IOI 2008 Isla tpaper. is much faster than ments inside the array are small (e.g. allto the [0, 100]), elements this inside problem can array be are solved small (e.g. O(N [0, 100]), Xis )the Dynamic problem be n. Programming, where X is upper of the elements inside array. Even though the run and IOI 2014 we need to use this approach. We must find athe special constraint in the problem and IOI 2014 Friend, we need to use approach. We must find special c To IOI 2008 Island Friend, we need to use this approach. We must find a bound special constraint inusing problem such algorithm for N =Friend, 36 is unlikely run inthe one second, we can, for instance, use athe O(2 )this Meet InaThe Midd pecial constraint in the problem such Finding Special Cases that this constraint allows the problem to be solvable in polynomial time. We can check whether an ad hus is the main focus of this paper. To solve IOI 2008 Island and IOI 2014 Friend, we need to use this approach. We must find a special N/2 and IOI 2014 Friend, we need to use this approach. We must find a special constraint in the problem su s.aint paper. To solve IOI 2008 Island n. ming, where X is the upper bound of Programming, the elements inside where the X array. is the Even upper though bound the of the running elements time inside of the the array. Eve algorithm is exponential to the size of the input, the algorithm is still fast enough for the given con that this constraint allows the problem to be solvable in polynomial time. We can check whether an additi that this constraint allows the problem to be solvable in polynomial time. We ca constraint in the problem such the problem toan solvable polynomial time. WeO(2 can check whether an additional algorithm for solving a be problem likeinSUBSET-SUM. While ) is still exponential to N , it is much faster tha Weallows can check whether additional nd thus theinto main focus of this paper. Tothe solve IOI 2008 Island ach. WeisNmust find asize special constraint in problem such that this constraint allows the size problem togiven be solvable in polynomial time. We N algorithm that this constraint the problem to be solvable invalue polynomial time. can check an addition al constraint the problem is exponential the ofallows thesuch input, algorithm the algorithm is exponential istwice still fast to enough for of input, constraint. the Another is enough way to apply this technique is the ofofN not too large Nwhether < still 40).fast For examp can check whether an additional O(2 ), and the range of N that it can solve iswhen the range Nisthe using aWe O(2 ) (e.g. solution. N N/2 pproach. We must find a special constraint in the problem such able in polynomial time. We can check whether an additional eply canthis check whether an additional technique isalgorithm when thefor value N toisisapply not too thistolarge technique when < 40). the For value example, of N iswhile not too O(2 < N way =of36 unlikely run (e.g. in oneisNsecond, we can, for instance, use large a)O(2(e.g.) N Mee Irvin GUNAWAN N/2 N/2 eolve solvable inJonathan polynomial time. Weone can check whether an additional IOI=2008 Island for N 36 is unlikely to run in algorithm second, we for can, N = for 36 instance, is unlikely use to a run O(2 in one ) Meet second, In The we can, Middle for instance, use algorithm for solving a problem like SUBSET-SUM. While O(2 ) is still exponential to N , it is Jonathan Irvin GUNAWANJonathan Irvin Finding GUNAWANSpecial Cases GUNAWAN 3.4 N/2 N/2 N olve IOI 2008 Island n problem suchO(2 Irvin GUNAWAN forthe solving a problem likeNSUBSET-SUM. algorithm for O(2 solving is a problem still exponential to range N , it of is much faster O(2 than ) is still expone Jonathan Irvin GUNAWAN ), and the Jonathan rangeWhile of N that it )can solve is like twiceSUBSET-SUM. the NWhile using a O(2 ) solution. N N n the problem such hether an additional is the approach in), the IOI, and thus the main of this paper.theTorange solveofIOI 2008 Islan nd theThis range of Nmost thatsuitable it can solve isO(2 twice andrange the range of Nisof using N that a O(2 itfocus can ) solution. solve is twice N using aO hether an IOI additional and 2014 Friend, we need to use this approach. We must find a special constraint in the problem suc 3.4 Finding Special Cases that this constraint allows the problem to be solvable in polynomial time. We can check whether an addition 3.4 Finding Special Cases 3.4 Finding Special Cases This is the most suitable approach in IOI, and thus is the main focus of this paper. To solve e most suitable approach in 2014 IOI, and This thus iswe is thethe most main focus approach this paper. in IOI, Tomust and solve thus IOIisa2008 the main Island focus of this and IOI Friend, need tosuitable use thisof approach. We find special constraint in th 014 Friend, we need to use this approach. and IOI 2014 We must Friend, find we a need special to constraint use this approach. in the problem We must such find a special this constraint allows the problem to be solvable in polynomial time. We can check wheth Jonathan Irvin that GUNAWAN constraint allows the problem to be that solvable this in constraint polynomial allows time.theWe problem can check to bewhether solvableaninadditional polynomial time. We Irvin GUNAWAN Jonathan Irvin GUNAWAN Fig. 4. Comparison of O(2N) and O(2N/2) SUBSET-SUM algorithm running time for various Jonathan GUNAWAN input sizes. This experiment is runIrvin 100 times for each value of N on a MacBook Pro (Retina, 13-inch, Early 2015). em. The most common approximation algorithm I found in textbooks is theApproximation 3.1 OVER problem, which means that the algorithm will not choose more than twice In real life, when we cannot theinoptimal solution, we can try to find the solution th ptimal solution. However, approximation problems rarelyfind occur competitive 2 2 Identifying Identifying Intractability Intractability 2 Identifying of of a a Problem Problem Intractability through through Reduction Reduction ofαa(where Proα solution. More specifically, we try to find a solution that is not larger than J.I. Gunawan e of the reason is92because to create this kind of problem, the judges have to Identifying Intractability of a Problem through Reduction solution for ais minimisation problem. The most common approximation algorithm I f r to that contestant’s solution indeed We Weverify would would like likethe to to know know that that the the problem problem that thatWe we weα-approximation. are would are attempting attempting like to know isisHowever, unlikely unlikely that the to toproblem have have an anthat immediate immediate we are solution. solution. attempting The The is 3.4. Finding Special Cases 2-approximation MIN-VERTEX-COVER problem, which means thatsolution. the algorithm will no impossible (orknow takes a isis long time). is not really suitable for would to that the problem thatthis we approach aremost attempting is unlikely have immediate The most mostlike common common way way to to apply apply aaSince well-known well-known technique technique common called called way reduction. reduction. is totoapply Suppose Suppose aanwell-known we we know know technique that that problem problem calledXXredu isis number of vertices than the optimal solution. However, approximation problems ra ot discuss this in we detail. t common way is athe well-known technique called reduction. we know that problem X impossible impossible to toapproach solve, solve, and and we also also know know that that we weimpossible can can solve solve problem problem to solve,XXand by bySuppose using we using also problem problem know that YY as as we aa black-box black-box can solve11.problem . IfIfiswe we can can Xb 22to apply Identifying Identifying Intractability Intractability of of a a Problem Problem through through Re Re programming (especially IOI). One of the reason isfocus because to paper. create this kind of pro 1 To This is the most suitable approach in IOI, and thus is the main of this ossible solve, and we also know that we can solve problem X by using problem Y as a black-box . If we can solve solvetoproblem problem Y, Y, then then we we can can solve solve problem problem X X solve as as well. well. problem Therefore, Therefore, Y, then problem problem we can Y Y solve is is also also problem impossible impossible X as to well. to solve. solve. Therefore, pr N/2 omparison of O(2N ) and O(2 )toSUBSET-SUM algorithm running time for various input sizes. This know the optimal solution in order to verify that the contestant’s solution isimmediate indeed αWe We would would like likeproblem to know know that the the problem problem that that we we are are attempting attempting is is unlikely unlikely to to have have an an immediate IOI 2008 Island and IOIwell. 2014 Friend, we need to use this approach. We must find e problem Y, 3.2 thensolve wePruning can solve Xthat as Therefore, problem Y is also impossible to solve. NN N/2 N/2 Figure 4: Comparison ofof )Pro ) )NSUBSET-SUM running time for variou Figure 4:of Comparison O(2 )and and SUBSET-SUM algorithm running time for vario N/2 NO(2 is run 100 times for each value N4:on atoMacBook (Retina, 13-inch, Early 2015) generating the optimal solution is impossible (or takes athe long time). Since this approac Figure 4:O(2 Comparison of O(2 )N/2 and O(2 )algorithm SUBSET-SUM algorithm runnin Figure Comparison O(2 )O(2 and O(2 )problems SUBSET-SUM algorithm running time for most common common way way isis to apply apply aaof well-known well-known technique technique called called reduction. reduction. Suppose Suppose we we know know that tha special constraint in the problem such that this constraint allows problem to be We We are are using usingamost NP-hard NP-hard problems problems for for illustration. illustration. We Recall Recall are that that using NP-hard NP-hard NP-hard problems problems have have for illustration. yet yet to to be be solved solved Recall in in polynomial that polynomial NP-har N N/2 Figure 4: Comparison of O(2 ) and O(2 ) SUBSET-SUM algorithm running time foE experiment is run 100 times for each value of N on a MacBook Pro (Retina, 13-inch, Early 20 algorithm running time for various input sizes. This experiment is run 100 times for each value of N on a MacBook Pro (Retina, 13-inch, Early 2 mpetitive programming problems. In ACM International Collegiate Programming competitive programming, I will not discuss this approach in detail. SUBSET-SUM algorithm running time for various input sizes. This experiment is run 100 times for each value of N on a MacBook Pro (Retina, experiment is run 100 times for each value of N on a MacBook Pro (Retina, 13-inch, N N/2 solvable in polynomial time. We can check whether an additional constraint causes a impossible impossible to to solve, solve, and and we we also also know know that that we we can can solve solve problem problem X X by by using using problem problem Y Y as as a a black-b black-b Wetime are using NP-hard forMIN-VERTEX-COVER illustration. Recall that NP-hard problems have yet to befor solved inaapolynomial time for for4:more more than thanproblems 44 decades. decades. time for is more isfor aa graph graph than problem 4problem decades. that that MIN-VERTEX-COVER involves involves finding finding minimum minimum is sizes. a 13-inch, graph subset subset pro Figure Comparison of O(2 )MIN-VERTEX-COVER and O(2 )100 SUBSET-SUM algorithm running time various input This experiment is run times each value of N on a MacBook Pro (Retina, E ok Pro (Retina, 13-inch, Early 2015) 0, on problem I (Robots on Ice) required the contestant to count number of N MacBook Pro (Retina, 13-inch, Early 2015) problem to bein solvable in polynomial time using the reduction proof of the original N N/2 solve solve problem problem Y, Y, then then we we can can solve solve problem problem X Xthe as as well. well. Therefore, Therefore, problem YY2015) is(withis also also impossible impossible auses aa problem torun be100 solvable polynomial time using the reduction proof of the original problem for than decades. MIN-VERTEX-COVER is aits graph problem involves finding avarious minimum subset of ofmore nodes nodes such such that that for for every every edge, edge, at atO(2 least least one one of of of nodes its endpoint endpoint such that isisPro in for inthat the the every subset. subset. edge, MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET atproblem least one ofprobits endpoint isisto ato in a experiment is4N times for each value of N on a MacBook (Retina, 13-inch, Early Figure 4: Comparison of O(2 ) and ) SUBSET-SUM algorithm running time for input sizes. This N N/2 N/2 ts (ACMofICPC World Finals 2010 problem statement n.d.), which isSUBSET-SUM known to Figure of O(2 )bebe and O(2 )additional algorithm running time various mparison O(2for )of and O(2 )Comparison SUBSET-SUM algorithm running time forathe various input sizes. This lem (without the additional constraint), and whether proof still holds given the constraint causes acauses problem to in time using the reduction proof of the orig constraint causes aproof problem to solvable inpolynomial polynomial time using the reduction proof of the or 3.2 Pruning tional constraint), and check the still holds the constraint to theone problem. odes such that every edge, at least one of endpoint ischeck in the subset. MAX-INDEPENDENT-SET isfor aproof graph graph problem problem of finding finding a4: awhether maximum maximum subset subset of of graph nodes nodes problem such such that that of finding for for every every maximum edge, edge, at at most most subset one of of of nodes its its endpoint endpoint such that isis for in in experiment is run 100 times for each value of N on asolvable MacBook Pro (Retina, 13-inch, Early 2015) constraint causes agiven problem to bein solvable in polynomial time using the reductio constraint aits problem to be solvable polynomial time using the reduction of ding all possible paths is impossible, the solution for this problem is to prune experiment is run 100 times for each value of N on a MacBook Pro (Retina, 13-inch, Early 201 additional constraint to the problem. run 100 times for each value of N on a MacBook Pro (Retina, 13-inch, Early 2015) constraint causes a problem to be solvable in polynomial time using the reduction proof of out additional constraint), and check whether the proof still holds given the additional constra ing the reduction proof of the original problem (without the additional constraint), and check whether the proof still holds given the additional constr We We are are using using NP-hard NP-hard problems problems for for illustration. illustration. Recall Recall that that NP-hard NP-hard problems problems have have yet yet to to be be solved solve h the problem of using finding a we maximum subset of nodes that for everyand atthe most one ofholds its endpoint in show the subset. subset. Suppose Suppose we already already know know that that MIN-VERTEX-COVER MIN-VERTEX-COVER thesuch subset. Suppose iswe isedge, aaalready NP-hard NP-hard know problem. problem. that MIN-VERTEX-COVER Therefore, Therefore, we weisInternationa can can show lynomial time the reduction proof of the problem (without the additional constraint), check whether the proof stillACM holds given theis out the additional constraint), and check whether proof still given the additional This approach isinoriginal useful some competitive programming In causes apaths problem to be solvable polynomial time using the proofproblems. of the original problem (withICPC World Finals 2010 Solutions n.d.). at toconstraint findgiven all possible (ACM We will give we example ofin aproblem special case in a reduction NP-hard Suppose we out the additional constraint), andis check whether the problem. proof still holds given the additional holds the additional to the time time for more more than than 4one 4also decades. decades. MIN-VERTEX-COVER MIN-VERTEX-COVER iswe is If aaaaproblem. graph graph problem that that involves involves finding finding aaaam m give we onestill example offor aconstraint special case in aaproblem. NP-hard problem. Suppose have aisproblem function withwe the subset. Suppose we already know that MIN-VERTEX-COVER areducing NP-hard Therefore, can show that that MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET is is also a NP-hard NP-hard that MAX-INDEPENDENT-SET problem by by reducing MIN-VERTEX-COVER MIN-VERTEX-COVER also a NP-hard problem problem problem by into into reduc er the proof holds given the additional constraint to the problem. Contest (ICPC) World Finals 2010, problem Iand (Robots onofIce) required the contestant out the additional constraint), and check whether the proof still holds given the additional constraint to the problem. constraint causes a problem to be solvable in polynomial time using the reduction proof the original problem (withossible to visit the rest of the unvisited points, then we can prune the path have a function with the following formula We give one example of case inthe NP-hard problem. Suppose we have a We will give we one example ofafor aspecial special case in aspecial NP-hard problem. Suppose have nodes nodes such such that that for for every every edge, edge, at at least least one one ofspecial its endpoint endpoint isThis inNP-hard the the subset. subset. MAX-INDEPEND MAX-INDEPEND N N/2 rmula MAX-INDEPENDENT-SET iswill also awill NP-hard problem by reducing aits MIN-VERTEX-COVER problem into awe MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET problem. problem. MAX-INDEPENDENT-SET problem. constraint causes awe problem to be solvable inexample polynomial time using the reduction proof of the origi ses a) problem to beof inHamiltonian polynomial time using the reduction proof of original problem We will give we one of aasizes. case in a (withNP-hard problem. Su We give we one example of aof case inis ain problem. Suppose we (2 and O(2suitable )ofsolvable SUBSET-SUM algorithm running time various input Paths with constraints (ACM ICPC World Finals 2010 problem statement out thevery additional constraint), and check whether the proof still holds given the additional constraint to the problem. it is not for IOI. Usually, IOIgive problems require deep analysis from We will we one example of a special case in a NP-hard problem. Suppose we following formula ard problem. Suppose we have a function with the following formula graph graph problem problem of of finding finding a a maximum maximum subset subset of nodes nodes such such that that for for every every edge, edge, at at most most one one of of its its X-INDEPENDENT-SET problem. out the additional constraint), and check whether proof still holds given the additional constrai onal constraint), and check the proof stilla formula holds given the additional constraint toiswe the problem. case ineach a NP-hard problem. Suppose we have function the following following formula s forget value of Nonly on awhether MacBook Pro (Retina, 13-inch, Early 2015) be a NP-hard problem. While finding allthe possible paths impossible, the solution for We will give we one"hacking" example a special case in a with NP-hard problem. have a function with the can Accepted by aofcomplete search algorithm. Therefore, weSuppose following formula the the subset. subset. Suppose Suppose we we already already know know that that MIN-VERTEX-COVER MIN-VERTEX-COVER isis aa NP-hard NP-hard problem. problem. Therefore Therefor 1, n = 1 ∨ n = 2 We We will will first first prove prove the the following following two two lemmas. lemmas. We will first prove the following two lemmas. N following N/2 ICPC World Finals 2 the exponential algorithm we use to find all possible paths (ACM f (n) = formula We will give we one example of a special case in a NP-hard problem. Suppose we have a function with the ) and O(2 ) SUBSET-SUM algorithm running time foraavarious sizes. by This etail. 1,1,input nn= 1MIN-VERTEX-COVER n =MIN-VERTEX-COVER 1∨n∨the that MAX-INDEPENDENT-SET isproblem. is also also NP-hard NP-hard problem problem by reducing reducing aawith We willone firstexample prove that the We will give we+ one example of a2impossible special case a NP-hard problem. Suppose we =2have 1then ∨ naw = 1,invisit =n=1=2∨2points, nn= f two (n −lemmas. 1) f (n − 2), n >(n) ve we of following aMAX-INDEPENDENT-SET special case in awe NP-hard Suppose we have a1, function f (n) = f = some point know that it is to the rest of the unvisited following formula ortoLemma each value of on MacBook Pro the (Retina, 13-inch, Early 2015) be solvable polynomial time using reduction proof problem (withf1,1) (n) = f (n) = Lemma 1. 1. Lemma 1.of Ifthe Ifin If N SS ⊆ ⊆ VVa is is an an INDEPENDENT-SET INDEPENDENT-SET of of graph graph S G(V, G(V, ⊆ VE), E), then an then VV − −2), SS2), isis n aanVERTEX-COVER VERTEX-COVER of of the theE n = of 1 ∨graph n = 2G(V, MAX-INDEPENDENT-SET problem. problem. foriginal − 1) ++ fINDEPENDENT-SET > f(n (n −is f(n (n− 2(n n following = 1 ∨∞nbacktrack =formula 2 mula n = 1 ∨ n = 2MAX-INDEPENDENT-SET fE), (n) =not fa− (n −− 1)IOI. +>2fto − 22),IOI nthe >2 fto (n − 1) + fVERTEX-COVER (n 2), nknow > 1, n = 1 ∨ n = 2 immediately. However, it is very suitable for Usually, problems r the sequence F = {f (n)} , and we define F (N ) to be the first N terms of F . We want t), and check whether the proof still holds given the additional constraint the problem. mma 1. If S ⊆ V is an INDEPENDENT-SET of graph G(V, then V − S is of N/2 graph graph G(V, G(V, E) E) graph G(V, E) n=1 3.3 Finding Small Constraints )), and SUBSET-SUM algorithm running time for various f (n −This 1) + f (n − 2), n > 2 f (n) = n+O(2 > 2(n −)2), ∞ ∞ input sizes. − 1) f n > 2 We consider the sequence F = {f (n)} , and we define F (N ) to be the first N terms of F . We consider the sequence F = {f (n)} , and we define F (N ) to be the first N terms of F We consider the sequence , and we define to be the first ∞ ∞ the contestant. It is rare that we can get Accepted by only "hacking" a complete search 1, n = 1 ∨ n = 2 can create a partition of F (N ) into two disjoint multisets A and B such that the sum of all elements n=1 n=1 ffollowing (n − 1) + f= (n −original 2),F n=1 n {f > 2 we hbe G(V, E) in We consider the sequence = (n)} , and we define F=(N ) to firs consider the sequence {f (n)} , and define F (N )∨ tonbe the firstbeNthe term n=1 We will willWe first first prove prove the the following two lemmas. lemmas. each value ofus Nassume on aWe MacBook Pro 13-inch, Early solvable polynomial time reduction proof of the (with1, n = 2A, fS (n) = ∞problem 1, n two =F 1of ∨ n2015) = 2Therefore, Proof. Proof. Proof. Let Let us assume that that Vusing VB − Sthe is(Retina, is not not VERTEX-COVER. VERTEX-COVER. Let us assume Therefore, that Vthere there − define SReduction are is are two a 1vertices vertices VERTEX-COVER. A, B B ∈ /∈ /that VN V− − The SS s We consider the sequence F = {f (n)} , into and we Ftwo (N )A be the first term whether we can create partition of F )partition multisets A and B such the ntifying ntifying Intractability Intractability of of a a Problem Problem through through Reduction N )to tothe be the first Nto terms of F .− We want toaathis know with large N that whether isof impossible can create to solve a(n partition exponentially F(N (N (e.g. )into into Ntwo two > 50). disjoint multisets and B such that the case terms .we We want to know whether we can create adisjoint partition of not to into two will not discuss technique in detail. n=1 al sum of all elements in fpartition (n) = ample of a special in a NP-hard problem. Suppose we have a function with the f (n) = f − 1) + f (n − 2), n > 2 dblem we define F (N ) be the first N terms of F . We want to know whether we can create a of F (N ) into two disjoint multisets A and B whether we can create a of F (N ) two disjoint multisets A and B such tha ∞ and check whether the proof still holds given the additional to the problem. We consider thedisjoint sequence {f ,create and we define (N )F to be first N terms of Fthe .BWe want know n=1 fin (n − 1) +the f (n − 2), nAs > 2Since of. Let us that Vconnecting − is= not aV+ VERTEX-COVER. Therefore, there are vertices A, ∈ /are V a∈ fF (n − 1) fiscan (n 2), nA, > and and there there isconstraints is an an edge edge connecting A A(n)} and and B. B. Since Since and there B B2∈ /constraint ∈ /is VVF an− − edge S, S, we we connecting have have A, A, B Btwo A ∈ ∈ and S. S. As B. A A and and B A, B B are /a− connected connected V S, we whether aA, partition of (N )problem into two disjoint multisets A and BSto− such th Vwe and − such that the sum of all elements in is equal toV sum inthat Amultisets is equal to the sum of all elements in B multisets A assume and B such the sum of all elements small in that A isS may equal help. to the For sum example, ofsum all aof elements SUBSET-SUM B Lemma Lemma 1. 1. If If SS ⊆ ⊆ is an an INDEPENDENT-SET INDEPENDENT-SET of of graph graph G(V, G(V, E), E), then then V − − S S is is VERTEX-C VERTEXo other two disjoint multisets A and B such that the sum of all elements in A is equal to the sum of all elements in B in A is equal to the all elements in B ∞ whether can create a partition of F (N ),the into two disjoint multisets A and Bnot such that the ofwant all elements We the sequence F = {f (n)} and we define Fwe (N )This to be the first N terms of F .sum We toSSknow ke ke to to will know know that that the the problem problem that that we we are are attempting attempting is unlikely unlikely to to have have an an immediate immediate solution. solution. The The there isconsider edge connecting A and B. Since A, Bsum ∈ /{f Vis − S,∞ have B ∈ S. As and B are connected n=1 by by an an edge, edge, we we note note that that an edge, note that S S isis not an an INDEPENDENT-SET. INDEPENDENT-SET. This is is athat aof S contradiction. contradiction. isF INDEPENDENT-SET. Therefore Therefore V− − of all elements in not .sequence eand solvable inwe polynomial time using the reduction proof of the original problem (within A iswe equal to of all elements inA, B not be solvable with N =the 100. When we are given the constraint ∞ graph graph G(V, G(V, E) E) ks like a an classic PARTITION problem. PARTITION problem is3.3 by reduction from SUBSETWe consider Fby = (n)} ,aNP-hard and we define (N )Aan to beConstraints the first N Vterms ofisisThi Faa. he sequence F = {f (n)} , and define F (N ) to be the first N terms F . We want to know Finding Small n=1 n=1 mple of a special case in a NP-hard problem. Suppose we have function with the in A is equal to the sum of all elements in B whether we can create a partition of F (N ) into two disjoint multisets A and B such that the sum of all elements 2 on on way way is to to apply apply a a well-known well-known technique technique called called reduction. reduction. Suppose Suppose we we know know that that problem problem X X is is n edge, we note that S is not an INDEPENDENT-SET. This is a contradiction. Therefore V − S is a This looks like a classic PARTITION problem. PARTITION problem is NP-hard by VERTEX-COVER. VERTEX-COVER. ndVERTEX-COVER. check the proof still holds given the additional constraint to) two the problem. This like classic PARTITION PARTITION problem isin bybyreduct are small 100]), this This problem looks like can aThis be solved using O(N X Dynamic PARTITION problem isNP-hard NP-hard reduc 1,value na= 1classic =PARTITION 2like efore, for whether a partition large[0, of(N N itlooks is unlikely to be toofA find an algorithm that finds B ansuch whether can create a∨ partition (N )problem. into disjoint multisets A problem and B that the su an create a(e.g. of F ), we into two disjoint multisets Bproblem. such that the PARTITION sum ofA all1and elements looks aFand classic PARTITION problem. is by NP This looks like an able classic PARTITION problem. isproblem NP-hard 1PARTITION in Af (n) isand equal to the sum ofTherefore, all elements in B = Proof. Proof. Let Let us us assume assume that that VVlarge − − Svalue Svalue isisby not not aN aNVERTEX-COVER. VERTEX-COVER. Therefore, Therefore, there are are two two vertices vertices A ooN solve, solve, and we we also also know know that that we we can can solve solve problem problem XX by using using problem problem YY as as ato a black-box black-box ..find Iffind Ifthere we we can can Suppose there is an NP-hard problem with large N that is impossible to solve expo reduction from SUBSET-SUM. Therefore, for a large value of , it is unlikely to be TEX-COVER. This looks like a classic PARTITION problem. PARTITION problem is NP-hard by SUM. for a large of , it is unlikely to be able to an algorithm that fin problem is NP-hard by reduction from SUBSETer bound of the elements SUM. inside Therefore, the array. for Even a though the of running , it is time unlikely of the be able to an algorithm that fi y. However, this sequence is defined in a very special way, in the sense that F is defined using the in A is equal to the sum of all elements in B toLemma the sum of all elements in B em. PARTITION problem is NP-hard by reduction from SUBSETSUM. Therefore, for a large value of N , it is unlikely to be able to find an at SUM. Therefore, for a large value of N , it is unlikely to be able to find an algorithm f (n − 1) + f (n − 2), n > 2 Lemma 2. 2. Lemma 2. If If S S ⊆ ⊆ V V is is a a VERTEX-COVER VERTEX-COVER of of graph graph G(V, G(V, If S E), E), ⊆ then V then is V a V VERTEX-COVER − − S S is is an an INDEPENDENT-SET INDEPENDENT-SET of graph G(V, of E), of the the the This looks like a classic PARTITION problem. PARTITION problem is NP-hard by reduction from SUBSETand and there there is an an edge connecting connecting Asequence and and B. B. Since Since A, A, B B ∈ /∈ /away. Vconstraints Vvery − − S, S, we we have have A, A, B Bthe ∈ ∈ S. S. As Asalgorithm A Athat and and B B ancan m m Y, then we we can solve solve problem problem XXedge as as well. well. Therefore, Therefore, problem problem isisefficient also also impossible impossible to to solve. able find an algorithm that finds we and for in an However, this sequence Sometimes we should also look other that may help. For example, le ofthe athen special case into aefficient NP-hard problem. Suppose have aYY function with the SUM. Therefore, for aA value of N ,small it is tosolve. be able find an efficient way. However, this sequence isin defined in way, into sense that is ble to find algorithm that finds A and B in an way. However, this is defined in aunlikely very special way, in the ofY, input, the algorithm isis still fast enough for the given Another F ned recurrence. we should inspect the formula more unlikely be able tofor find an algorithm that finds Alarge and Bconstraint. an efficient way. However, this sequence is defined in a very special way, inFan the efficient However, this sequence is defined inalgorithm aspecial very special way, insense the sense th ∞ mma 2. Ifto Slooks ⊆ V,Therefore, is aan VERTEX-COVER of graph G(V, E), then V problem − S isclosely. an INDEPENDENT-SET of the 1,E) n)way. = 1be ∨ nNP-hard = 2recurrence graph graph G(V, G(V, E) graph G(V, E) SUM. Therefore, a large value of N , it is unlikely to be able to find an that finds A and B in This like a classic PARTITION problem. PARTITION is NP-hard by reduction from SUBSETN F = {f (n)} and we define F (N to the first N terms of F . We want to know by by an edge, edge, we we note note that that S S is is not not an an INDEPENDENT-SET. INDEPENDENT-SET. This This is is a a contradiction. contradiction. Therefo Therefo is defined in a very special way, in the sense that is defined using the aforementioned is considered an problem, and will not be solvable with N = 100. When we are n=1 efficient way. However, this sequence is defined in a recurrence very special way, inmore the th aforementioned recurrence. Therefore, should inspect the formula closely. way, the that F issense defined using the en the value ofPARTITION Nsense isway, not aforementioned too large (e.g. recurrence. < 40). Therefore, For example, we should while O(2 inspect )inspect the recurrence more closely. fin (n) = in special This looks like aN classic PARTITION problem. PARTITION problem isformula NP-hard bysense reductio secial like aa classic problem. PARTITION problem iswe NP-hard by reduction from SUBSETed very in the that F ismultiples defined using the aforementioned recurrence. Therefore, we should inspect recurrence aforementioned recurrence. Therefore, we should the recurrence more hsing G(V, E) efficient way. However, this sequence defined a of very special way, in sense that F isthe defined the Any consecutive subsequence of Finstance, with length three can be partitioned into two multisets SUM. Therefore, afclosely. large value of N it is unlikely to be able to find anthe algorithm that finds Aformula andusing informu ancc fproblems (n − 1)for + (n − 2), nRecall > 2is,should recurrence. Therefore, we inspect the recurrence formula more closely. N/2 artition of Fformula (N ) into two disjoint multisets Athat and Bin such that the sum of all elements VERTEX-COVER. VERTEX-COVER. sing NP-hard NP-hard problems for for illustration. illustration. Recall that NP-hard NP-hard problems problems have have yet yet to to be be solved solved in in polynomial polynomial all the elements inside the array are small (e.g. [0, 100]), this problem can beB solved aforementioned recurrence. Therefore, we should inspect the recurrence formula more recurrence more o run in one second, we can, for use a O(2 ) Meet In The Middle Proof. Proof. Proof. The The proof proof is is actually actually similar similar to to the the previous previous lemma. lemma. The proof Let Let us us is assume assume actually that that similar V V − − to S S is the is not not previous a a INDEPENDENT-SET. INDEPENDENT-SET. lemma. Let us assu SUM. for a be large value of Nan, italgorithm isFF unlikely to finds bemultiples able to find anan algorithm that find ore,aforementioned for a large value of Nformula , Therefore, it is unlikely to able to find that A and Bthree in uld inspect the recurrence more closely. Any consecutive subsequence of with length of can partitioned Lemma 3.sequence Any subsequence of with length multiples of canbebeEven partitione Lemma 3. recurrence. Therefore, we inspect the recurrence formula closely. m. efficient way. However, this isisisnwhere defined special way, in the sense that Fthree isof defined using the N/2 fe SUBSET-SUM. all elements in B than than 44proof decades. decades. MIN-VERTEX-COVER MIN-VERTEX-COVER aashould graph graph problem problem that that involves involves finding finding aaFmore minimum minimum subset subset ∞ Programming, X is the upper bound of the elements inside the array. thoug Any consecutive subsequence of with length multiples of three c 1, n = 1consecutive ∨ = 2Therefore, Lemma 3. Any consecutive subsequence ofconnecting F with length multiples three can be part Lemma 3. ere While O(2 ) SS isthe still exponential toin Nathere ,very itin is much faster than of. The is actually similar to previous lemma. Let us assume that V − S is not a INDEPENDENT-SET. = {f (n)} , and we define F (N ) to be the first N terms of F . We want to know Lemma 3. Any consecutive subsequence of with length multiples of three can be Therefore, Therefore, there there are are two two vertices vertices A, A, B B ∈ ∈ V V − − S S and and there there is is an an are edge edge two connecting vertices A, A A B and and ∈ V B. B. − S Since Since and A, A, there B B ∈ ∈ is V Van − − S, S, efficient way. However, this sequence is defined in a very special way, in the sense that Fedg is n=1 However, this sequence is defined in a very special way, the sense that F is defined using Lemma Lemma 2. 2. If If ⊆ ⊆ V V is is a a VERTEX-COVER VERTEX-COVER of of graph graph G(V, G(V, E), E), then then V V − − S S is is an an INDEPENDEN INDEPENDEN f (n) = Any consecutive subsequence of F with length multiples of three can be par Lemma 3. of equal sum. ltiples of three can be partitioned into two multisets of equal sum. aforementioned recurrence. Therefore, we should inspect the recurrence formula more closely. Ninto ch h that that for for every every edge, edge, at at least least one one of of its its endpoint endpoint is is in in the subset. subset. MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET is is a a algorithm is exponential to the size of the input, the algorithm is still fast enough for the with length multiples of three can be partitioned two multisets of equal sum. of equal sum. t any can solve is)(n twice the of N using O(2 )with solution. fA, −∈ 1) + frange (n 2), n > 2AaSlength into two multisets of equal refore, there are two vertices A, B ∈ V − and there issum. an edge connecting Ais and B. Sinceby A,F Binto ∈V − This S, tion ofhave F (NA, into two disjoint multisets and such that the sum ofwhich allclosely. elements we we have B B /∈ /partitioned S. S. As As A A− and and B are are connected connected we by by have an an edge, edge, A,formula B we ∈ /we S. note note As that A that and SSwe B iscan not not are adenote connected a partitioned VERTEX-COVER. VERTEX-COVER. by an edge, This we isnote is aa Any consecutive subsequence of FB length multiples of three be two multisets Lemma 3. consecutive subsequence of F with multiples of three, will = aforementioned recurrence. Therefore, we should inspect the recurrence formula more closely. ed recurrence. Therefore, we should inspect the recurrence more graph graph G(V, G(V, E) E) of equal sum. cem PARTITION PARTITION problem istechnique NP-hard reduction from SUBSETm of ofA, finding finding aB aproblem. maximum maximum subset subset of of nodes nodes such such that that for for every every edge, edge, at atF most most one one of ofisan its its endpoint endpoint is isthree, in inThiswhich way tois apply this isby when the value of NVERTEX-COVER. not too large (e.g. N < 40). F note Pick any consecutive subsequence of F with length multiples of three, we wiw Proof. Pick any consecutive subsequence of with length multiples of which we Proof. ave B ∈ / S. As A and B are connected by an edge, we that S is not a is a l elements in contradiction. contradiction. Therefore Therefore V V − − S S is an an INDEPENDENT-SET. INDEPENDENT-SET. contradiction. Therefore V − S is INDEPENDENT-SET. ∞ of equal sum. +{f1), f (a + ,2), ...f (b)} for some a < Pick b. We can Fof into Any consecutive subsequence ofsubsequence Fpartition with length multiples of three can into two multisets Lemma 3.and Pick any consecutive subsequence ofbeof Fpartitioned with length multiples of thr Proof. Proof. any consecutive subsequence of F with length multiples ofwe three, which we (n)} we define F (N ) to be the first N terms of F . We want to know Proof. Pick any consecutive with length multiples three, which n=1 ge value of N , it is unlikely to be able to find an algorithm that finds A and B in an Any consecutive subsequence of F with length multiples of three can be partitioned Lemma 3. Suppose Suppose we we already already know know that that MIN-VERTEX-COVER MIN-VERTEX-COVER is is a a NP-hard NP-hard problem. problem. Therefore, Therefore, we we can can show show ny consecutive subsequence of F(a+ with length multiples of three partitioned into multisets algorithm for N+2), = 36 is unlikely tocan run inb. one second, wetwo can, use awhich O(2 Proof. Proof. The The proof isis1), actually actually similar similar to to the the previous previous lemma. lemma. Let us uspartition assume assume that that Vinto Vinstance, − −SSof isis not not aa INDEPE INDEP any consecutive subsequence of FLet with length multiples three, Proof. {f fby (a 1), f{f + ...f (b)} for some aabe < We can F into multiples of three, which we will by F = {f (a), fproof + f(a (a 2), ...f (b)} for some < b. We can Ffor radiction. Therefore Vdisjoint −(a), S isthree, an INDEPENDENT-SET. denote of 3.4 Finding Special Cases F with length multiples of which we will denote by F = (aTheorem + 1), (a + 2), ...f (b)} for some a− <SS We can partition into =Pick {f (a), ffin (a + 1), ff(a + 2), ...f (b)} for some apartition < b.b. .isisWe partition FF F into F will denote for some We can parti on of equal F (N )sum. into two multisets A and B such that the sum of allis E), elements N/2 b− a(a − 2(a), bE), − a −an 2We any consecutive subsequence of F with length multiples of three, which we will denote by = Proof. A Theorem Theorem 1. 1. 1. If If S S ⊆ ⊆ V V is is a MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET of of graph graph If S ⊆ G(V, G(V, V a MAX-INDEPENDENT-SET then then V V − a a MIN-VERTEX-COVER MIN-VERTEX-COVER of graph G(V is sequence is defined in a very special way, the sense that F is defined using the of equal sum. Pick NDEPENDENT-SET NDEPENDENT-SET is is also also a a NP-hard NP-hard problem problem by by reducing reducing a a MIN-VERTEX-COVER MIN-VERTEX-COVER problem problem into into a a algorithm for solving a problem like SUBSET-SUM. While O(2 ) is still exponential to Therefore, Therefore, there there are are two two vertices vertices A, A, B B ∈ ∈ V V − − S S and and there there is is an edge edge connecting connecting A and and B. B. Since Since {f (a), f + 1), f (a + 2), ...f (b)} for some a < b. can partition F into rtition F can into ARTITION problem. PARTITION from SUBSETA = {f (a + 3k), 0 into ≤ k ≤ problem}is∪NP-hard {f (a + 1by + reduction 3k), 0 ≤bkb− ≤ } < b. We partition F tion into −2 2 elements in B a − b − a − 2so − a b − a − 2 N N 3 3 {f (a), fIfPick (a + 1), f (a + 2), ...f (b)} for some a < b. We can partition F into orem 1. graph Swe ⊆thus Vproblem. is a MAX-INDEPENDENT-SET of graph G(V, E), then V − S is a MIN-VERTEX-COVER of of the the graph G(V, G(V, E). E). of the graph G(V, E). any consecutive subsequence of F with length multiples of three, which we will denote by F = Proof. Therefore, should inspect the recurrence formula more closely. h in IOI, and is the main focus of this paper. To solve IOI 2008 Island PENDENT-SET PENDENT-SET problem. b − a − 2 b − a − 2 b − O(2 ), and the range of N that it can solve is twice the range of N using a O(2 ) we we have havetoA, A, B Bable ∈ /∈ /Fany S. S. As A A=and and B B(a are are connected connected by by an an edge, edge, we note note that S+ isis1∪three, not not a k+ VERTEX-COV VERTEX-CO Alength {f{f (a + 3k), 0+ k{f }}we ∪ (a +that 11+ 0+ ≤ } = + 3k), 0≤ ≤ k≤ ≤ ∪{f {f (a + +S3k), 3k), 0≤ ≤ak ≤ valueconsecutive of N , it is subsequence unlikely be toAs find an algorithm that finds A and B in an Pick consecutive subsequence of Fwhich with length multiples of which we wil Proof. A = (a + 3k), 0 ≤ k ≤ } {f (a 1 + 3k), 0 ≤ A = {f (a 3k), 0 ≤ k ≤ } ∪ {f (a 3k), 0 ≤ k ≤ any of with multiples of three, we will denote by F = b − a − 2 b − b − a − 2 3 3 b − a − 2 3 3 he graph G(V, {f1−(a), fisapproach. (a +E). 1), f≤ (a + 2), ...f (b)} some a}. <sense b.an We can partition F using into3 the } ∪ {f this We must find afor special constraint in 3k), the problem such −use a 2 3k), b− ain − 2− 3− (a A = {f (a + 0 ≤ k ≤ + 1 + 3k), 0 ≤ k ≤ contradiction. contradiction. Therefore Therefore V V − S S is is an INDEPENDENT-SET. INDEPENDENT-SET. a + + 0 ≤ k } B = {f (a + 2 + 3k), 0 ≤ k ≤ sequence defined in a very special way, the that F is defined b a − 2 b − a − 2 e Proof. subsequence of(b)} F 1that with of three can be partitioned two {f (a), f0(a (a + 1), f0(a + 2), (b)} for athat <1into b. partition F into ∪ {f (a + + 3k), ≤ kisproblem ≤ }...f 1), f (a +} We 2), ...f for some a < We can partition FWe into Proof. Proof. We know know that Vlength V{f − S S+multiples is ab. a vertex vertex cover by by lemma lemma know 1. 1.(a The The only only − thing thing that a vertex for uslemma to to prove prove 1. is The is its itso bVbWe − aS − acan RTITION problem. PARTITION isk cover NP-hard by reduction from SUBSET3is2≤ 3− }3k), ∪some {f + 3k), 0multisets ≤remains A 3k), ≤ ≤{f b −cover a −for 2}byus b− −2that 2remains oblem to be solvable in = polynomial time. can check additional first first prove the the following following two two lemmas. lemmas. 3 prove 3We }.ka B3B = (a− + 2−2+ 0+ k+k+ ≤ }.k− = {f (a + +whether 3k), 0≤ ≤an ≤ 3.4 Finding Special Cases herefore, we should inspect the recurrence formula more closely. 3 3 b a 2 b − a − 2 }. B = {f (a 2 + 3k), 0 ≤ ≤ }. B = {f (a + 2 3k), 0 ≤ k ≤ of. We know that V − S is a vertex cover by lemma 1. The only thing that remains for us to prove is its b − a − 2 V V − − S S is is not not minimum minimum vertex vertex cover. cover. Then, Then, V there there − S is is is another another not minimum vertex vertex cover vertex cover V V cover. − − S S where Then, where minimality. minimality. Suppose Suppose minimality. Suppose 3graph alueb − of aN−, 2it is unlikely to{f be1. able algorithm that finds B in ank3G(V, Theorem Theorem 1. Sto ⊆ isan MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET of of G(V, E), 3then then}VV − −SS isisb a− a MIN-VE MIN-VE A as = (a + 3k), 0VV2k≤is≤ kaab−a−2 ≤ }−+∪22{f 02≤ ≤ E), a−2 b+A−10and a+ 2a3≤graph b −3k), − bIfIf−S −find }. B =b{f (a +(a 3k), k ll have the sum, for every 0a⊆ ≤ − ≤ {fsame 3(a a3k), is≤another }. ≤ 33k), 3 3k), A = {f + 0 ≤ k ≤ } ∪ {f (a + 1 + 0 ≤ k A = (a + 3k), 0 ≤ k ≤ } ∪ 1 + 0 k ≤ } V − S is not minimum vertex cover. Then, there vertex cover V − S where mality. Suppose 3 |V |V − − S S | | < < |V |V − − S|, S|, which which implies implies that that |S |S | | > > |V |S|. |S|. − S By By | < lemma lemma |V − 2, 2, S|, S S which is an an implies independent independent that |S set. set. | > Therefore, Therefore, |S|. By lemma S S is is not not 2, S aa} If If S S ⊆ ⊆ V V is is an an INDEPENDENT-SET INDEPENDENT-SET of of graph graph G(V, G(V, E), E), then then V V − − S S is is a a VERTEX-COVER VERTEX-COVER of of the the quence is defined in a very special way, in the sense that F is defined using the b−a−2 b−a−2 }. B = {f (a + 2 + 3k), 0 ≤ k ≤ of of the the graph graph G(V, G(V, E). E). This ismultiples the suitable approach in IOI, and thus is = the main b−a−2 focus of this paper. ubsequence of F of with length multiples of most three can be partitioned into two multisets 3 3 3 B will have the same sum, as for every 0 ≤ k ≤ Aand and B will have the same sum, as for every 0 ≤ k ≤ ve subsequence FA with length of three, which we will denote by F b−a−2 3 3 will as for 3 3 3≤ 0 ≤ k ≤ b − a − 2 A and B will have the same sum, as for every A and B have the same sum, every 0 ≤ k − Smaximum | < |V −should S|, which that |S(a >− lemma 2, S is independent isspecial not a constr maximum independent independent set. set. This This a3k), a|acontradiction. contradiction. maximum Therefore Therefore independent VVan − −this S S isisapproach. the This minimum isset. a b−a−2 contradiction. vertex vertex cover. V −S 3 SaTherefore 3Therefore, E) E) erefore, web−a−2 the formula closely. ≤ 3k) Bb.fimplies = {f + 2 is + 0|S|. kBy ≤more b set. − athe − 2minimum (a +(a 3k) + + 1F + = f (a +sum, 2 }. + and IOI we need to 3k) use must cover. find bfis 2Friend, Arecurrence and B−2014 will have the same as for every 0≤ k ≤ We ..f (b)} for some a2inspect < We can partition into 3 thing 3 0≤ k ≤ }. B = {f (a + 2 + 3k), 0 ≤ k ≤ b−a−2 }. B = {f (a + + 3k), 0 ≤ k ≤ Proof. Proof. We We know know that that V V − − S S is is a a vertex vertex cover cover by by lemma lemma 1. 1. The The only only thing that that remains remains for for us us imum independent set. This is a contradiction. Therefore V − S is the minimum vertex cover. 3 A and B will have the same sum, asconstraint for every allows 0≤k≤ fthe + fto + 1f1+ + 3k) = + + 3k) f(a(aproblem 3k) f(a(a +solvable +3k) 3k) =ffpolynomial f(a(a+ +12f2+ 3k) that this be in time. We can 3(a 3+3k) fmultisets (a 3k) fif3k) (a 2 +che fthere (a+ ++ 3k) + (a 1+ + 3k) = (a+ +MIN-VERTEX-CO + From Fromthat the the theorem, we we conclude conclude that that aaTherefore, From MIN-VERTEX-COVER MIN-VERTEX-COVER the above theorem, can can we be be conclude easily easily constructed that a− we we+have have a3k a bsequence of FofVabove with multiples of 3Vthree can be partitioned into two us us assume assume that Vabove − −with Slength Satheorem, isis−length not not aaSuppose VERTEX-COVER. VERTEX-COVER. Therefore, there are are two two vertices vertices A, A, B Bconstructed ∈ /∈ /isVV − SS2=+ifvertex subsequence F multiples of three, which we will denote by F = b−a−2 V − − S S is is not not minimum minimum vertex vertex cover. cover. Then, Then, there there is another another vertex cover cover minimality. minimality. Suppose b − 2 b − a − 2 (a + 1 + 3k) = f (a + 2 + 3k) = f (a + 2B≤ + 3k) A and will have the same sum, as 1for every 0≤≤kk≤≤ 3 f (a}+ 3k) + fb−a−2 f (a + 1 + 3k) = f (a + 2 + 3k) a + 3k), 0 k ≤ } ∪ {f (a + + 3k), 0 b−a−2 vin GUNAWAN From the above theorem, we conclude that a MIN-VERTEX-COVER can be easily constructed if we have a MAX-INDEPENDENT-SET. MAX-INDEPENDENT-SET. an anMAX-INDEPENDENT-SET. edge edge connecting connecting and B. B. Since Since B Binto ∈ /3k) ∈ /same Vimplies V+ − −fsum, S, S, we we have A, A, B Bf∈ S. S. As A and and B B is are are connected A and B have as for3k) every 0∈ ≤ ≤+A and will will have the for have thesome sameasum, as for|can every 0 S|, ≤ kA, ≤the fA, (a + (athat +as 1have + (aBy +klemma 2As 3k) (b)} for <|V b. A We partition F |V − − S |< < |V |V − − S|, which which that |S |S |3|every > >= |S|. |S|. By lemma 2, SS is an anconnected independent independent set. set. Theref Theref 3 S 32, 3implies Jonathan Irvin Jonathan IrvinGUNAWAN GUNAWAN X-INDEPENDENT-SET. we we note note that that SS maximum ismaximum is not not an INDEPENDENT-SET. INDEPENDENT-SET. This This is is a a contradiction. contradiction. Therefore Therefore V V − − S S is is a a Jonathan Irvin GUNAWAN Jonathan Irvin GUNAWAN b −an a− 2 f (a + 3k) + f (a + 1 + 3k) = f (a + 2 + 3k) independent independent set. set. This Thiswhich isis aa contradiction. contradiction. Therefore Therefore −SS isis the the minimum minimum vertex vertex cover. cover V ubsequence of0 ≤ multiples three, we denote F =V − bF−kwith a≤f−(a 2length bthe −will 2 MIN-VERTEX-COVER }. a + 2In + the 3k), Jonathan Irvin GUNAWAN f−(a + 3k) + fof(athis +by1section, + 3k) =we f (a 2NP-hard +we 3k)know + 1ofassume + 3k) f≤ (a + 2abeginning + 3k) Jonathan Irvin GUNAWAN the beginning of of this this section, section, we we assume we In know know that that assume isis+ aa NP-hard problem. problem. that MIN-V ItIt isis OVER. OVER. + 3k), 0In≤ k beginning ≤ }+ ∪3k) {f (a f+(a1 + + 0 ≤=kwe }MIN-VERTEX-COVER 3 3k), Jonathan Irvin GUNAWAN b)} for some a < b. 3We canthe partition Ftheorem, into we 3isisthat From From the above above theorem, we conclude conclude that aa MIN-VERTEX-COVER MIN-VERTEX-COVER can can be be easily easily constructe n the beginning of this section, we assume wepossible. know that MIN-VERTEX-COVER is aencounter NP-hard Itisconstructe isnecessary good good to to know know as as many many NP-hard NP-hard problem problem as as possible. good to This This know necessary necessary as many NP-hard so so that that ififproblem we we encounter as possible. aaproblem. new new This problem problem X, X, we we b−a−2 Jonathan Irvin GUNAWAN b − a − 2 me sum, as for every 0 ≤ k ≤ If If S S ⊆ ⊆ V V is is a a VERTEX-COVER VERTEX-COVER of of graph graph G(V, G(V, E), E), then then V V − − S S is is an an INDEPENDENT-SET INDEPENDENT-SET of of the the MAX-INDEPENDENT-SET. MAX-INDEPENDENT-SET. 3 by the construction of the function. dn to many problem possible. This that if X, we encounter a new problem X, we bof −≤ aNP-hard −NP-hard 2 bisreduce −necessary a −of 2itit the Jonathan Irvin as GUNAWAN can can use useas any the the NP-hard problems that that we we know, know, can use reduce any to tosoproblem problem NP-hard X, problems and and thus thusthat prove prove wethat that know, XX is reduce is also also NP-hard. it NP-hard. to prob }.problems + 2GUNAWAN +know 3k), 0any ≤ kof 3k), 0 ≤ k ≤ }3 ∪ {f (a + 1 + 3k), 0 ≤ k ≤ } E) E) use any of the NP-hard problems that we know, reduce it to problem X, and thus prove that X is also NP-hard. 3 3 11We 1 f (a 3k)problem + f (aXX+isis1reducible + 3k) =to (a + 2 Y + We say say+ that that problem reducible tofproblem problem Y 3k)We say that problem X is reducible to problem Y the the beginning beginning of of this this section, section, we we assume assume we we know know that that MIN-VERTEX-COVER MIN-VERTEX-COVER isis aa NP-hard NP-hard −In a≤ − 2b−a−2 um, as for everysimilar 0b ≤ kIn proof proof isisthat actually actually to to the the previous lemma. lemma. Let Let us us assume assume that that VV − −SS isis not not aa INDEPENDENT-SET. INDEPENDENT-SET. We X is reducible to problem Y }.3previous 2 +say 3k), 0 problem ≤ k ≤similar good good3 to to know know as as many many NP-hard NP-hard problem problem as as possible. possible. This This isis necessary necessary so so that that ifif we we encounter encounter aa new new here here are two vertices vertices A, B ∈∈3k) VV − − SSfand and+there there isis an an edge edge connecting connecting A A and and B. B. Since Since A, A,B B ∈∈ VV − −S, S, fare (atwo + 3k) + fcan (aA, + 1Bany + = (a 2 + problems 3k) can use use any of of the the NP-hard NP-hard problems that that we we know, know, reduce reduce it it to to problem problem X, X, and and thus thus prove prove that that XX ii b−a−2 B B /∈ /as S. S.for As Asevery A A and and B Bkare are connected by by an an edge, edge, we we note note that that SS isis not not aa VERTEX-COVER. VERTEX-COVER. This This isis aa m,∈ 0≤ ≤ connected 3 11We We say that that problem problem XX isis reducible reducible to to problem problem YY n. n. Therefore Therefore VV − −SS isis an ansay INDEPENDENT-SET. INDEPENDENT-SET. ICPC World Finals 2010 Solutions n.d.). at problem. we use tosolvable find all possible paths (ACM to be in polynomial time using the reduction ofgiven the original problem (withemadditional constraint), and check whether the proof stillproof holds the additional constraint to the problem. onstraint), and check whether the proof still holds given the additional constraint toIfthe re that we can2 get Accepted by only "hacking" a complete search algorithm. Therefore, we through ollowing formula 2 Identifying Identifying Intractability Intractability of a Problem of a Problem through Reduction Redu is impossible to visit the rest of the unvisited points, then we can prune the path and int), and check whether the proof still holds given the additional constraint to the problem. causes ainproblem to be solvable in polynomial time using the reduction proof of the original problem (withchnique detail. wever, it is not very suitable for IOI. Usually, IOI problems require deep analysis from e one will example give we one ofwhether a in special inproblem. a NP-hard problem. Suppose we havewith a function with the editional of a example special case a NP-hard Suppose weadditional have a function the problem. constraint), and check thecase proof still holds given the the We likewould to know likeonly that to know the problem that that problem we are that attempting we are attempting unlikely unlikely havetoan to immediate have an immediate solution. solu The 1,athe n= 1is∨ n = constraint 2is to at weformula canwould getaWe Accepted by "hacking" complete search algorithm. Therefore, we example of special case in a NP-hard problem. Suppose we have a function with the ing f (n) = Understanding Unsolvable Problem 93 most common most common way is to way apply is to a well-known apply a well-known technique technique called reduction. called reduction. Suppose Suppose we know we that know problem that pro X i Finding Small f (n − 1) + f (n − 2), n > 2 ue in detail.3.3by the construction of theConstraints function. case of 1 1 l give we oneimpossible example asolve, special in a know NP-hard problem. Suppose we have ausing function with the impossible to solve, to and we also and know we also that we can that solve we can problem solve X problem by using X problem by Y problem as a black-box Y as a black-box . If we can . by the construction of then function. by construction of the bysequence the construction of time the function. ∞ function. 1, 1∨ = 2first 1, n =define 1then ∨solve n F= 2n ) SUBSET-SUM algorithm running for various input sizes. This the We consider the = {f , and weX (N )= well. to bebe the ofimpossible F We impossible want to know NP-hard with large Ncan that is impossible to exponentially (e.g.NY Nterms > 50). Theorem 2.FIf = is(n)} divisible by three, can partitioned two multisets ormula n=1 fwe (n) fthe (n)function. = solveproblem problem Y, problem then Y, then solve we can problem solve problem as well. X Therefore, as Therefore, problem problem isinto also is .also to solve. to solve Theorem 2. If N is divisible by three, then F (N ) can be partitioned into Y two multisets of equal sum. nstruction of solve by the construction of the function. by the construction of the function. 1, n = 1 ∨ n = 2 3.3 Finding Small Constraints f N on a MacBook Pro (Retina, 13-inch, Early 2015) f (n − 1) + f (n − 2), n > 2 fpartition (n −N 1) + fSUBSET-SUM (n 2), n >algorithm 2then hether can asum. of Fthat (N−function. )may into two disjoint A suchproblem that the sum allpartitioned elements ofcreate equal also lookwe small constraints For acan SUBSET-SUM N N/2 Theorem 2.example, IfF N is)) can divisible by then F (N ) canof be int by the of the Theorem 2. IfIf by three, (N be partitioned into two multisets of equal f for (n) = Theorem 2. N is divisible byhelp. three, then Fmultisets (N beand partitioned into two multisets of equal sum. sum. omparison ofother O(2 )construction and O(2 ) divisible running time forBthree, various input sizes. This is by construction of the function. fthe (n −the 1) + felements (n − 2), n > 2 by the construction of the function. by construction of the function. by the construction of the function. nrd A is equal to the sum of all in B problem, and will not be solvable with N = 100. When we are given the constraint that ∞ Proof. If N is divisible by three, then F (N ) is a prefix of F with length multiples of three. By lemm 2. If N is divisible by three, then F (N ) can be partitioned into two multisets of equal sum. 1, n = 1 ∨ n = 2 ∞ Theorem 2. If N is divisible by three, then F (N ) can be partitioned into two multisets of equal by the construction of the function. Theorem 2. Ifthen N isthe divisible by three, F> (N ) problems can partitioned into two mult is run 100 times for each value N, and on a(N MacBook 13-inch, Early 2015) nsider the F = we define FPro (N )(Retina, the first terms of F .be We want totoknow We=sequence are using We are NP-hard using problems NP-hard problems for illustration. for Recall Recall NP-hard that problems NP-hard have yet to have be of yet solved be in polynomia solved in p quence F {fProof. (n)} ,N and we define F three, ) to to beillustration. first Nabe terms ofthen FN We want tomultiples know rd problem with large that isof impossible solve exponentially (e.g. 50). If {f is=(n)} divisible by to isthat prefix of .N with length n=1 fN (n) 2 length Proof. Ifof N(N is))F divisible bybe three, then Finto (N multiples )multiples is amultisets prefix F equal with length Theorem 2. is Ifdivisible N isn=1 divisible by three, can partitioned two of sum. Proof. IfIf by three, then F is aa )prefix of F of three. By Proof. N is[0, divisible by three, then Fthen (N is(N prefix of F with with length of of three. By lemma lemm ∞ the array are small (e.g. 100]), this problem can be solved using O(N X )to Dynamic can be partitioned into two multisets equal sum.. f (n − 1) + f (n − 2), n > 2 eer F = {f (n)} , and we define F (N ) to be the first N terms of F . We want know polynomial time using the reduction proof of the original problem (withwe can create a partition of F (N ) into two disjoint multisets A and B such that the sum of all elements three. By lemma 3, can be partitioned into two multisets of equal sum. time for more time for than more 4 decades. than 4 decades. MIN-VERTEX-COVER MIN-VERTEX-COVER is a graph is problem a graph that problem involves that finding involves a finding minimum a minimu subse ate a partition of F (N ) into two disjoint multisets A and B such that the sum of all elements ook for other small constraints that may help. For example, a SUBSET-SUM problem Theorem If N divisible bypartitioned three, then (N )be can be partitioned into of equa n=1 Theorem 2.can IfF N is))F by three, then F (N )two besum. partitioned Theorem 2. N is)divisible divisible by three, Fsum.. (N can be partitioned into two multisets of three. equal sum Theorem 2. IfIfN N is by three, then (N can partitioned into two multisets of equal sum Nfunction. isthe divisible by three, then F2. (N istwo aisIfproblem. prefix of multiples of By lemma 3,can Fmultisets (N )of Ifelements is then F (N )problem isdivisible a prefix of length Byin Theorem 2. be IfProof. N isthe divisible bydivisible three, then (N )then be partitioned into two multisets of equal can beFF into two ofprefix equal sum.. Proof. Nby isthree, divisible bylength three, then Fmultisets (N )three. isF awith of F multiples with length multiples can be partitioned into multisets of equal can be partitioned into two multisets ofwith equal sum.. looks like classic PARTITION PARTITION isthe NP-hard by reduction from SUBSETX isThis upper bound of inside the array. Even though the running time of the then Fnodes (N )will can partitioned into two multisets of equal sum. partition ofthe Fcan (N )aholds into two disjoint multisets Athen and Bequal such that the sum of allin elements ther the proof still given the additional constraint to the problem. s equal to sum of all elements in B of of such nodes that such for every that for edge, every at least edge, one at least of its one endpoint of its endpoint is in subset. is the MAX-INDEPENDENT-SET subset. MAX-INDEPENDENT is a e sum of all elements in B oblem, and not be solvable with N = 100. When we are given the constraint that Proof. If N is divisible by three, F (N ) is a prefix of F with length multiples of three. By lemma ∞ then F (N ) be partitioned into two multisets of sum. 3.the If N ≡ 1 be (mod 3), F (N ))to bebeof partitioned into two multisets of(withequal sum. er the F = {f (n)} ,can and we define Fusing (N to be the first Nofconstraint. terms of FAnother . We want to know artitioned intoofTheorem two ofalgorithm equal sum.. asequence problem toofmultisets be solvable in polynomial time the reduction proof ofalgorithm the original problem nto two multisets sum. Theorem 3. If , three, cannot cannot partitioned into two multisets of can be partitioned into two multisets of equal sum.. into two multisets equal sum.. n=1 UM. Therefore, aequal large value of N ,ispartitioned it is unlikely be able to an that finds A Bfunction. inBy anlengt lauses tothe the size the input, still fast enough for the given sible by three, then F (N )100]), can be partitioned into two multisets equal sum. Proof. If N isthe divisible by then F (N )partitioned isO(N afind prefix of F with length multiples of three. By 2 by the construction the Proof. Ifnodes N is divisible by three, then F (N )of isbe aone prefix of F with Proof. N is divisible by three, then F (N is aF prefix of F with length multiples ofand three. By lemm Proof. IfIf N is divisible by three, then F (N ))of is a≡ prefix of F with length multiples of three. lemm by the construction of the function. by construction the function. by construction of the function. of all elements infor B graph problem graph of problem finding of a finding maximum a maximum subset of subset such nodes that such for every that for edge, every at most edge, at most of its one endpoint of its endp is in Proof. If N is divisible by three, then F (N ) is a prefix of with length multiples three. By lemma 3, F (N array are small (e.g. [0, this problem can be solved using X ) Dynamic Theorem 3. If N 1 (mod 3), F (N ) cannot partitioned into two m can be partitioned into two multisets of equal sum.. Theorem 3. If N ≡ 1 (mod 3), F (N ) cannot be into two multisets of equal sum. the construction of the function. Theorem 3. If N ≡ 1 (mod 3), F (N ) cannot be partitioned into two multisets of equal sum. efficient aHowever, partition ofofFN (N into two disjoint multisets A and Bexample, the sum all elements equal sum. Fcan (N))create isway. a prefix prefix ofand F check with length multiples ofstill three. By lemma 3, Fsuch (N )that itional constraint), whether the proof holds given the additional constraint toNofFthe problem. this sequence is defined in athat very special way, in the sense that is defined using the not F (N nique is when the value is)inside too large (e.g. N < 40). For while O(2 )elements. F (N is a≡ of F with length multiples of three. By lemma 3, )contains can be partitioned into two multisets of equal sum.. n. can be partitioned into two multisets of equal sum.. can be partitioned into two multisets of equal sum.. can be partitioned into two multisets of equal sum.. Proof. Suppose F (N ) = F (N ) − f (1). Note that F (N ) N − 1 Since N ≡ 1 (m 3. If N 1 (mod 3), F (N ) cannot be partitioned into two multisets of equal sum. l case in a NP-hard problem. Suppose we have a function with the th multiples of three. By lemma 3, F (N ) Theorem 3. If N ≡ 1 (mod 3), F (N ) cannot be partitioned into two multisets of equal sum. his looks like a classic PARTITION problem. PARTITION problem is NP-hard by reduction from SUBSETthe subset. the Suppose subset. we Suppose already we know already that know MIN-VERTEX-COVER MIN-VERTEX-COVER is a NP-hard is a NP-hard problem. problem. Therefore, Therefore, we can show we can be partitioned into two multisets of equal sum.. a classic PARTITION problem. PARTITION problem is NP-hard by reduction from SUBSEThe upper bound of the elements the array. Even though the running time of the Theorem 3. If N ≡ 1 (mod 3), F (N ) cannot be partitioned into two multisets of e yis three, then F (Nall is a3. prefix of F1 )can, with length multiples ofby three. By lemma 3, FNMiddle (N )1of ual to the sum of elements in B of equal sum.. three, Fdivisible Theorem 2. Ifthen Nsum. is by three N/2 ≡ = Theorem 2. If N istwo divisible by three, (N ) can be part (N Theorem 2. If N is)divisible divisible by three, then F(N (N )fis can be partitioned into two multisets equal sum. Theorem 2. If N divisible then F (N )two can be partitioned into two multise Proof. Suppose F (N ) F (N ) − f (1). Note that F (N ) contains N − forementioned recurrence. Therefore, we should inspect recurrence formula more closely. Theorem If N (mod 3), F (N ) cannot be partitioned into multisets of equal sum. the Proof. Suppose F (N = F (N ) − (1). Note that F (N ) contains − elements. Since N ≡ 1 (m unlikely to run in one second, we for instance, use a O(2 ) Meet In The Proof. Suppose F (N ) = F (N ) − f (1). Note that F ) contains N − 1 elements. Since N ≡ 1 (m heorem 2. If N is by three, then F ) can be partitioned into multisets of equal f equal sum.. Proof. Suppose . Note that contains elements. n. haveN − 1 ≡ 0 (mod 3). By lemma 3, F (N ) can be partitioned into two multisets of equal sum. The sic PARTITION problem. PARTITION problem is NP-hard by reduction from SUBSETTherefore, for aoflarge of3.NIfis,case itstill is≡ unlikely to be able to find an algorithm that finds Awith and the Bofin an sum. that that MAX-INDEPENDENT-SET is also aNP-hard NP-hard is also aproblem. NP-hard problem by problem reducing by reducing ahave MIN-VERTEX-COVER aB MIN-VERTEX-COVER problem into probla or asize large value N ,sum.. itvalue is unlikely be able to find an algorithm that finds and in multisets an he ofMAX-INDEPENDENT-SET the input, the algorithm fast enough the given constraint. Another one wo multisets equal (mod 3),into Theorem N 1two (mod 3), cannot be partitioned into two equal give we example of a1fSuppose special in we a)N function N hree, then Fof )Fcan partitioned multisets sum. Theorem If)F N ≡ 13). FA (N cannot be partitioned into two m Theorem 3. N ≡3), 13). (mod 3), F)F(N (N )F cannot be partitioned into two multisets ofbe equal sum. Theorem 3. IfIfWhile N ≡ 1to 3), F )for cannot be partitioned two multisets of equal sum. 3. rtitioned into two multisets of equal sum. of uppose Flike (N )(N = (N )be −elements Note that (N contains − 1be elements. Since ≡ 1)F)can (mod 3), we Proof. F (N )have = Fstill (N )sum. − (1). Note that FA (N )elements contains − 1sum. elements. Since N ≡ Theorem 3. If N ≡ (mod F (N )aF cannot be partitioned into two multisets equal haveN − 1F ≡ (mod By lemma 3, Ftwo (N be partitioned into tw Proof. Suppose (N )f(N =0)equal (N )Suppose − (1). Note that Fof (N contains N − 1sum. element N/2 equal problem SUBSET-SUM. O(2 is exponential to N ,fpartitioned it isof much faster than haveN − 11sequence ≡ 0(1). (mod 3). By lemma 3, F (N can into multisets of equal The Since ,into we .(mod By lemma 3, is(N can haveN −all ≡ 0not (mod By lemma 3, (N )N can be partitioned into two multisets of sum. The Nin sum of in F (N ) is even. However, the sum all in ) = F (N ) + f (1), wh arge value of N , it is unlikely to be able to find an algorithm that and B an ))ever, cannot be partitioned into two multisets of equal too finds Proof. If N divisible by three, nt way. However, this is defined in a very special way, in the sense that F is defined using the MAX-INDEPENDENT-SET MAX-INDEPENDENT-SET problem. problem. this sequence is defined in a very special way, in the sense that F is defined using the is when the value of N is large (e.g. N < 40). For example, while O(2 ) Proof. If N is divisible by three, then F (N ) is a prefix of F(m w Proof. If N is divisible by three, then F (N ) is a prefix of F with length multiples of three. By lemma 3, F (N )then Proof. If N is divisible by three, then F (N ) is a prefix of F with length multiples of Any consecutive subsequence of F with length multiples of three can be partitioned into two multisets emma 3. Proof. Suppose F ) = F (N ) − f (1). Note that F (N ) contains N − 1 elements. Since N ≡ 1 (N oof. If N is divisible by three, then F (N ) is a prefix of F with length multiples of three. By lemma 3, F (N ) cannot be partitioned into two multisets of equal sum. oks like a classic PARTITION problem. PARTITION problem is NP-hard by reduction from SUBSEThree, then F (N ) can be partitioned into two multisets of equal sum. ormula N 1of≡N 03), (mod 3). By lemma 3, F (N )F can partitioned into two of equal sum. Therefore, multisets of equal sum. haveN 1very ≡ (mod 3). By lemma 3,equal FTherefore, (N )multisets can be into two equal sum of all elements F )F is even. However, the sum of all elements haveN −multiples 1))way, ≡ 0using (mod 3). By lemma 3,defined (N can be partitioned into multisets partitioned into two multisets of equal sum. the sum of all elements in twice (N partitioned that can solve is the range of N aaformula O(2 )partitioned solution. sum of all elements in )be is However, the of all elements in (N = F (N )of + ff(1), wh in the 0 sum of all elements in F (N is However, the sum of all elements in F (N )multisets = F (N )contains +Since (1), wh we (N by the construction the function. nSuppose = 1− n = 2special mod F (N cannot be partitioned two multisets of sum. because F (N )= is even while fsum (1) isinto odd. Therefore, there is no to partition F (N ). Proof. Suppose F (N = F (N )(1). − (1). Note that F (N ))1can contains − 1)equal elements. N ≡− this sequence defined in a∨ in the sense that Fsum is using the of N/2 f be partitioned into two multisets mentioned recurrence. Therefore, should inspect the recurrence formula more closely. then F (N )itaSuppose is ais prefix of F with length three. By lemma 3, F (N )way Proof. Suppose F (N )F = F )− − felements. (1). Note that FN )1two Proof. Suppose F (N )of = F (N )even. − Note that (N )(N contains N − 1F elements. Since N ≡ The (m Proof. F (N )into = (N )even. − ffof (1). Note that F (N )into contains N − 1N elements. Since N ≡ 11N (m urrence. Therefore, we should inspect the recurrence more closely. ikely to run in)multiples one second, we can, for instance, use O(2 Meet In The with length three. By lemma 3, can be two multisets of sum.. can be partitioned into two equal sum.. can be partitioned two of equal sum.. frefore, equal sum. Proof. F (N )all F (N )unlikely − fF (1). Note that F≡ ))an contains N Since ≡ (mod w haveN − 1of ≡ 0multisets (mod 3). By lemma 3, F (N )(N can be partitioned into two of(N equal into Middle be partitioned two multisets of equal sum.. sum.3), for large value of N ,elements it is to be able to find algorithm that finds Amultisets and B in an elements multisets of ln). elements in F ) is even. However, the sum of all in F (N ) = F (N ) + f (1), which is odd 1). Note that F (N ) contains N − 1 elements. Since N 1 (mod 3), we sum in F (N ) is even. However, the sum of all elements in ) = F (N ) + f (p is even. However, the sum of all elements in , which is because F (N ) is even while f (1) is odd. Therefore, there is no way to (N sum of all elements in F (N ) is even. However, the sum of all elements in F (N ) = because F (N ) is even while f (1) is odd. Therefore, there is no way to partition F (N ). by the construction of the function. because F (N ) is even while f (1) is odd. Therefore, there is no way to partition F (N ). more N/2 Note that F (N ) contains N − 1 elements. Since N ≡ 1 (mod 3), we haveN − 1 ≡ 0 (mod 3). By lemma 3, F (N ) can be partitioned into two multisets of equal sum ce. Therefore, we should inspect the recurrence formula closely. hen F (N ) is a prefix of F with length multiples of three. By lemma 3, F (N ) sets of equal sum.. haveN − 1 ≡ 0 (mod 3). By lemma 3, F (N ) can be partitioned into tw haveN − 1 ≡ 0 (mod 3). By lemma 3, F (N ) can be partitioned into two multisets of equal sum. Th We will first We prove will first the prove following the following two lemmas. two lemmas. haveN − 1 ≡ 0 (mod 3). By lemma 3, F (N ) can be partitioned into two multisets of equal sum. Th em SUBSET-SUM. O(2 ) (N is still tobe N∨partitioned , nitthe is faster than n − 1) + f (n − 2), nisWhile > 213).is −F(N 1Theorem elements. Since N ≡ haveN −be 1this ≡ 0sequence By lemma 3, Fexponential (N )(1) can be partitioned into two of equal sum. Therefore, th (mod sum all elements F )while is even. However, the sum of all elements in to F (N )two =≡ F ) +). f3), (1),F (N wh 1,two n = 1to = 2much like N ay. However, defined inwith very special way, in sense that F is defined using the Ifof N divisible by three, then F (N ))multiples can two multisets equal sum. while Any subsequence of Fwe length of three can partitioned into multisets ma 3. = (N )is)−can fconsecutive (1). Note that Finto (N )≡ contains N − 1 elements. Since N ≡ 1into (mod 3), we Theorem 4. If 2is (mod 3). F (N can be partitioned into two multisets of equal sum. subsequence of F with length of can be partitioned into two multisets F ) Pick even while f1(mod is= odd. Therefore, there is no way partition F≡ (N ). ,nsecutive (N partitioned multisets of equal sum. Therefore, the odd because in is3), even length is odd. Therefore, there is no way partition because Fsubsequence (N )(N even f≡ is odd. there ismultisets no way to partition F (N Theorem 3. Ifin N 1)(N (mod because Faof (N )be is even while fTherefore, (1) is Therefore, there is no way partition F Theorem 3. If N 1be (mod 3), Fwe (N )of cannot be partitioned i( F Theorem 3. If2. N ≡ (mod 3), F )F cannot partitioned into two multisets of equal sum. any consecutive with multiples of three, which will denote by F = roof. odd. to multiples multisets N Theorem 3. If N 1three (mod 3), F (N )the cannot be partitioned into two of equ f(1) (n) heorem 3. Ifsolve N ≡ 1 (mod 3), F (N ) cannot be partitioned into two multisets of equal sum. ,ets F of (N )can can be partitioned into two multisets of equal sum. Therefore, the 3.4 Finding Special Cases sum all elements in F (N ) is even. However, sum of all elements F (N = F (N ) + f equal sum.. range (N of sum of all elements in F (N ) is even. However, the sum of all elements sum of all elements in (N ) is even. However, the sum of all elements in F (N ) = F (N ) + f (1), w sum of all elements in F (N ) is even. However, the sum of all elements in F ) = F (N ) + f (1), w that it is twice the of N using a O(2 ) solution. wo multisets of equal sum. Therefore, the sum of all elements in F (N ) is even. However, the sum of all elements in F (N ) = F (N ) + f (1), which is od Theorem 4. If ≡know 2then (mod 3). F (N )− can be partitioned intomultisets twoofmult because F (N )Sinto is while ff3). (1) is (N odd. Therefore, there no way tothen partition F is (N ).sum. F Theorem 4. If N ≡ 22N (mod F (N )) + can be partitioned into two multisets of equal Theorem 2. If+ N is divisible by three, Fis (N )closely. can be partitioned into two o( Theorem 4. If N ≡ (mod 3). (N can be partitioned into two multisets of equal sum. recurrence. Therefore, we should inspect the recurrence formula more E), tive subsequence of F with length multiples of three can be partitioned into two multisets feven (n − 1) (n − n > 2Nto we define Fsum )of be the first terms of F We want ual sum. By lemma 3, Ff(N (N )to can be partitioned into two multisets of equal sum. Therefore, the .of However, the all elements in F (N ) = F ) f (1), which is odd F (N ) cannot be partitioned two multisets of equal sum. Lemma 1. Lemma 1. If S ⊆ V If is an ⊆ INDEPENDENT-SET V is an INDEPENDENT-SET of graph of G(V, graph G(V, then E), V S is V a − VERTEX-COVER S a VERTEX-COV the dand into two multisets equal sum. .2), foned (a), f (a + 1), (a + 2), ...f (b)} for some a < b. We can partition F into (N sum elements in F (N )4. = F ) B. + fSince (1), which isof odd (N because F (N is(1). even while f3). (1) is odd. Therefore, is no way to partition F= (NFF ). If=2N by then F (N )Therefore, is a≡ prefix ofcan F with length multiples of three. By lemma 3, is there Fway F (N )contains isSuppose even while fiselements. (1) odd. Therefore, there no to because FF (N is even while (1) isto odd. Therefore, there no way to partition F (N ). because F (N )f)which is even while fffbecause (1) is odd. Therefore, there way to partition F ). divisible Proof. (N now Proof. Assign (1) A and (2) f−isbe (1) = f− we are partition (N 4. If N (mod 3). (N ))three, can be partitioned into two multisets sum. sHowever, inProof. F (N )≡the F (N )Theorem + fno (1), is odd 4. If N ≡ 2Note (mod F (N )(N partitioned into multisets equal sum. Proof. Suppose F (N )multisets (N )F − f) )(= IOI, because F (N )of is while f)to (1) is odd. there to partition F (N ).into )3). Theorem Ifthat N 2= FN (N )equal can be partitioned two of equ (N )no = F (N )Since − (1). Note that (N ) con Suppose F (N )all = F (N )− fall F (N )paper. N 1is N≡≡ 1of (mod 3), we Proof. Suppose Fin (N )(N F (1). Note that Ftwo (N )ftrying contains N − is13), elements. ble approach in and thus is− main focus of this To solve IOI 2008 Island nto disjoint multisets A and B such that the sum of all elements oof. Suppose Fthere (N ){f =even F (N fthe (1). Note that FFAssign contains −F 1(2), elements. Since N 1to (mod we (N )two is even. However, the sum of elements (N ))(mod = F (N )fno + fway (1), which is odd FProof. (N )Therefore, cannot be partitioned into two multisets of equal sum. dd. is way to partition F (N ). ∞ graph G(V, graph E) G(V, E) are no we denote Proof. f (1) to A and f (2) to B. Since f (1) = f (2), Theorem 4. If N ≡ 2 (mod 3). F (N ) can be partitioned into two multisets of equal sum. Any consecutive subsequence of F with length multiples of three can be partitioned into two multisets .onsecutive r the sequence F = (n)} , and we define to be the first N terms of F . We want to know Proof. Assign f (1) to A and f (2) to B. Since f (1) = f (2), we are now trying to partition F (N ) = Theorem 4. If . can be partitioned multisets of equal Proof. If N is divisible by three, then F (N ) is a prefix of F with length multiples of thre dd. Therefore, there is no way to partition F (N ). Proof. Assign f (1) to A and f (2) to B. Since f (1) = f (2), we are now trying to partition F (N ) = can be partitioned into two multisets of equal sum.. Pick any consecutive subsequence of F with length multiples of three, which we will by F = n=1 subsequence of F with length multiples of three, which we denote by Fthe bfind − aa2− 23). blemma − a 1obtain − 2= f(mod (1) −3). fapproach. (2). F (N )We will have N − elements. Since N 2will (mod 3), we N − ≡ 0By (mod 3). partition F− ). haveN − ≡3, 0function. 3). lemma − f (1). Note F (N ) Since contains N − 12≡ elements. Since Nlemma ≡ 1be (mod 3), we by the construction of 1 ontains 10that elements. ≡ (mod 3), we haveN − 1≡ ≡ 0partitioned (mod By F(mod (N ) 2equal can be partition −1N 1≡ ≡ (mod 3). By 3,1− F (N )can can be partitioned into two multisets equal sum. Therefore, the mu 3.4 Finding Special Cases haveN 0to (mod By 3, F≡the (N )3). can be partitioned into two multisets of3 we need to use this must special constraint in problem such BhaveN veN − 0(N By lemma 3, F (N )(mod be partitioned into two multisets of equal sum. Therefore, the hile fTheorem (1) is odd. Therefore, there is no way partition F (N ). Theorem 4. Ifpartitioned N ≡ 3). F (N )A can into two multisets of sum. be Theorem 4. If N 2B (mod 3). F (N )of be partitioned into two Theorem 4. Iflemma NN ≡ (mod 3). F (N can be partitioned into two multisets of equal sum. Theorem 4. If N ≡ 22≤ (mod 3). F (N )})we can partitioned into two multisets of equal sum. A = {f (a + 3k), 0 k ≤ ∪ {f (a + 1 + 3k), 0 ≤ k ≤ } can ssign f (1) to A and f (2) to B. Since f (1) = (2), are now trying to partition F (N ) = F (N ) − Proof. Assign f (1) to A and f (2) to B. Since f (1) = f (2), we are now trying to partition F 4. If N ≡ 2 (mod 3). F (N ) can be partitioned into two multisets of equal sum. f (1) − f (2). F (N ) will have N − 2 elements. Since N ≡ 2 (mod 3), we Proof. Assign f (1) to A and f (2) to B. Since f (1) = f (2), we are now trying to um. can create a partition of F (N ) into two disjoint multisets and such that the sum of all elements sum. f (1) − f (2). F (N ) will have N − 2 elements. Since N ≡ 2 (mod 3), we obtain N − 2 ≡ 0 (mod 3). can be into two multisets of equal sum.. f (1) − f (2). F (N ) will have N − 2 elements. Since N ≡ 2 (mod 3), we obtain N − 2 ≡ 0 (mod 3). utive subsequence FF length multiples of we will denote by F with even. ,aum (a + 1), f(b)} for some aHowever, < b. We can partition F into 2), ...f some acontains < b. We can partition Fthree, into a which 3,+for F2), (N ) (N can be partitioned into multisets of equal which our theorem. 3two 3of − (1). Note Fof (N )(b)} N − 1 elements. Since N ≡ 1elements (mod 3), we )ff+ can be partitioned into two multisets of equal sum. sum of all elements inwhich Fthe )(N is (N ma 3, F (N )(athat can be partitioned into two multisets of equal Therefore, the Proof. Proof. Let us assume Let us that assume V − that S is not − S athe VERTEX-COVER. is not VERTEX-COVER. Therefore, Therefore, there are two are two A, vertices B ∈ /odd V)even. A, − BF S oned two multisets of equal sum. Therefore, the sum of in F(N (N )implies is sum of ofinto all elements in...f (N )fis is even. the sum of all elements in F(N )= = F (N (N )+ +fHowever, fvertices (1), sum all elements in F (N )sum. isall However, the sum all elements in(N Fis = ows problem to be solvable in polynomial time. We can check whether additional Proof. Assign (1) and fN (2) to B. Since feven. (1) = fsum, (2), we are now trying to partition F )all = be m of all elements F even. However, sum of all elements in F F )there (1), which odd )2). can partitioned into two multisets of equal of Theorem 3. If N ≡ 1− (mod 3), FA (N )V cannot be partitioned into two multisets of equal sum. sum. in F Fthe (N )for will have N − 2)We elements. Since ≡ 2N (mod 3), we obtain Ninto −which 2an 0multisets (mod 3). By lemma ultisets of equal sum. pproach IOI, and thus is the main focus of this paper. To solve IOI 2008 Island fbe (1) fAssign (2). Fto (N )two will have −equal 2to elements. Since N ≡ 2)≡ (mod 3), we obtain N −iswhich 2obtain ≡ 0F (mo Theorem 2. If N is divisible by three, then (N ) 3, F (N ) can be partitioned two of equal sum, f (1) − f (2). (N ) have N − 2 elements. Since N ≡ 2 (mod 3), we N al to the sum of all elements in B in 3, F (N ) can be partitioned into two multisets of equal sum, which implies our theorem. 3, F (N ) can be partitioned into two multisets of equal sum, implies theorem. our will impl b − a − 2 ), ...f (b)} some a < b. can partition F into mod 3). F (N ) can partitioned into multisets of equal sum. Proof. f (1) to A and f (2) B. Since f (1) = f (2), we are now trying to partition ma 3, F (N ) can be partitioned into two multisets of sum. Therefore, the because F (N ) is even while f (1) is ven. However, sum of all in F (N )Since F (N )B + fno (1), which is odd Assign fno to A and to Since fby (1) = f≡ (2), weF are Proof. Assign f)a2elements (1) A0with and f≡is (2) to Since (1) = (2), we are now trying to partition F (N )no− and is an there edge isF connecting an connecting A and B. A Since and A, /(1) VF A, − B S, ∈ /≡ we V have − S, A, we B ∈ S. A, As Bnotwo A ∈ S. and As B A are connected B are cs Proof. Assign f(N (1) to A and f≤ (2) to B. Since ffway (1) ffpartition (2), we are now trying to (N all elements in Fthe (N )problem = (N + (1), odd because (N )= is even while fB. (1) is odd. Therefore, there is(N Proof. Assign f23k), to and (mod to . 3), Since ,(2) we are now trying to because Fthere (N iseven even while fisedge (1) is odd. Therefore, there to F (N ). because F (N )Proof. even while f∈ (1) is odd. Therefore, there is way to partition F kcause any consecutive subsequence length multiples of three, which will F = Proof. Assign f3, to A and ftoF (2) to B. fB. (1) = f(N (2), we are now trying to partition Fpartition (N = F (N ))n f)is (1) − f(1) (2). F )isof will N − 2= elements. Since N 2whether (mod 3), we obtain N − 2theorem. 0)and (mod 3). b which − a − 2sum, bwe − ahave − 2denote blem. PARTITION NP-hard by reduction from SUBSET is }. B = {f (a + + ≤ k F (N )and while f (1) odd. Therefore, there is way to partition F (N ). b − − b − a − 2 Theorem 3. If N 1 F ) cannot be partitioned into multisets of equal two have Therefore, solving this problem is reduced to checking N ≡ 1 (mod 3). We can solve this can be partitioned into multisets of equal which implies our theorem. B. Since f (1) = f (2), we are now trying to partition F (N ) = F (N ) − eed to use this approach. We must find a special constraint in the problem such F (N ) can be partitioned into two multisets of equal sum, which implies our k F )San can be partitioned into two multisets equal sum, which implies our theo are (a + Aby {f (a 0note ≤ ≤ }+ ∪ {f + 1f(N + 3k), 0This ≤ ≤ }contradiction. 3felements. A {f (a + 3k), 0we ≤ ≤ }< ∪(N {f (a + 1− 3k), ≤ }− 3k), B. Since (1) = (2), we now trying tofNote partition (N )(1), F )≡ − F (N )an = F (N )f)partition − felements. fpartition (2). F0F (N )− will have N − 2a1− elements. Since N ≡ 22≡ (mod 3), we sum of all elements in F (N )− = F (N )≤ + which isk22Ifis odd Proof. Suppose F )will =be F (N )N − (1). contains elements. Since ≡ 12whether (mod 3), we there f )ven. is= odd. Therefore, is no way to F ). (2). F )equal will have N 2of elements. N 23). (mod 3), f= (1) − (2). F (N will have N(1) − 2that Since N (mod 3), we obtain N(mod −then ≡ (mod 3). by an edge, an edge, we that that S3, not is INDEPENDENT-SET. not an INDEPENDENT-SET. This contradiction. is Therefore Therefore − Slemm is Vowa1 partition . into will reduced Since fthe (1) − ff(N (2). F (N ))kis will have N 2(N elements. Since N ≡ (mod 3), obtain − ≡ 00V (mod 3). no way to partition Fknote (N ). 1), f(2) (a 2), ...f (b)} some a b. We can F now trying to partition F (N = F (N Proof. N is divisible by three, F (N )N is a(N b2(N − 2)3), bto a= − 2(N fHowever, −f+ fto (2). F )fafor have − 2− Since ≡ 2in (mod 3), we obtain N − 2Since ≡ 0N By whether Therefore, solving this problem to checking ≡ 3, F (N )− can partitioned into two multisets of sum, implies our theorem. s+ unlikely to be able to find that finds A and B an Therefore, solving this problem is reduced checking N ≡ 1a− (mod 3). We can solve this 3(1) 3elements. Therefore, solving this problem is− reduced to checking whether N ≡)we 1sum. (mod 3). We can solve this 3more 3have and f(1) to B. Since (1) = falgorithm (2), we are now trying toN partition F (N )which = Fequal (N We will provide examples of special cases in the following section. lements. Since N ≡ (mod we obtain N − 2 ≡ 0 (mod 3). By lemma he problem be solvable in polynomial time. We can check whether an additional Theorem 4. If N ≡ 2 (mod 3). F Theorem 4. If N ≡ 2 (mod 3). F (N ) can be partitioned into oks like a classic PARTITION problem. PARTITION problem is NP-hard by reduction from SUBSETTheorem 4. If 2 (mod 3). F (N ) can be partitioned into two multisets of f (a + 3k), 0 ≤ k ≤ } ∪ {f (a + 1 + 3k), 0 ≤ k ≤ } Theorem 4. If N ≡ 2 (mod 3). F (N ) can be partitioned into two multisets of equal b−a−2 heorem 4. If N ≡ 2 (mod 3). F (N ) can be partitioned into two multisets of equal sum. Proof. Suppose (N ) = F (N ) − f (1). Note that F (N ) contains N − 1 elements. Sin ements. Since N ≡ 2 (mod 3), we obtain N − 2 ≡ 0 (mod 3). lemma (mod 3). By lemma 3, F can be partitioned into sum, which implies is odd. Therefore, there is no way to partition (N ). haveN − 1 ≡ 0 (mod 3). By lemma 3, F (N ) can be partitioned into two multisets of equal sum. Therefore, the , we obtain . By lemma 3, can be parti 3, F (N ) can be partitioned into two multisets of equal sum, which imp 3, F (N ) can be partitioned into two multisets of equal sum, which implies our theorem. VERTEX-COVER. VERTEX-COVER. 3, F (N ) can be partitioned into two multisets of equal sum, which implies our theorem. bWe − a − 2provide fore, solving this problem is sum, reduced to2two checking whether N− ≡ 13the (mod 3). We can solve this in O(1). bthe − − we obtain N − 2≡ 0 provide (mod 3). Byas lemma Therefore, this problem is checking whether N≡ (mod We can solv A and BF− have the same for every 0we ≤ kdefined ≤ can be partitioned into two multisets sum 3, (N )We can be partitioned into multisets ofsum. equal sum, which implies our theorem. will more examples of special cases in1 the following section. Therefore, solving this problem is reduced to checking whether N3).≡of 1 equal (mod 3).o 3 into fined in awill very special way, in that F is using the will more examples of special cases in following section. We will more examples of special cases the following section. WAN 3find have N 2abe Since N,3k), 20asolving (mod 3), obtain Nreduced 2inchecking ≡ 0to (mod 3). By lemma multisets of equal sum, which implies our theorem. F= (N ) for can partitioned two multisets equal bsense − − 2(mod bcan − abe −N 2≡ }. B = {f (a + + ≤ kaof}. ≤ nto two multisets of equal sum. refore, large value oftwo N it≡ isis− unlikely toof be able to an algorithm that finds AF and B in anmultisets B {f (a + 2elements. + 3k), 0provide ≤ k2F ≤ solving into Therefore, this problem is reduced to whether 1 (mod 3). We can solve this haveN 1 ≡ 0 3). By lemma 3, F (N ) partitioned two of equ tioned into multisets equal sum, which implies our theorem. multisets of equal sum, which implies our theorem. sum of all elements in (N ) even. However, the sum of all elements in F (N ) = (N ) + f (1), which is odd bspecial a kf− 2 3to Atheorem. =examples {f (arecurrence +We 0−≤ ≤cases }following {f (a + 1and 3k), 0 are ≤ kB. ≤ Since }section. rovide more of in provide the section. plies will provide more examples of special cases innow the following Proof. Assign fF(mod (1) to AF and to We will more examples of special cases in the following section. Proof. Assign fG(V, (1) to A and f= (2) to Since fwhether (1) = fof (2), inspect the formula more closely. Proof. Assign f0(1) to3k), A and (2) B. Since fspecial (1) = f+ (2), we now trying to partition (N )We = F(N (N)solve )f−(2) − Proof. Assign f∪problem (1) to A fwe (2) to fF (1) f1INDEPENDENT-SET (2), we are trying to oof. Assign (1) to A and fsolving (2) to B. Since f3(a (1) = fcases (2), are trying to partition F (N ) .the =now ned into two ofTherefore, equal sum, which implies our theorem. solving this isway, reduced to checking whether N ≡ 1B. 3). We can solv F (NHowever, )our can befmultisets partitioned into two multisets ofof equal sum. }. fould (a + 2 + 3k), ≤ k ≤ Therefore, solving this problem is reduced to checking N ≡p Therefore, solving this problem is reduced to checking whether N ≡ (mod 3). can solve thi Lemma 2. Lemma 2. If S ⊆ V If is S a ⊆ VERTEX-COVER V is a VERTEX-COVER of graph of G(V, graph E), then E), V − then S is V an − S is an INDEPENDENT-SE the Therefore, solving this problem is to checking whether N ≡ 1 (mod 3). We can 3 3 reduced this ay. sequence is defined in a very in the sense that defined using this Theorem 3. If N ≡ 1 (mod 3), F (N ) cannot be Therefore, solving this problem is reduced to checking whether N ≡ 1 (mod 3). We can solve this in O(1). f (a + 3k) + f + 1 + 3k) = f (a + 2 + 3k) We will provide more examples special in the following section. Therefore, this problem is reduced to checking whether sum of all elements in F (N ) is even. However, the sum of all elements in F (N ) = F (N because F (N ) is even while f (1) is odd. Therefore, there is no way to partition F (N ). (mod Fof 3 educed to checking whether N ≡ 1 3). We can solve this in O(1). f (1) − f (2). F (N ) will have N − 2 e 2) to B. Since f (1) = f (2), we are now trying to partition F (N ) = (N ) − 4 Some example special cases ), we are now trying to partition F (N ) = F (N ) − b−a−2 f (1) − f (2). F (N ) will have − 2 elements. Since N ≡ 2 (m foned (1) − f (2). F (N ) will have N − 2 elements. Since N ≡ 2 (mod 3), we obtain N − 2 ≡ 0 (mod 3). By lemma b−a−2 f (1) − f (2). (N ) will have N − 2 elements. Since N ≡ (mod 3), we obtain N − b − a − 2 1) − f (2). F (N ) will have N − 2 elements. Since N ≡ 2 (mod 3), we obtain N − 2 ≡ 0 (mod 3). By lemma educed to checking whether N ≡ 1 (mod 3). We can solve this in O(1). B will have the same sum, as for every 0 ≤ k ≤ We will more examples ofin special cases insection. the following section. the same sum, as for every 0provide kcan ≤ We will provide more examples of special cases in the following section. We provide more examples of special cases in the the following section. graph G(V, graph E) G(V, E) We will provide examples of special cases in following section. inspect recurrence. Therefore, we0≤more should the recurrence formula more closely. with length multiples of three be into two multisets ≡sF 1 (mod 3). We can solve this in O(1). 3 We can solve this in . We will provide more examples of special cases the following 3partitioned odd. because F (N ) is even while f (1) is Therefore, there is no way to partition F (N ). 4 Some example of specia 4 Some example of special cases 4 Some example of special cases }. B = {f (a + 2 + 3k), ≤ k ≤ problem is reduced to checking whether N ≡ 1 (mod 3). We can solve this in O(1). )ial B.)3), Since fpartitioned (1) = (2), we are now trying to partition Fwhich (N )Proof. = Fpartitioned (N )our −of ial cases in the following 3,theorem. Finto )two be(N partitioned into two − 2FTheorem elements. Since 2section. (mod 3),(N we obtain N − 23,sum, ≡sum, (mod 3). By lemma (mod wethe obtain N≡ −≤ ≡ 03,b−a−2 (mod 3). lemma F0 (N )into be equal sum, w 3, (N )can can be partitioned into two of equal implies F )(N can be partitioned into two multisets equal sum, which our theore Suppose F(N (N )can =multisets F ) implies − of f (1). Note tha 3can ame sum, as for every 0f≡ k ≤ Fto (N be into two multisets of equal which implies our theorem. cases in following 4. If NN 2section. (mod 3). Fmultisets )By be two multisets of equal sum. 3 common We will provide more examples of−partitioned special cases in the following section. 4 Some example of special cases 4theorem. Some example of special cases 4three Some example of special We will look atfwhich some examples of= special cases that may occur inistwo competitive programming p mples ofimplies special cases in the following section. Irvin GUNAWAN case −,onathan 2 elements. Since N ≡ 2proof (mod 3), we obtain N ≡ 0 (mod 3). By lemma Any consecutive subsequence of F with length multiples of can be partitioned into multisets 3k) + f (a + 1 + 3k) f (a + 2 + 3k) two multisets offour equal sum, implies our Proof. Proof. The proof is actually is similar actually to similar the previous to the lemma. previous Let lemma. us assume Let us that assume V − S that not V − a S INDEPENDENT-SET is not a INDEPEND (a +The 3k) + (a + 1 + 3k) = f (a 2 + 3k) which theorem. haveN −partitioned 1special ≡ occur 0occur (mod 3). By lemma 3,of Fequal (Noccur ) sum can Theorem 4. ≡ 2checking (mod 3). F (Ncases )common can be into two multisets 4Ifk N≤We Some example of cases b−a−2 will look at some examples of special cases that may We will look at some common examples of special that may in competitive programming p We will look at some common examples of special cases that may in competitive programming p Therefore, solving this problem is Therefore, solving this problem is reduced to checking whet Therefore, solving this problem is reduced to whether N ≡ 1 (mod 3). We can solve this in O(1). will have the same sum, as for every 0 ≤ Therefore, solving this problem is reduced to checking whether N ≡ 1 (mod 3). W this problem is reduced toV checking 14 (mod 3). We can this inB. solve 3 flength (asolving +there 3k) +are fto (a +of 1vertices + 3k) = (a 24 +BS 3k) two multisets of equal sum, which implies our theorem. Assign f (1) A and ftwo (2) tofB B. Since fdenote (1) = Sfby(2), we are now trying to partition Feven. (N )O(1). = Fspeci )−− m. Therefore, Therefore, there two are A, vertices ∈+ A, − ∈and V whether − there and is an there edge connecting anSome edge connecting Ain and B.A Since and A, B Since ∈(N VA, BS Some example of special cases example of 4 Some example of special cases f Therefore, FProof. with multiples three, which we will FinN =≡ sum ofis all elements F (N )competitive is However, 4ofWe Some example of special cases ook at some common examples special cases that may occur competitive programming problems. will look atN some common examples ofprovide special cases that may occur in will look at some common examples of special cases that may occur in programm competit We will provide more examples ofparti speth m is reduced to(mod checking whether ≡ 1cases (mod 3). We can solve this in3), O(1). me example of special cases hether N ≡ 1 3). We can solve this in O(1). We will more examples of special cases in the following We will provide more examples of special cases in the following section. We We will provide more examples of special cases in the following section. e will provide more examples of special in the following section. Proof. Assign f (1) to A and f (2) to B. Since f (1) = f (2), we are now trying to f (1) − f (2). F (N ) will have N − 2 elements. Since N ≡ 2 (mod we obtain N − 2 ≡ 0 (mod 3). By lemma me cases wecases have A, we BSome have ∈ /of S. A, B ∈ /+some S. and As A and connected byof an edge, by+Planar an we edge, note that weF note S occur is that aS VERTEX-COVER. iswhile not fa(1) VERTEX-COVER. ispa 4.1 graphs aial < example b. We can partition Fspecial into We will look common special cases that may in competitive programming because (N )will isnot even odd. This Therefo Irvin GUNAWAN Example ofB Special Cases fAs (aatA 3k) + fare (a + length 1Bexamples +are 3k)connected = fcan (a +solve 2of 3k) khan any consecutive subsequence of Fsome with multiples three, we denote bycompetitive F =isthat mNAWAN is4 reduced to4. checking whether N ≡ 1 F(mod 3). We this inwhich O(1). Some example of special cases special in the following section. ng section. cases 4.1 Planar graphs 4.1 Planar graphs We will look at common examples of special cases that may occur in programm 4.1 Planar graphs We will look at some common examples of special cases may occur We will look at some common examples of special cases that may occur in competitive programming We will look at some common examples of special cases that may occur in competitive programming f (1) − f (2). (N ) will have N − 2 elements. Since N ≡ 2 (mod 3), we obtain N − 2 ≡ 3, F (N ) can be partitioned into two multisets of equal sum, which implies our theorem. contradiction. contradiction. Therefore Therefore V − S is V an − INDEPENDENT-SET. S is an INDEPENDENT-SET. We will look at some common examples of special cases that may occur in competitive programming problems. AN es ofaspecial special cases that maysome occur in competitive programming problems. + 1), f−(a ...f (b)} for a in < competitive b.that We F ainto b− 2+ 2), bPlanar − acan − be 2partition Planar graph a (N graph drawn on flat surface without having twographs edges o special cases in thethat following 4.1 graphs 4.1 Planar 4.1 Planar es of cases may programming problems. Theorem 4. Ifgraphs N ≡ 2which (mod 3). Fcrossing (N ) theorem. caneach be pa 3,isoccur Fsection. ) can be can partitioned into two multisets of equal sum, implies our r in competitive programming problems. } ∪ {f (a + 1 + 3k), 0 ≤ k ≤ } Planar graph is aof graph that can be drawn on ais can flat surface without havi 4 Som Planar graph is aaproblem graph that can be drawn on aaspecial flat surface without having two edges crossing each ot 4 Some example of Planar graph is graph that can be drawn on flat surface without having two edges crossing each ot 4.1 Planar graphs 4 Some example of special cases mmon examples of special cases that may occur in competitive programming problems. 4 Some example of special cases et al. 2001). There are many graph problems which are easy to solve if the graph is planar. We will prov Therefore, solving this is reduced to checking whether N ≡ 1 (mod 3). We solve this in O(1). 3GUNAWAN 3 4 Some example of cases Theorem 1. 1. If S ⊆ V If is S a ⊆ MAX-INDEPENDENT-SET V is a MAX-INDEPENDENT-SET graph G(V, of graph E), G(V, then E), V − then S V a MIN-VERTEX-COVER − S is a MIN-VERTE rvinTheorem We will look at someb − common examples of special casesPlanar thatb may occur in4.1 competitive a flat − 2graph −graphs acrossing − 2flat 4.1 graphs Planar graphs 4.1 is aAa graph that can be drawn onamany agraph without having two each Planar graph is that can be on aProof. surface without having two crossing et al. 2001). There are many graph which easy solve ifprov thefc Planar graph graph that can be drawn on aproblems surface without having two edg Some example cases et al. 2001). There are graph problems which are easy to solve the graph planar. We will et al. 2001). There are problems which are easy to solve the isisare planar. We will prov faphspecial cases 4.1 Planar graphs b− − 2of Assign fifif}(1) tograph A other and f(West (2) toto B. Since = {f (a +more 3k), 0of ≤ kspecial ≤E). }surface ∪is {fathis (a 1drawn + 3k), 0Planar ≤ kflat ≤edges Therefore, solving problem is reduced to checking whether N ≡ 1edges (mod 3). We examples. We will provide examples of many special cases in + the following section. of the graph the G(V, graph E). G(V, 4.1 Planar graphs programming problems. Planar graph is a graph that can be drawn on a flat surface without having two edges crossing each otm }. k ≤ 3 3 4.1 Planar graphs We will look at some common examp We will look at some common examples of special cases that We will look at some common examples of special cases that may occur in competitive programming problems. 1). There are many graph problems which are easy to solve if the graph is planar. We will provide several et al. 2001). There are many graph problems which are easy to solve if the graph is planar. We wi We will look at some common examples of special cases that may occur in competitiv ome example of special cases examples. et al. 2001). There are many graph problems which are easy to solve ifcrossing the graph ishav poeo examples. e will look some common examples of special cases that may occur in competitive problems. 3 at examples. fasurface (1) −surface fcan (2). Fwithout (N )programming will have Nsurface − 2crossing elements. Sin We will provide more examples of special cases in the following section. Planar graph is a graph that can be drawn on flat having two edges crossing Planar graph is a graph that be drawn on a flat without Planar graph is a graph that can be drawn on a flat surface without having two edges each Planar graph is a graph that can be drawn on a flat without having two edges each 4.1 Planar graphs b − a − 2 Planar graph is a graph that can be drawn on a flat surface without having two edges crossing each other (Wes etsurface al.cases 2001). There are many graph problems which are easy toThe solve ifthat the graph is planar. We will prov amples ofa = special that may occur inproblems. competitive programming problems. mayProof. occur in competitive programming only rawn on flat without having two edges crossing each other (West examples. Proof. We know We that know V − that S is V a − vertex S is a cover vertex by cover lemma by 1. lemma The 1. thing only thing remains that for remains us to for prove us to is it p examples. }. B {f (a + 2 + 3k), 0 ≤ k ≤ 3, F (N ) can be partitioned into two multisets of b−a−2 awn on a≤ flat surface without having two each other (West et al.are 2001). There are many graph problems which are easy to solve ifgraph the graph is planar. Weifpro wi et al.crossing 2001). There are many problems which easy to th etcrossing al. 2001). There are many graph problems which are easy to solve theplanar. graph planar. Wesolve will pro et al. 2001). There are many graph problems which are easy to solve ifif the isisare planar. We will 4.1.1 Number of edges ving two edges each other (West 3edges ry 0 can ≤ kal. et 2001). There many graph problems which are easy to solve ifgraph the is We will provide examples. mples of special cases may occur competitive programming problems. 3 Suppose hat be drawn on atothat flat surface without two edges crossing each other (West oblems which are easy solve ifSthe the graph isishaving planar. We will provide several V −4 is VSome not −inS minimum not minimum vertex cover. vertex Then, cover. there Then, isgraph another there is vertex another cover vertex V − cover S severa where V − minimality. minimality. Suppose example of special cases 4.1.1 Number of edges 4.1 Planar g 4.1. Planar Graphs 4.1.1 Number of edges 4.1 Planar graphs 4.1.1 Number of edges 4.1 Planar graphs blems which are easy to solve if graph is planar. We will provide several examples. examples. examples. examples. 4.1 Planar graphs he graph is planar. We provide several examples. b−a−2 will graph edges provide solving Therefore, this problem is cases reduced to ca any graph are easy to solve the is planar. We will several InPlanar simple general graph, the of canBy be up order with respect the 4|Sedges Some example ofindependent special ill sum, for 0≤ kimplies ≤ifnumber −the |V < |V − S −which <as |V which − S|, implies which that |S |3 that > of |S|. By |> lemma |S|. 2,lemma S isto an 2,a independent Squadratic isNumber an set. Therefore, set. Therefore, S to is not 4.1.1 Number 4.1.1 Number of edges 4.1 4.1.1 of edges graphs + have f |V (a + 1Sproblems +|same 3k) = f|S|, (a + 2graphs +every 3k) Planar graph iseach awith graph that can bein In simple general graph, the number of edges can be up to a quadrat Planar graph is a graph that can be drawn on a flat surface 2 In simple general graph, the number of edges can be up to a quadratic order with respect to the In simple general graph, the number of edges can be up to a quadratic order respect to the Planar graph is a graph that can be drawn on a flat surface without having two edges crossing each other (West 4.1.1 Number of edges Planar graph is graph that can be drawn on a flat surface without having two edges We will look at some common examples of special cases that may occur in competitive programming problems. We will provide more examples of special cases anar graph is a graph that can be drawn on a flat surface without having two edges crossing other (West vertices (i.e. O(V )). This is not the case for planar graph. In a planar graph, we may show that Ednn maximum independent independent set. This set. is a This contradiction. is a contradiction. Therefore Therefore V − S is Vthe − minimum S is the minimum vertex cover. vertex cover. wi 4.1 maximum Planar graphs 2 2 4.1.1 Number of edges 2 4.1.1 Number of edges 4.1.1 Number of edges 4.1.1 Number of edges general graph, the number of edges can be up to a quadratic order with respect to the number of In simple general graph, the number of edges can be up to a quadratic order with respect to etis al. 2001). There are many graph pr be drawn on avertices flat surface without having two edges each other (West Planar graph is aet graph that can be drawn on a2Therefore, flat surface without having two edges vertices (i.e. O(V )). isgraph not case for planar graph. In aeasy planar In simple graph, the number of edges can be up to aO(V quadratic order wi without having two edges each other (West fV(acrossing +3graph 3k) + fThis (a +is 1general + 3k) = fcrossing (aal. + + 3k) eteasy 2001). There are graph problems are to (i.e. O(V )). not the case for planar In athe planar graph, we may show that E et 2001). There are many problems which are to solve ifgraph. the graph planar. We will provide several vertices (i.e. O(V )). This issome not the case for planar graph. Inmany ais planar graph, we may show that E 4.1.1 Number of edges al. 2001). There are many graph problems which are easy to solve ifwhich graph is plan We will look at common examples of special cases that may occur in).the competitive pr al.al. 2001). There are many graph problems which are easy to solve ifThis the planar. We will provide several holds for ≥ by using the Euler’s formula. number of edges is Naturally, any 4.1.1 Number of edges simple general graph, the number edges can be upthe tograph. a quadratic order with respect to the n 2 Number 2planar 2 of 4.1.1 of edges i.e. O(VifFrom )).which This is not the case for graph. In a planar graph, we may show that E ≤ 3V − 6 be drawn on aIn flat surface without having two edges crossing each other (West crossing each other (West et al., 2001). There are many graph problems which are easy vertices (i.e. O(V )). This is not the case for planar In a planar graph, we may show th examples. h solve problems are easy to solve if the graph is planar. We will provide several the From above the theorem, above theorem, we conclude we conclude that a MIN-VERTEX-COVER that a MIN-VERTEX-COVER can be easily can be constructed easily constructed if we have if holds for V ≥ 3 by using the Euler’s formula. Therefore, the number of vertices (i.e. O(V )). This is not the case for planar graph. In a planar graph, we oamples. the graph is planar. We will provide several examples. holds for V ≥ 3 by using the Euler’s formula. Therefore, the number of edges is O(V ). Naturally, any examples. holds for V ≥ 3 by using the Euler’s formula. Therefore, the number of edges is O(V ). Naturally, any examples. that has O(E) in running time can be changed into O(V ).In shortest path in goaw In(i.e. simple general graph, the number of up edges can up to aofquadratic order with to 2its In simple graph, the number edges can be up toarespect ageneral quadra In simple general graph, the number ofgeneral edges can be upbeto to aaquadratic quadratic order with respect to the the In simple general graph, the number of edges can be up aComputing order with respect to 4.1.1 Number of edges 4.1 Planar graphs In simple general graph, the number of edges can be to a quadratic order with respect to the number vertices O(V )). This is not the case for planar graph. planar graph, we may show that E 4number Some exam to solve graph is planar. We provide several examples. ≥ 3 by can using Euler’s formula. Therefore, the number ofits is O(V ). Naturally, any algorithm ofproblems edges can bethe up toif afor quadratic order with respect tothe the number of hV which are easy to solve the graph is3will planar. We will provide several holds V ≥ 3ifrunning by using the Euler’s formula. Therefore, the number of edges O(V Naturall MAX-INDEPENDENT-SET. MAX-INDEPENDENT-SET. that has O(E) in running be changed into O(V ). Computin holds Vis ≥ by using Euler’s formula. Therefore, theplanar is O( 2path 2for that has O(E) in time can be changed into O(V ). Computing shortest path in aedges gr 2edges that has O(E) in its its running time can be changed into O(V ). Computing shortest inshow a).general general gE 22O(V of edges be up to athe quadratic order with respect to the number of vin GUNAWAN Bellman-Ford takes O(V E) (Halim & Halim 2013), but only takes O(V )isgraph. in aof planar graph vertices (i.e. )). This is not the case for planar graph. In awe planar we may t 2 vertices (i.e. O(V )). This istime not the case for plana vertices (i.e. O(V )). This is not the case for planar graph. Incan a planar planar graph, we may show that vertices (i.e. O(V )). This not the case for planar graph. In ait graph, we may that 4.1 Planar graphs atic order with respect to the number ofinto vertices (i.e. O(V )). This is not the case for planar graph. In ato planar graph, may show that EIn≤inashow 3V −E holds for V ≥ 3algorithm byup using the Euler’s formula. Therefore, the number of edges isgraph, O(V ). Naturally, any 2 2 thePlanar number of edges can be to a quadratic order with respect the number of O(E) in its running time can be changed O(V ). Computing shortest path in a general graph using case for planar graph. In a planar graph, we may show that E ≤ 3V − 6 graph is a graph that can be drawn on a flat surface without having two edges crossing each other (West that has O(E) in its running time can be changed into O(V ). Computing shortest path a gen Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only tp that has O(E) in its running time can be changed into O(V ). Computing shortest Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V ) in a planar graph. Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V ) in a planar graph. 4.1.1 Number of 4.1.1 Number of edges 4.1.1 Number of edges case for planar graph. In a planar graph, we may show that E ≤ 3V − 6 the number of connected components using DFS in a general graph takes O(V + E), but it only takes holds for V ≥ 3using by−using thecan Euler’s formula. Therefore, theatnumber of).Therefore, edges is ). O(V Naturall holds for V changed ≥ 3 Therefore, by using the Euler’s formula. the number of holds for ≥ in 3the by the Euler’s formula. Therefore, the number of edges edges is O(V O(V ). Naturally, an holds for VV ≥ 3E by using the Euler’s formula. the number of is Naturally, any 4.1.1 Number of edges ar graph, we may show that ≤graph 3V 6isformula. holds for that Vbeginning ≥ 3the byO(E) using Euler’s Therefore, the number of edges is Naturally, any algorithm has its running be into O(V Computing shortest path in ain). general gr We will look some common examples of special 2). 2two 2i 4.1.1. Number of Edges his is not the case for planar graph. InHalim aiswe planar graph, we may show that Ein ≤asurface 3V −itO(V 62013), Planar atime graph that can be drawn on athe flat without having edges cro Ford algorithm takes O(V E) (Halim & 2013), but it only takes O(V ) planar graph. Counting ormula. Therefore, number of edges O(V ). Naturally, any algorithm et al. 2001). There are many graph problems which are easy to solve if graph is planar. We will provide several Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but only takes O(V ) a planar In the In the beginning of this section, of this section, assume we we assume know we that know MIN-VERTEX-COVER MIN-VERTEX-COVER is a NP-hard is a NP-hard problem. prob It the number of connected components using DFS in a general graph takes Bellman-Ford algorithm takes O(V E) (Halim & Halim but it only takes O(V the number of connected components using DFS in a general graph takes O(V + E), but it only takes 4.1.1 Number of edges the number of connected components using DFS in a general graph takes O(V + E), but it only takes of edges ormula. Therefore, the number ofalgorithm edges O(V ). Naturally, any algorithm planar Therefore, ifisrunning the problem requires usgeneral to compute the number ofO(V connected components that has O(E) in its time can be changed into O(V ).with Computing shortest path in ausin gen that has O(E) its running time be changed into O(V ).order that has O(E) in its running time can be changed into O(V ). Computing shortest path inthe general that has O(E) in its running time can be changed into O(V ). Computing shortest path in aabeComputi general g fner edges is O(V ).components Naturally, any In simple general graph, number that has O(E) ingraph. its running time be changed into O(V ).This Computing shortest path into a2athe general Bellman-Ford algorithm takes E) (Halim & Halim 2013), but itcan takes )the inin anumber planar graph. In simple graph, the number of edges can up towe simple general graph, the number ofcan edges can be up toin abe quadratic order respect ofnumb Ingraph, simple general graph, the number of edges can be up to ato with In simple general the number of edges can up to quadratic order respect simple general graph, the number of edges can be up to a). quadratic order with the number of the Euler’s Therefore, the edges is O(V Naturally, any algorithm et al. 2001). are many graph problems are easy towith ifquadratic graph isthe planar. of connected using DFS in aO(V general graph takes O(V +a000, E), but itonly only )new a2components be changed into O(V ). Computing shortest path in arequires general graph using examples. the number of connected components using DFS in awhich general graph takes O(V + E), but itsolutio only good to formula. know good as to many know NP-hard as many problem NP-hard as possible. as possible. This isus necessary is necessary so that if so we that encounter ifthe we encounter problem agraph new X, prob planar graph. Therefore, if the problem requires us to number of connected components using DFS in arespect general graph takes O(V + E)ii 4.1.1 Number of edges 2solve planar graph. Therefore, ififThere the problem to compute the number of connected planar graph. Therefore, the problem requires us to compute the number of connected components 22compute be changed into O(V ). Computing shortest path in a general graph using 2 graph, even though the constraint states that V ≤ 100, E ≤ 100, 000 , standard DFS Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V ) in a planar 2 2 Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V ) in a planar graph Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V ) in a planar graph 2 2& path in awith general graph vertices (i.e. )). This is−graph. not the mber of(i.e. edges can be up to aonly quadratic order respect to number of 2the Bellman-Ford algorithm takes O(V E) (Halim Halim but itto only takes O(V )and inaO(V athus planar graph. Countin oing a shortest quadratic order respect to the number of the number of connected components using DFS in ato general graph takes O(V + E), it3V only takes vertices (i.e. O(V )). This is not case for planar IO 2planar vertices O(V )). This not the case for planar graph. In athe planar graph, we may show that E ≤ 3V − 6conne to number of vertices (i.e. ). This is not case for planar graph. In planar vertices (i.e. O(V )). This is2013), the case for planar graph. In a100, planar graph, wealso m 22the rtices O(V )). This is not the case for graph. In a≤ planar graph, we may show that Ebut ≤ 6100, ning time can be changed into O(V ).using Computing shortest path in aof general graph using examples. P aph. Therefore, if2013), the problem requires us to compute the number connected components in athe planar (Halim &(i.e. Halim but itisthe takes O(V inwith planar graph. Counting planar graph. Therefore, the problem requires us compute the number of connected compon can use any can of use the any NP-hard of problems NP-hard problems that we know, we reduce know, itthe reduce problem it to X, problem and thus X,compute prove that prove X is that also X NP-hard is graph, even though the constraint states that ≤ 000, E ≤4.1 00 2if planar graph. Therefore, ifusing the problem requires us to number of graph, even though the constraint states that Vnot 100, 000, E ≤ 100, 000 the standard DFS solution even though the constraint states that V ≤ 100, 000, E ≤ 100, 000 ,, V the standard DFS solution 2 graph, Halim & Halim 2013), but it only takes O(V ))Therefore, in aathat planar graph. Counting under one second (in competitive programming, we assume that 1number million operations can be done in the number of connected components DFS in aedges general graph takes O(V + E), but it only the number of connected components using DFS in a general graph take the number of connected components using DFS in a general graph takes O(V + E), but it only takes the number of connected components using DFS in a general graph takes O(V + E), but it only takes mber of edges can be up to a quadratic order with respect to the number of y takes O(V ) in a planar graph. Counting holds for V ≥ 3 by using the Euler’s f t the case for planar graph. In a planar graph, we may show that E ≤ 3V − 6 the number of connected components using DFS in a general graph takes O(V + E), but it only takes O(V ) in 2 In a planar graph, we may show that E ≤ 3V − 6 planar graph. Therefore, if the problem requires us to compute the of connected components i holds for V ≥ 3 by using the formula. Therefore, the n 2 graph, we may show that holds for by using the Euler’s holds for V ≥ 3 by using the Euler’s formula. the number of is O(V ). Naturally, any algorithm 2 still holds for V 3though by using the Euler’s formula. Therefore, the number of edges 2 isDFS olds for ≥the by using the Euler’s formula. Therefore, the of≤ is programming, O(V ). Naturally, any algorithm akes O(V E) & Halim 2013), but it+≥ only takes O(V )number inthat awe planar graph. Counting en though constraint states that V even ≤ 100, 000, ≤ 100, 000 ,assume the standard DFS solution runs using DFS in3(Halim aunder general graph takes O(V E), but itEthe only takes O(V ) edges in athat graph, even though the constraint states V 100, 000, ≤ 100, 000 , of the standard s under one second (in competitive we assume that 1O(V mill graph, constraint states V ≤ 100, 000, E ≤ 100, 000 ,the the sta 4.1.1 Number of edges under one second (in competitive programming, that 11E million operations can be done in one second (in competitive programming, we assume that million can be done in 1V 1 We using DFS in a general graph takes O(V + E), but it only takes O(V ) in a (Halim & Halim 2013)). planar graph. Therefore, if the problem requires us to compute the number connected compon We say that problem say that X problem is reducible X is to reducible problem to Y problem Y 2 operations planar graph. Therefore, if the problem requires us to compute num planar graph. Therefore, if the problem requires us to compute the number of connected components planar graph. Therefore, if the problem requires us to compute the number of connected components Planar graph is a graph that can be drawn on a fl the case for planar graph. In a planar graph, we may show that E ≤ 3V − 6 es O(V + E), but it only takes O(V ) in a that has O(E) in its running time can er’s formula. Therefore, the number of edges is O(V ). Naturally, any algorithm planar ifthat the problem requires us to compute the number of connected components in a plana Therefore, the number edges is .that Naturally, any algorithm that has Computing in its graph number of edges isTherefore, O(V ). Naturally, any algorithm graph, even though the constraint states that V ≤ 100, 000, E ≤ 100, 000 ,athe standard DFS solution has O(E) in its running time can changed into O(V ).d hat has O(E) inits its running time can be changed into O(V ).2013)). Computing shortest path in ageneral general using has O(E) in its running time can be changed into O(V ). shortest has O(E) in running can be changed into O(V Computing shortest path using components using DFS in atime general graph takes O(V + E), but takes O(V )we in eat second (in competitive programming, we assume that 1). million operations can be done inbe second m requires usgraph. to compute the number of connected components init aonly planar under one second (in competitive programming, we assume that 1ain million can bepa 4.1.1 Number of (Halim & Halim under one second (in competitive programming, assume that 1 graph million operati 21 operations (Halim & Halim 2013)). (Halim & Halim 2013)). 22 edges m requires us to compute the number of connected components in aV planar graph, even though the constraint states that ≤ 100, 000, E ≤with 100, ,standard the standard DFS 2There graph, even though the constraint states that Vthe ≤ 100, 000, E 2013), ≤ 100, graph, even though the constraint states that ≤ 100, 000, E ≤ 100, 000 ,000 the standard DFS solutio graph, even though the constraint states that VV ≤ 100, 000, E ≤ 100, 000 ,graph DFS solutio 2 et al. 2001). are many graph problems which 2 r’s formula. Therefore, the number of edges is O(V ). Naturally, any algorithm In simple general graph, the number of edges can be up to a quadratic order respect to the number of mber of connected components in a planar Bellman-Ford algorithm takes O(V E) eellman-Ford can be changed into O(V ). Computing shortest path in a general graph using running time can be changed into . Computing shortest path in a general us2 graph, even though the constraint states that V ≤ 100, 000, E ≤ 100, 000 , the standard DFS solution still run ). Computing shortest path in a general graph using under one second (in competitive programming, we assume that 1 million operations can be done Bellman-Ford algorithm takes O(V E) (Halim & Halim b0si 2 Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V ) in a planar graph. Counting Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V takes O(V E) & Halim 2013), but itcomponents only takes O(V ) in a planar graph. Counting )in ifHalim the problem requires compute the number ofDFS connected in a planar 2013)). tes that V≤ ≤algorithm 100, 000, Eus≤ ≤to 100, 000(Halim , the standard solution still runs runs (Halim & Halim 22013)). (Halim & competitive Halim 2013)). 2 2 es that V 100, 000, E 100, 000 , standard DFS solution still 2 under one second (in programming, we assume that 1 million operations can be 2 under one second (in competitive programming, we assume that 1 mil under one second (in competitive programming, we assume that 1 million operations can be done under one second (in competitive programming, we assume that 1 million operations can be done 4.1.2 Maximum Clique examples. In simple general graph, the number of can be upgeneral tomay ait of quadratic order with can changed into O(V ). Computing shortest path agraph. general graph using vertices (i.e. O(V )). This is not the case for In aedges planar graph, we show that E ≤)in 3V −res 6gdibi 000 ,(Halim the standard DFS solution runs the connected components E) &connected Halim 2013), itstill only takes O(V in aincomponents planar graph. Counting under second competitive programming, we assume that 1O(V million operations can be done 1in 2 but itbe only takes O(V )(in in abut graph. (Halim & Halim 2013)). the number connected components using DFS in general he number of connected components using DFS ageneral general graph takes O(V E), but only takes O(V aE), the number ofCounting connected using DFS inproblem anumber graph takes O(V + eonstraint number ofone components using DFS inin a4.1.2 graph takes ++ E), but itMaximum only takes O(V )ain asecon states that V ≤ 100, 000, E ≤ 100, 000 ,)planar the standard DFS solution still runs gramming, we assume that 1planar million operations can be done in 1of second 4.1.2 Clique probl Maximum Clique problem 4.1.2 Maximum Clique problem 2 2 gramming, we assume that 1 million operations can be done in 1 second (Halim & Halim 2013)). (Halim & 2013)). (Halim & 2013)). (Halim & Halim 2013)). vertices (i.e. O(V )). isifplanar not the case forofplanar In planar graph, we may s E) (Halim && Halim 2013), but it takes O(V ) to in aHalim graph. Counting holds for VO(V ≥incan 3+ by using the Euler’s formula. Therefore, the number edges is O(V ). aNaturally, any algorithm llion operations be in 1only second planar graph. Therefore, the problem ents using DFS aMaximum general graph takes O(V + E), but it only takes O(V ) of in aset (Halim Halim 2013)). graph takes E), but itproblem only takes ) us inThis aoperations planar graph. Therefore, if graph. the problem us to compute planar graph. Therefore, ifHalim the problem requires compute the number connected components planar planar graph. Therefore, the problem requires us to compute the number of connect anar graph. Therefore, ifdone the requires us to compute the number of connected components inin aifasuch planar mpetitive programming, we assume that 1O(V million can be done in 1 second The Clique problem requires us to find the maximum of vertices inrequires a graph, that ev 4.1.2 Maximum Clique problem 4.1.2 Maximum Clique problem 4.1.2 Maximum Clique problem 2 2 holds for V ≥ 3 by using the Euler’s formula. Therefore, the number of edges is O(V ).sta N 4.1.1 nts using DFS in a general graph takes O(V + E), but it only takes O(V in a that has O(E) in its running time can be changed into O(V ). Computing shortest path in a general graph using graph, even though the constraint oblem requires us to compute the number of connected components in a planar 2) The Maximum Clique problem requires us to find the maximum set of ve te the number of connected components in a planar graph, even though the constraint states that V ≤ 100, 000, E The Maximum Clique problem requires us to find the maximum set of vertices in a graph, such that eve graph, even though the constraint states that V ≤ 100, 000, E ≤ 100, 000 , the standard DFS solution still runs The Maximum Clique problem requires us to find the maximum set of vertices in a graph, such that ev 4.1.2 Maximum Clique problem graph, even though the constraint states that V ≤ 100, 000, E ≤ 100, 000 , the stand aph, even though the in constraint thatconnected V ≤ 100,by 000, ≤ 100, , the standard DFS solution still runs cliqu vertices the set isstates directly an E edge. By 000 reduction from vertex cover, the maximum 2 2 2 4.1.2 Maximum Clique problem 4.1.2 Maximum Clique prob 4.1.2 Maximum Clique problem 4.1.2 Maximum Clique problem that has O(E) in its running time can be changed into O(V ). Computing shortest path in Clique problem requires us to find maximum set of vertices inproblem aconnected graph, such that every of oblem requires us to compute the number of connected components in astill planar Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V )can abe planar graph. Counting The Maximum Clique problem requires us to find the maximum set of vertices in acompetitive such th under one second (in pro tmum that V 100, E ≤ 100, 000the ,connected the standard DFS solution runs vertices incompetitive the is directly by an edge. By reduction from The Maximum Clique problem requires us to find the maximum set of vertices incliqu ave Estates ≤ 100, 000 ,≤ the standard DFS solution still runs under one second (in competitive programming, assume tg vertices in the set is directly connected by an edge. reduction from vertex cover, the maximum under one second (in competitive programming, we assume that 1In million operations done in 1we second vertices in000, the set is directly by an edge. By reduction from vertex cover, the maximum cliqu 4.1.2 Maximum Clique under one second (in programming, we assume that 1pair million operation nder second (in competitive programming, we assume that 1By million operations can be done in 1graph, second on general graph is NP-hard. However, it isset easy to solve this problem inin planar graph. Consider th simple general graph, the number of edges ca .1.2 one Maximum Clique problem The Maximum Clique problem requires uscan to find the maximum set of+vertices in aonly graph, such that eve 2 2 Maximum Clique problem Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V ) in a ne.1.2 the set is directly connected by an edge. By reduction from vertex cover, the maximum clique problem states that V ≤ 100, 000, E ≤ 100, 000 , the standard DFS solution still runs the number of connected components using DFS in a general graph takes O(V E), but it takes O(V vertices in the set is directly connected by an edge. By reduction from vertex cover, the maximum (Halim & Halim 2013)). programming, we assume that 1 million operations be done in 1 second on general graph is NP-hard. However, it is easy to solve this problem vertices the set is directly connected by an edge. By reduction from vertex cover, that 1 million operations can be done in 1 second (Halim & Halim 2013)). on general graph is NP-hard. However, it is easy to solve this problem in planar graph. Consider th blem on general graph is NP-hard. However, it is easy to solve this problem in planar graph. Consider th Halim & Halim 2013)). is aPlanar graph graph that can drawn on can a flat edgesNumber crossing each other (Westeach other (West is abegraph that besurface drawn without on a flathaving surfacetwo without having two crossing 4.1.1 ofedges edges canSuppose be partitioned two ofedges equal sum.. There many Number graph which easy toProof. solve ifare the graph is4.1.1 planar. We will several Number ofNote 4.1.1 edges 4.1.1 Number of edges et are al. 2001). Thereproblems areof many graphare problems which easy to if F the graph isprovide planar. We severa F solve (N )into = (N )multisets − f (1). thatwill F provide (N ) contains In simple general graph, the number of edges can be up to a quadratic order with4.1.1 respectN 4.1.1 Number of edges examples. haveN − number 1 ≡ 03.(mod 3). By lemma 3, F a(N ) can be partitioned int 2order Iffor N ≡ 1to (mod Fto ) graph cannot partitioned int general graph, the edges can be3), up quadratic order with res ber of edges can be up toIna simple quadratic withisTheorem respect theof number of In simple general graph, the of can be up agraph. quadratic order with to show the Planar isbe arespect graph that can vertices (i.e. O(V )).number This notedges the to case planar In a(Nplanar graph, we may sum of all elements in F (N ) is even. However, the sum of all eleme 2 simple general the of edges can In simple upfor graph, order the with number respect of edges to the ca vertices O(V )). This is not the be case graph. In2001). aofplanar graph, we may the case for In planar In graph, we may show that E≤ 3Vtoplanar −ageneral vertices (i.e. O(V )). isnumber not the case for planar graph. In6quadratic athe planar graph, we may show En et There are many gra holds foragraph, V2planar ≥(i.e. 3This by using the Euler’s formula. Therefore, edges is O(V ).that J.I. 94 graph. Gunawan Proof. Suppose F (N ) =f F (Nis)number − al. f (1). Note that F (N )Natur cont 4.1.1 Number4.1.1 of edges because F (N ) is even while (1) Therefore, there isO(V no way 2 2odd. Number of edges vertices (i.e. vertices (i.e. O(V )). This is not the case for planar graph. In a O(V planar )). graph, This is we not may the show case that for pla E holds for V ≥ 3 by using the Euler’s formula. Therefore, the number of edges is ). ’s formula. Therefore, the of in edges is O(V formula. ). Naturally, any algorithm holds forthat V ≥number 3 by using the Euler’s the number edges is O(V ). Naturally, examples. has O(E) its running time can−Therefore, be ).of Computing in any aN g≤ haveN 1 ≡changed 0 (modinto 3). O(V By lemma 3, F (Nshortest ) can be2path partitioned holds for VO(E) ≥ 3edges by using the Euler’s Therefore, holds the for number ≥ 3F by ofbut using edges the isbe O(V Euler’s ).O(V Naturally, formula. any Ther has O(E) in its running time can be changed into O(V ). Computing shortest can In be changed into ).that Computing shortest path a 4. general graph using neral graph, the number of can be up toTheorem aformula. quadratic order with respect to the number ofto that hasO(V in its running time can beinchanged ).V Computing shortest path in a)number general gi Bellman-Ford algorithm takes O(V E) (Halim & Halim itcan only takes in of apath plan simple general graph, the number of edges can be up to a≡ quadratic order with the of ing Bellman-Ford algorithm takes (Halim and Halim, 2013), itrespect only takes If Ninto 2O(V (mod 3). )but partitioned into two sum of all elements in F 2013), (N ) is(N even. However, the sum 2 allgre 2 takes 2 2 6takes 2 that has O(E) in its running time can be changed into that O(V has ). O(E) Computing in its running shortest time path can in a be general changed Bellman-Ford algorithm O(V E) (Halim & Halim 2013), but it only O(V ) in a E) & Halim 2013), but it only ) in a planar graph. Counting O(V(Halim )). This is not the case for planar graph. In a planar graph, we may show that E ≤ 3V − Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but it only takes O(V ) in a planar graph the number of connected components using DFS in a general graph takes O(V + E), but it on in a planar graph. Counting the number of connected components using DFS in vertices (i.e. O(V )). This is not the case for planar graph. In planar graph, weis may show that E ≤ 3Vis − 6 because F f(N ) to isa even while f (1) odd. Therefore, no 2f (1) = fthere A (2) toO(V B. Since (2), we ar Bellman-Ford algorithm takes O(V E) (Halim &edges Halim Bellman-Ford but algorithm only takes takes O(V O(V ) of inbut E) a planar (Halim graph. &comp Ha the number of connected components using DFS in general graph O(V E), but using DFS in≥ anumber graph takes O(V + E), but itof only takes ) and inNaturally, afitaplanar ≥nts 3 by using Euler’s formula. Therefore, the number is O(V ). any algorithm of connected components using DFS in(1) a 2013), general graph takes O(V +takes E), it + only takes takes ,Therefore, but itAssign only takes graph. Therefore, graph. Therefore, ifProof. the problem requires us to compute the number connected holds forthe Vthe 3general byplanar using the Euler’s formula. the number of edges is ). Naturally, any algorithm simple general graph, the nu f (2). Fshortest )requires will have N − 2EIn elements. Nit ≡only 2 (mod 3O 2bebut the number of connected components using DFS in ato the general number graph of connected takes + E), using DFS takes in planar graph. Therefore, if−requires the problem us compute the number of connected blem requires us time to compute the number ofthe components in a≡ ) inthat its running can be changed into O(V ).f (1) Computing path in ato general graph using if in the problem requires toconnected compute the number components in aSince planar graph. Therefore, ifus the problem us compute the number of connected components Theorem 4.(N Ifof N 2100, (mod 3). FO(V (N )components can partitioned into graph, even though constraint states that Vconnected ≤planar 000, ≤ 100, 000 , the standard DFS has O(E) its running time can be changed into O(V ). Computing shortest path in aplanar general graph using 2 by the construction of the function. 2 vertices (i.e. O(V )). This is n 2 2 2 3, F (N ) can be partitioned into two multisets of equal sum, which 2 Eof graph. Therefore, the problem us planar compute graph. the Therefore, number if connected the problem requires in graph, even though the constraint states that Vruns ≤ 000, 000 ,components the standard graph, even though theif constraint that the standard states thattakes Vplanar ≤O(V 100, 000, E ≤ 100, 000 ,2013), the standard DFS algorithm E) (Halim &second Halim but itrequires only takes O(V )only in aEassume planar graph. Counting graph, even though the constraint states that Vsolution ≤to 100, 000, ≤100, 100, 000 ,≤ the standard DFS solutio under one (in competitive programming, we that million operations can us be Bellman-Ford algorithm takes O(V E) (Halim &states Halim 2013), but itstill takes O(V ) 1 ,in a100, planar graph. Counting by the construction of the function. 2to for Proof. Assign fassume (1) to A and fmillion (2) B. Since fby (1) = fdone (2), w holds V ≥ a3 using the Eu graph, even though the constraint states that V ≤ 100, graph, 000, even E ≤ though 100, 000 the , constraint the standard states DFS that solution V ≤ DFS solution still runs under one second (in competitive programming, we assume that under one second (in competitive programming, we assume that 1 million operations ca we assume that 1 million operations can be done in 1 second fprogramming, connected components using DFS in a general graph takes O(V + E), but it only takes O(V ) in under one second (in competitive programming, we that 1 operations can be in Theorem 2. If N is divisible by three, then F (N ) can be partitioned into two multise (Halim components & Halim 2013)). the number of connected using DFSTherefore, in a general graph takes O(V + E), but it takes whether O(V ) inN a this solving problem isthat reduced toonly checking f (1) − f (2). F (N ) will have N − 2 elements. Since N ≡ 2 (mo has O(E) in its running tim 1 million operations can be done in 1 second (Halim and Halim 2013)). under one second (in competitive programming, we under assume one that second 1 million (in competitive operations programming, can be done in (Halim & Halim 2013)). Theorem 2. Ifproblem N&isHalim divisible then F (N )number can be partitioned into two multisets of equal sum.in a planarw Therefore, if (Halim the requires usthree, to compute the of connected components in a planar planar graph. Therefore, if 2013)). thebyproblem requires us to compute the number of connected components three, then We will more special the sectio Proof. N is000, divisible Fexamples (N ) isHalim a2of prefix of Fcases within length multiples of 3,byFprovide (N )2can bestandard partitioned into two multisets of following equal sum, wh Bellman-Ford algorithm takes O( (Halim &states Halim 2013)). 2013)). hough the constraint that V ≤If100, E≤ 000 , the DFS solution still runs graph, even though the constraint states that V 100, ≤ 100, 000, E(Halim ≤ 100,&000 , the standard DFS solution still runs 4.1.2 Maximum Clique problem Proof. If N is4.1.2. divisible bycan three, thenProblem F (N ) into is a two prefix of F with lengthsum.. multiples of three. ofByconnected lemma 3,compo F (N ) be partitioned multisets of equal the number Maximum Clique cond (in competitive weprogramming, assume that 1wemillion operations can problem be done 1can second 4.1.2 Maximum Clique problem 4.1.2 Maximum Clique problem 4.1.2 Maximum problem under one secondprogramming, (in competitive assume that 1Clique million operations betodone in 1 second Therefore, solving this isinreduced checking wheth can be partitioned into Maximum two multisets of equal sum.. planar graph. Therefore, ifMaxi the p The problem requires us to the4maximum set of vertices in4.1.2 a graph, such The Maximum CliqueClique problem requires usMaximum to find thefind maximum set of vertices in a graph, 4.1.2 Clique problem im 2013)). Some example of spe (Halim & Halim 2013)). Theorem 3. If N ≡ 1We (mod 3), F (N ) cannot be partitioned into two multisets of equs will provide more examples of special cases in the following The Maximum Clique problem requires us to find the maximum set of vertices in a graph, uires us to findThe thesuch maximum set of vertices in a graph, such that every pair of Maximum Clique requires us maximum set an of edge. vertices in a though graph, that ev that every of vertices in the settois find directly connected by By reduction graph, even the vertices in pair the problem set is directly connected bythe an edge. By reduction from vertex cover,such theconstrai maxim TheoremThe 3. Maximum If N ≡ 1 vertices (mod 3), Fthe (Nset ) cannot be partitioned into two multisets of equal sum. Clique problem requires us to find the The maximum Maximum set of Clique vertices problem in a graph, requires such us to that find eve t in is directly connected by an edge. By reduction from vertex cover, the m cted by an edge. By reduction from vertex cover, the maximum clique problem from vertex cover, the maximum clique problem on general graph is NP-hard. However, vertices in the set is directly connected by an edge. By reduction from vertex cover, the maximum cliqu under one second (in competiti on general graph is NP-hard. However, it is easy to solve this problem in planar graph. Con examples special N cases may oc Suppose FWe (Nwill )problem = look F (Nat ) −some f (1).common Note that F (N )ofcontains − 1that elements. 4.1.2 Proof. Maximum Clique 4.1.2 Maximum Clique problem vertices set directly connected by an By vertices reduction in the from set is directly cover, the maximum by an edge. clique general graph NP-hard. However, isvertices easy solve this problem in graph. the edge. N it solve isFinof easy to solve inthat planar graph. Consider the colouring a1planar wever, it is Suppose easy this problem in planar graph. Consider the on to general graph NP-hard. However, it is easy to solve this problem inof planar graph. Consider th (Halim & connected Halim 2013)). a)this graph such that two have the same colour. Note that ifwe Proof. (Ncolouring )on = haveN Fisis (N − f1problem (1). Note F (N )adjacent contains 1to elements. Since N ≡two (mod 3), ≡ 0is (mod 3).no By lemma 3,it Fproblem (N )− can be vertex partitioned into multisets of 4problem Some example of st on general graph is NP-hard. However, it is easy to on solve general this graph problem is NP-hard. in planar graph. However, Consider it is easy the of colouring a graph such that no two adjacent vertices have the same colour. Note tha graph such that no two adjacent vertices have the same colour. Note that if there is a adjacent vertices have the same colour. Note that if there is a clique of mtwo Clique problem requires us to find the maximum set of vertices in a graph, such that every pair of of colouring a graph such that no two adjacent vertices have the same colour. Note that if there is size problem k insum a graph, vertices insideset the must coloured with kevery colours. Th The Maximum requires tooffind ofclique vertices in abegraph, such thatTherefore, pair of haveN − 1 ≡ 0 Clique (mod 3). By lemma 3, us Fset(N )inthe can bemaximum into two multisets equal sum. of all the elements Fthe (N )partitioned is even. However, the sum ofof all elements in F (N ) =the F 4.1 Planar graph ofsize colouring aby graph such that no two adjacent vertices ofodd. colouring have the aFsame graph colour. such that Note no that two ifadjacent there ve a clique of size in in graph, ofWe the vertices the clique must be coloured size kthe aset graph, the set of the inside the clique with kproblem colour be be with clique coloured kset colours. Therefore, the entire ertices setvertices isinside directly connected an edge. By reduction from vertex cover, the maximum clique problem ksetinisamust graph, of the vertices inside the clique must coloured with kspecial Therefore, will look at some common ofcoloured cases that ma inthe the directly by edge. By reduction from vertex cover, the maximum clique sum of all elements in F (N )connected is even. However, the sum of all elements inbe (Nexamples )must = Fis (N )way +colours. fwith (1), which isFis odd because F (N )the isan even while fvertices (1) isinside Therefore, there no to partition (N colours. Therefore, the entire graph requires at least colours. By the four colour theaeven graph, setto ofodd. the itvertices inside the clique sizeproblem k must intoa partition be graph, coloured set with of kthe colours. vertices Therefore, inside the graph Planar graph is planar graph that can be drawn aConsider flat surface without aphbecause is general NP-hard. it isthe easy solve this problem in graph. Consider the problem on NP-hard. However, is easy to there solve in planar graph. the problem Fsize (NkHowever, ) in is is while f (1) is Therefore, isathis no way F (N ).on Jonathan Irvin GUNAWAN graph requires at least kmultisets colours. Bysolve therf The Maximum Clique problem orem, any planar graph can be coloured with at most four colours. (Gonthier, 2005). Since Theorem 4. If N ≡ 2 (mod 3). F (N ) can be partitioned into two of equal et al. 2001). There are many graph problems which are easy to a graph such that no two adjacent vertices have the same colour. Note that if there is a clique of of colouring a graphIrvin such that no twoGUNAWAN adjacent vertices have the same colour. Note that4.1 if there is a cliquegr of Jonathan Irvin Jonathan GUNAWAN colours. the four colour theorem, any can be coloured with at most four the four By colour theorem, any planar graph can begraph with at most four colours. 2005). Since at most vertices inentire setPlanar is directly con most colours are required to colour a planar there does not exist athe clique 4. If vertices N ≡ 2four (mod 3). F (Nplanar ) can becoloured partitioned into two multisets of (Gonthier equal sum. examples. aph,Theorem the kset of theat inside thevertices clique must be coloured with kgraph, colours. Therefore, the size in a graph, the set of the inside the clique must be coloured with k colours. Therefore, the entire Jonathan Irvin GUNAWAN Jonathan Irvin GUNAWAN Proof. Assign fcolour (1) toawe Aplanar and fgraph, (2) tonot B. Since (1) = f (2), wethan are now trying to pa orem, anyatcolours planar graph can be coloured with at most four . Since most four colours are required does exist most four are required tofour colour a to planar graph, there does exist athat clique with more vertices. H on graph is NP-hard. with more than vertices. Hence, can solve the problem byfnot checking whether there Planar graph is athere graph can begeneral drawn on a four flat surface with Since f (1) = f (2), we are now trying to partition F (N ) = F (N ) − Proof. Assign f (1) to A and f (2) to B. f (1) − f (2). F (N ) will have N − 2 elements. Since N ≡ 2 (mod 3), we obtain N −w2 es. required to colour a planar graph, there does not exist four vertices. Hence, wethe can solve by checking whether there is a clique Hence, we can problem by problem checking whether there is a clique with four vertices. If there is no clique of colouring a graph such that is solve a clique with fourthe vertices. If there is no clique with four vertices, we check whether et al. 2001). There are many graph problems which are easy to so Number oftheore edg − 2 elements. Since N ≡ 2 (mod 3), we obtain N − 4.1.1 n GUNAWAN fno (1) − f (2). F (Nchecking ) vertices, will have N ≡ (mod 3). our By lemma Jonathan Irvin GUNAWAN 3,whether Fwith (Ncheck ) can beispartitioned two multisets of equal sum, which implies solve theclique problem by there a clique re iswith with four we whether therewith isinto a clique withisthree vertices. ue four vertices, we whether there three vertices. Finding whether there is a the clique with k there is acheck clique three vertices. Finding whether there a clique with vertices can size k 2in a0graph, set of the examples. k kthree 4of edgeswhich F (N )whether can besolved partitioned into multisets of equal sum, which our theorem. s,a we check there is a clique with clique with k vertices can be solved naively inInvertices. O(V ).the Therefore, theimplies whole solution th k 3,vertices can be naively in two O(V ). . Therefore, Therefore, the whole solution simple general graph, the number up to a qua naively in whole solution takes is takes O(V ) time, can be is polynomial. Therefore,2 solving this2 problem is2 reduced to checking whether N ≡ 1 (mod 3). W k solved in O(V ).improved Therefore, the whole solution is polynomial. The solution can solution betoimproved to O(V of). Instead of having four nested polynomial. The improved to having four nested loopsindependently, ial. Thenaively solution can be O(Vcan ).be Instead having nested vertices (i.e. O(Vfour )). Thisloops isof not the case forvertices planar graph. In of a pl to find four . Instead 4.1.1 Number Jonathan Irvin GUNAWAN Therefore, solving this problem is reduced checkingofwhether N ≡ 1in(mod 3). We can solve this in O(1). We will provide moretoexamples special cases the following section. 2 an be improved to O(V ). Instead of having four nested totwo find four independently, we can two nested loops over the edges instead sntly, independently, cannested havevertices two nested loops overinstead the edges and test whether we can havewe loops over the edges and test whether holds for V have ≥ 3instead by using the Euler’s formula. Therefore, number the four vertices (which are thethe endpoint We will provide more examples of special cases in the following section. 2 the the 2 takes wo nested over the edges instead testthat whether In simple general graph, of can be up to a and the four vertices (which are the endpoint twoasnumber edges) a clique. re the of thetest twowhether edges) form aand clique. This solution ),same which isO(V the oint of endpoint the loops two edges) form a clique. This solution takes O(E ), which is of the has O(E) in itsO(E running time can be2form into O(V ). Comp )changed in edges planar graph. 2 2 isvertices the same as in planar graph. s)graph. form a clique. This solution takes takes O(E ), , which the4 (i.e. O(V )). This is not the case for planar graph. Bellman-Ford algorithm takes O(V E) (Halim & Halim 2013), but itIno Some example of special cases holds for V ≥ 3 by using the Euler’s formula. Therefore, the num the number of of connected components using DFS in a general graph t 4 Some example special cases 4.1.3. Problem Example that has examples O(E) in its time that can be changed into O(Vthe ). C We willexample look at some common of ifrunning special cases may occur in competitive planar graph. Therefore, the problem requires us to compute n 4.1.3 example Problem 4.1.3 Problem We use a that past programm Wesome will common use a pastexamples competitive programming problem illustrate the importance of the Bellman-Ford algorithm takes O(V E) (Halim & 100, Halim 2013), will look at of special cases that may occur in will competitive programming problems. lemWe example graph, even though theto constraint states Vcompetitive ≤ 000, E ≤ but 10 etitive programming illustrate theThe importance of the properties in a planar ramming problemproperties to problem illustrate the importance of ‘Traffic’ the properties in a planar in ato planar graph. problem from Central European Olympiad in graph. The ‘Traffic’ problem from Centra the number of connected components using DFS in a general gra under one second (in competitive programming, we assume that 1 4.1 this Planar graphs ontral illustrate the importance of the properties in a2011 planar lem from Central EuropeaninOlympiad in (CEOI) Informatics (CEOI) 2011this illustrates concept European Olympiad Informatics illustrates concept Informatics (CEOI) 2011 illustrates this concept well. In thiswell. problem, there isrequires a directed In problem this problem, there directed t planar graph. Therefore, if the us is toacompute (Halim & Halim 2013)). 4.1 Planar graphs mpiad Informatics 2011 this concept ere isgraph aindirected graph up to000 Villustrates = 300,is000 vertices given a 2D plane. There are graph with up to vertices in a 2D plane. There are two vertical lines cted with up to(CEOI) Vwith = 300, vertices given ingraph, athat 2D plane. There are two vertical lines denoted as ‘left’ and ‘rig Planar graph a graph can be drawn on a flat surface without having two edges even though the constraint states that V ≤ 100, 000, E≤ V‘left’ = 300, 000 vertices given a contained 2D plane. There are denoted as that ‘left’ and ‘right’. All are contained within the ‘left’ and ‘right’ lines, as andgraph ‘right’. Allgraph vertices are within the ‘left’ and ‘right’ lines, with some dto ‘right’. All vertices contained within theThere ‘left’ and ‘right’ lines, with some vertices possibly lying on these two lines. Planar is aare can be drawn onvertices a under flat surface without having two edges crossing each other (West etin al. 2001). are many graph problems which are easy to solve if the graph is plan one second (in competitive programming, we assume tha 4.1.2 Clique pr 2 the Maximum 2of visitable with some vertices possibly lying onsome these two lines. The ifproblem requires contestant are contained within the ‘left’ and ‘right’ lines, with these two2001). lines. The problem requires the contestant to print the number ines. The problem requires the contestant to print the number of solve visitable vertices lying on the line from eve et al. There are many graph problems which are easy to the graph is planar. We‘right’ will provide severa examples. (Halim & Halim 2013)). 2 2 lying on the ‘right’ line from every vertex lying to vertex print number of(which visitable vertices the contestant tothe print the number ht’every line from every lying on the ‘left’ of line (which we shall call problem ‘left’ vertices andus for mrequires vertex lying on the ‘left’ line wevisitable shall call ‘left’ vertices and The Maximum Clique requires to find the maximum set o ‘right’ vertices simplicity). An instanc examples. on the ‘left’ (which we shall call ‘left’ and ‘right’connected vertices forbysimplicity). An reduction from on the (which we shall call ‘left’ vertices and ity). An instance for this problem can be seen figure tance for‘left’ this line problem can beline seen on figure 5. on vertices in5.vertices the set is directly an edge. By 4.1.1 Number of edges Maximum Clique for this problem can beon seen on Fig. 5. is NP-hard. However, 4.1.2 em can be seen oninstance figure 5. graph it is easy to solve this prob 4.1.1general Number of edges simple general graph, number of edges upadjacent to a to quadratic withsa The bruteInforce solution for of this problem is runClique DFS from every ‘left’ vertex which Thethe Maximum problem requires us find the order maximum colouring a to graph such thatcan no be two vertices have the 2 . Itcan In simple general the number edges be up to a quadratic order with respect to the number of givesgraph, us a running time of of is very difficult to find a solution (if any) faster than vertices (i.e. O(V )). This is not the case for planar graph. In a planar graph, we vertices in the set is directly connected by an edge. By reduction size k in a graph, the set of the vertices inside the clique must be m co forThis this However, there is an important constraint on the problem. The vertices (i.e. O(V 2 )). isproblem. not case planar graph. In a planar graph, we may show that E ≤ 3V − holds for the V ≥ 3 byforusing the Euler’s formula. Therefore, the number of edges is O(V on general graph is NP-hard. However, it is easy to solve this6) given the in this problem is planar graph. Wechanged first relabel the ‘right’ vertices holds for V ≥graph 3 by using Euler’s formula. the of edges isno O(V ).).adjacent Naturally, any algorithm that has O(E) inalways its Therefore, running time can be into O(V Computing shortest of acolouring anumber graph such that two vertices havepat th Jonathan Irvin GUNAWAN 2 in ascending order according to the y-coordinate. The planar properties ensures that for that has O(E) in its running time can be changed into O(V ). Computing pathbut in a general graph using Bellman-Ford algorithm takes E) (Halim & Halim it only O(V ) in size k inO(V a graph, the set ofshortest the 2013), vertices inside thetakes clique must b 2 Bellman-Ford algorithm takes E) (Halim & Halim 2013), butusing it only takes ) in graph a planar graph. the O(V number of connected components DFS in aO(V general takes O(V Counting + E), b the number of connected components DFS in ifa the general graph takes O(V E), but the it only takesofO(V ) in a planar graph.using Therefore, problem requires us to+compute number connect 2 vertex v is visitable from vertex u if thereJonathan is a path from u to vGUNAWAN Irvin 2 in a planar planar graph. Therefore, ifgraph, the problem requires us to compute the number of connected components even though the constraint states that V ≤ 100, 000, E ≤ 100, 000 , the stand graph, even though the constraint that(inV competitive ≤ 100, 000, programming, E ≤ 100, 0002 ,we theassume standard DFS solutionoperations still runs under onestates second that 1 million under one second (in competitive (Halim &programming, Halim 2013)).we assume that 1 million operations can be done in 1 second (Halim & Halim 2013)). Understanding Unsolvable Problem 95 Fig. 5. An instance of problem ‘Traffic’. In this example, the expected output is {4, 4, 0, 2}, since the top ‘left’ vertex can visit 4 ‘right’ vertices, the second top ‘left’ vertex can2 visit 4 of O(V ). It is very difficult to find a ‘right’ vertices, the third top ‘left’ vertex cannot visit any ‘right’ vertex, and the bottom ‘left’ important constraint on the problem. vertex can visit 2 ‘right’ vertices. the ‘right’ vertices in ascending order ‘left’ the sequence ‘left’ the of visitable ‘left’ is is anof ‘right’ vis 2 2 vertices from thatvertex, 2‘right’ or this It is problem. very However, to find there a solution an sequence (if any) faster O(V ) forHowever, this problem. there fficult r).this problem. to finddifficult aevery solution However, (ifvertex, there any) isisfaster an than O(V ) forthan this problem. thereHowever, is an vertex we have removed all ‘right’ vertices w agraph. contiguous sequence, assuming we problem have removed all a‘right’ vertices arerelabel ways constraint planar graph. on the graph problem. We first first relabel The given that inis this is always planar graph. We first ways nntthe aaproblem. planar The We given relabel in graph this problem always a planar graph. We first relabelwhich not visitable from any ‘left’ vertex. With this property, there is a O(V log V ) solution solution (CEOI 2011 Solu ht’ anar vertices properties in ascending ensures that that order foraccording every to theThe y-coordinate. The planar properties anar scending properties order ensures according to for the every y-coordinate. planar properties ensures that forensures every that for every (CEOI 2011 Solutions, n.d.). tex, contiguous sequence sequence, of ‘right’ assuming visitable that vertices vertex issequence, a contiguous sequence, aace contiguous ofthe ‘right’ visitable sequence, vertices assuming fromthat that ‘left’ from vertexthat is a‘left’ contiguous assuming that assuming that evertex. removed With allthis this ‘right’ property, vertices there which a from not any visitable anyWith ‘left’this vertex. Withthere this property, there is a ight’ ertex. vertices With which property, are notthere visitable isis aare ‘left’ from vertex. property, is a g V ) solution (CEOI 2011 Solutions n.d.). CEOI 2011 Solutions n.d.). 4.2. Bipartite Graph Bipartite graph is a graph in which th edges connect a vertex from U and a the problem statement does not explic Bipartite graph is a graph in which the vertices can be partitioned into two disjoint sets used as an introduction for this pape and such such that all edges from and Va vertex from Somethat all oaph edisjoint disjoint graph issets sets a graph and inVVwhich such that canconnect be partitioned into two sets U andallV .such in which the UU and vertices canthe that bevertices partitioned all into twoa vertex disjoint sets U disjoint and such that instatement subtask 5does of this problem implicit problems have a bipartite graph as an input although the problem not onnect bipartite a vertex graph from as an U input and a although vertex from V . Some problems have a bipartite graph as an input although bipartite from U and graph a vertex as an input from Valthough . Some problems have a bipartite graph as an input although graph problems that are NP-hard for g explicitly state that the graph must be bipartite. problem that we usedthat we blem ust bestatement bipartite. does The not problem explicitly thatgiven state we given thatinput the given input graph must beThe bipartite. The ust does be not bipartite. explicitly The state problem that that the we input graph must be bipartite. The problem that weproblem bipartite graph and bipartite matchin as an for paper, IOIis 2014 Friend is aconstruction very goodThe example. The construcmple. Thepaper, construction for this ofpaper, the graph graph IOI 2014 Friend a very good example. of the graph mple. nanforintroduction this The construction IOIintroduction 2014 of the Friend isthis a very good example. The ofconstruction the graph that this type of problem may be con tionensures of the graph in subtask 5 ofthe this problem thatseveral the There final graph ask ways 5be be ofimplicitly this bipartite. problem There implicitly are several several ensures that final graph will alwaysensures be bipartite. are several ways oblem bipartite. There are that the final graph will always be implicitly bipartite. There are will always be bipartite. There are solvable several time graph that NP-hard general Since al roblems time ififthat the are graph NP-hard bipartite. forbut general Since graph in polynomial time ifare the graph isforbipartite. el time NP-hard the forgraph general isis bipartite. graph Since solvable in but polynomial if problems the graph is bipartite. Since 4.2.1 Vertex Cov graph but solvable in polynomial time if the graph is bipartite. Since bipartite graph andexpect ellabus graph(Forisek (Forisek and bipartite 2015), matching we can can expect expect was recently in IOI(Forisek 2015 syllabus 2015), we can partite labus matching 2015), was recently we included in IOI included 2015 syllabus 2015),(Forisek we can expect bipartite matching was recently included in IOI 2015 syllabus (Forišek, 2015), we can slll take type take abe look problem at several several mayinbe examples. conceived in the nearWe future IOI.a We take a look at several examples. em mayaof look conceived at examples. the near future of IOI. will of take lookwill at several examples. As we discussed in an earlier section, b expect that this type of problem may be conceived in the near future of IOI. We will are NP-hard. However, both of these take a look at several examples. aximum 4.2.1 matching) Vertex Cover and Independent Set (and maximum matching) aximum Vertex matching) Cover and Independent Set (and maximum matching) theorem, the size of the minimum ve matching (Bondy & Murty 1976), and Cover Independent (and Maximum Matching) iscussed MAX-INDEPENDENT-SET in an 4.2.1. earlierofVertex section, problems both and of the MIN-VERTEX-COVER and MAX-INDEPENDENT-SET problems MAX-INDEPENDENT-SET arlier section, both the MIN-VERTEX-COVER problems andSetMAX-INDEPENDENT-SET problems number ofand the vertices minus the size Asproblems we discussed in an earlier section, ofon thebipartite MIN-VERTEX-COVER time on However, bipartite both graph. of these By Konig’s problems solvableboth in polynomial time on bipartite graph.MAXBy Konig’s time ,hard. both on ofbipartite these graph. By areKonig’s solvable in are polynomial time graph. By Konig’s finding the size of the maximum bip INDEPENDENTSET problems NP-hard. However, bothsize of to these m, to the size size of ofvertex the minimum maximum cover in bipartite graph equal to the of the problems maximum are bipartite he o the minimum the maximum cover in vertex bipartite bipartite graph is are equal to the issize of the maximum bipartite maximum matching in bipartite graph solvable in polynomial time on bipartite graph. By Konig’s theorem, the size of the gset set (Bondy in bipartite bipartite &and Murty graph 1976), equal and to thethe the size of independent the maximum in bipartite graph urty in 1976), graph the size isis of equal the to maximum setindependent in bipartite set graph is equal to the is equal to the tomaximum solve, as compared to using Edmon minimum vertex in bipartite graph ismatching. equalboth to the size of the herefore, of the the vertices both problems minus the are size equivalent ofcover the maximum bipartite Therefore, both problemsbipartite are equivalent minus erefore, both sizeproblems of the maximum are equivalent bipartite matching. Therefore, problems are equivalent 5thindependent subtask of IOI 2014 Friend. 3 3 matching (Bondy and Murty, 1976), and the size of the maximum set in 3 3 ng n O(V the size ofbipartite the maximum bipartite whichincan be solved O(V time. Finding the size size of thematching, O(V )the time. he maximum matching, which can be solved )) time. Finding the of the O(V ) time.inFinding sizeFinding of the the size of the imum-Flow m matching algorithm in bipartite is much graph simpler using Hopcroft-Karp algorithm or Maximum-Flow algorithm mum-Flow bipartite graph algorithm using is Hopcroft-Karp much simpleralgorithm or Maximum-Flow algorithm is much simpleris much simpler h. , as This compared actually to using the solution solution Edmonds of the Blossom the on general algorithm on general graph. This is actually h. to This using isisEdmonds actually the Blossom algorithm of graph. This is actually the solution of the solution of the 4.3 of IOI 2014 Friend. 4ask Friend. 4.2 4.2 Graph Bipartite Graph Bipartite A directed acyclic graph is a directed g that graph problems NP-hard forthe general graph but inmatching polynomial if the included graph is in bipartite. hat are NP-hard graph but time solvable in graph polynomial timesolvable if Since the graph is bipartite. Since polynomial time iffor thegeneral graph is are bipartite. Since neral graph but solvable inthat polynomial if is bipartite. bipartite graph and bipartite wastime recently IOI 20 4.2.1 Vertex Cover and Independent Set (and maximum matching) bipartite graph and bipartite matching was recently included in IOI weIOI. can W and bipartite matching recently included in IOI 2015 syllabus (Forisek 2015), wesyllabus can expect I 2015 syllabus (Forisek 2015), wesyllabus can expect was recently included inwas IOI 2015 (Forisek 2015), we expect that this type of can problem may be2015 conceived in (Forisek the near 2015), future of that this typeof ofIOI. problem may be aconceived in the near future ofatIOI. We examples. will take a look at several examp problem may be conceived in the near future of IOI. We will take a look several OI. We will take a look at several examples. ived in the near future We will take look at several examples. e discussed in an earlier section, both of the MIN-VERTEX-COVER and MAX-INDEPENDENT-SET problems 4.2.1 Vertex Independent NP-hard. However, both of these problems are solvableJ.I.inGunawan polynomial time onCover bipartiteand graph. By Konig’s Set (a 96matching) 4.2.1 Vertex Cover and Independent Set (and maximum matching) Vertex Cover and Independent Set (and maximum matching) tr.2.1 (and maximum and Independent Set (and maximum matching) em, the size of the minimum vertex cover in As bipartite graph in is equal to the size of theofmaximum bipartite we discussed an earlier section, both the MIN-VERTEX-COVER hing (Bondy & Murty 1976), and the size of the maximum independent set in bipartite graph is equal to thein polyno bipartite graph is equal to theare number of MIN-VERTEX-COVER the vertices minusofthe size of the maximum in Assection, we discussed in an earlier section, both of the andproblems MAX-INDEPENDENT-SET pro nh an earlier both of the MIN-VERTEX-COVER and MAX-INDEPENDENT-SET problems VER and MAX-INDEPENDENT-SET problems of the MIN-VERTEX-COVER and MAX-INDEPENDENT-SET problems NP-hard. However, both these are solvable ber of theboth vertices minus the size are ofboth the maximum bipartite Therefore, problems are equivalent bipartite matching. Therefore, both problems are equivalent toboth finding the size of the graph. are solvable NP-hard. However, ofon these problems are solvable in polynomial time on bipartite owever, of problems solvable in polynomial time bipartite graph. By Konig’s lynomial time onthese bipartite graph. By Konig’s problems are in polynomial time bipartite graph. By Konig’s theorem, thematching. size ofon the minimum vertex cover in bipartite graphBy is eK 3 time. Finding the size maximum bipartite which can bebe solved in nding the minimum size of size the maximum bipartite matching, which caninto solved in )equal time. Finding ofmaximum the indepe eisofequal the vertex cover in bipartite graph is cover equal the size of O(V the ismaximum bipartite theorem, the size the minimum vertex bipartite graph to the ofsize the bi to the of the maximum bipartite ex cover in bipartite graph isof equal tomatching, the size of the maximum matching (Bondy &bipartite Murty 1976), and the size size ofthe the maximum of the maximum matching in bipartite graph using Hopcroft-Karp algorithm or Maximum matching in bipartite graph using Hopcroft-Karp algorithm or Maximum-Flow algorithm is much simpler (Bondy & Murty 1976), and the graph size of isthe maximum setmaximum in bipartite graph ismatchin equal yhe&size Murty 1976), and theindependent size ofisthe maximum independent set in bipartite graph to the bipartite dependent set in bipartite graph equal of matching the maximum setto in the bipartite equal tominus the independent number of the vertices the sizeisofequal the mum-Flow algorithm is much simpler toTherefore, solve, asgraph. compared using Edmonds Bloslve, asminus compared to Edmonds Blossom algorithm on general This to is bipartite actually the solution of the ertices number of using the vertices minus the size of the maximum bipartite matching. Therefore, both problems rtices the size of problems the maximum bipartite both problems are equivalent ching. Therefore, both are equivalent the maximum bipartite matching. Therefore, both problems are tomatching. finding the sizeequivalent of the maximum matching, which canare beequ sol so algorithm on general graph. This is actually of IOI 3the solution of the 5th subtask 3 3 som 3the ubtask IOI 2014 Friend. toO(V finding the size of the maximum bipartite matching, which can be solved in O(V ) time. Finding the size e solved of matching, theofin maximum bipartite matching, which can be solved in O(V ) time. Finding the size of the ertite ) time. Finding the size of which can be solved in O(V ) time. Finding the sizeinofbipartite the maximum matching graph using Hopcroft-Karp algorithm or 2014 Friend. ingorin bipartite graph using Hopcroft-Karp algorithm orHopcroft-Karp Maximum-Flow algorithm much simpleralgorithm maximum matching bipartite graph algorithm or isMaximum-Flow algorithmonis general much s m Maximum-Flow algorithm much simpler sing Hopcroft-Karp algorithm orinisMaximum-Flow algorithm is much simpler to using solve, as compared to using Edmonds Blossom th th to solve, toalgorithm usingThis Edmonds Blossom algorithm on general is actually the solution pared to using Edmonds Blossom on general graph. This is thegraph. solutionThis of the graph. This is as actually the graph. solution of the seral Blossom algorithm oncompared general is 5actually theofsolution of actually the subtask IOI 2014 Friend. 5th subtask IOI 2014 Friend. OI 2014 Friend. 4.3 Directed Acyclic Graph 4.3. of Directed Acyclic Graph ected acyclic graph is a directed graph that does not contain any cycle. Similar to planar and bipartite graphs, 4.3acyclic Directed Acyclic are several graphAproblems that aregraph muchiseasier to solve if the is a contain directed directed acyclic a directed graph thatgraph does not any cycle.graph. Similar to 4.3 Directed Acyclic Graph 4.3 Directed Graph c Graph Directed Acyclic Graph Acyclic G planar and bipartite graphs, A there are several thatgraph are much easiernot to contain any c directed acyclicgraph graph problems is a directed that does Minimum Path Cover A acyclic graph is4.3.1 anot graph that does not graphs, contain cycle. to planar solve if the graph isSimilar a directed directed acyclic graph. cnygraph a directed graph that does contain anyare cycle. Similar to planarany andthat bipartite graphs, cycle. Similar planar and bipartite graphs, aph that isdoes notto contain any cycle. tothere planar and bipartite several graph problems areSimilar much easier to and solvebipartite if the gr g there are several graph problems thatif are much easier to solveacyclic if the graph is a directed acyclic graph. graph problems that are much easier to solve the graph is a directed graph. he graph is a directed acyclic graph. re much easier to solve if the graph is a directed acyclic graph. -PATH-COVER is a problem that requries us to find the minimum number of vertex-disjoint paths needed 4.3.1. Minimum Path Cover 4.3.1 Minimum Path Cov over all of the vertices in a graph. By a simple reduction from Hamiltonian Path, this problem is NP-hard. MIN-PATH-COVER is a Path problem that requires us Path to findCover the minimum number of 4.3.1 Minimum Cover 4.3.1 Minimum Cover 4.3.1 Minimum Path Cover aph has a Hamiltonian Path if and only if we MIN-PATH-COVER only need one path to all ofthat the vertices. However, is cover a problem requries us to refind this the minimu vertex-disjoint paths needed to cover all of the vertices in a graph. By a simple em can be solved in polynomial time for a directed acyclic graph. For a graph G = (V, E), we create a new from VER is a problem that requries us to find the minimum number of vertex-disjoint paths needed is anumber problem that requries to isfind the minimum number of vertex-disjoint pathsHn imum number of duction vertex-disjoint paths needed requries usMIN-PATH-COVER to find the minimum of Path, vertex-disjoint needed to cover all us ofpaths the vertices in Aa graph graph. ByaaHamiltonian simple reduction from Hamiltonian this problem NP-hard. has hhe G (Vout ∪ ,all E this ), where Voutifis= = VA and E = {(u, v) ∈ Vout × Vthe :ifvertices. (u, v)isonly ∈NP-hard. E}. Then it can beone path in in toincover of the inVin aonly graph. By ahas simple reduction from Hamiltonian this problem is NP vertices a VPath, graph. a vertices simple reduction from Hamiltonian Path, problem m Hamiltonian problem NP-hard. By a=simple reduction from Hamiltonian Path, this problem is NP-hard. graph a to Hamiltonian Path and ifPath, we only need Path ifBy and only we need one path cover allthis of However, this n bytoKonig’s Theorem that G has a matching of size m if and only if there exist |V | − m vertex-disjoint graph has avertices. Hamiltonian Path if and only if we only need one path to cover all of the vertices. Howeve amiltonian Path ifproblem and only if we only need one path to cover all of the vertices. However, this ath all of the However, this only if cover weAonly need one path to cover all of the vertices. However, this problem can be solved in polynomial time for a directed acyclic graph. can be solved in polynomial time for a directed acyclic graph. For a graph For ssolved that cover all ofacyclic vertices indirected G. for , awe graph. aout graph = E), we create ainnew problem can begraph. solved in polynomial time for a we directed For a=graph (V, create aph. apolynomial graph Gthe =time (V, E), we create anew new me forFor aindirected For a graph Ggraph = (V,G E), create aG,new graph = (V ∪ Vacyclic E (V, ), ,graph. where Vout Vin =GV= and E =we{(u, v) ∈ create aacyclic where and E), in out in out graph G = (V ∪inV∈= E and ),it V{(u, V∈ =Then V×and E =be {(u, v)by ∈Konig’s Vhas × V (u, v) E}.mThen it ∪V EV ), V= = Vv) v) VitTheorem : (u, v) ∈ E}. Then itmatching can ∈ V,out × where V v){(u, ∈ E}. Then can be .out can be shown Theorem that = Vin = and V,Vout ×where VEin = : (u, v)= ∈by E}. Then it can shown Konig’s that G of∈size if and out in out inV out a in :be out in in :E(u, ttv) in Konig’s by Theorem that athat of of size |V | − m vertex-d has matching size has and only there exist vertex-disjoint vertex-disjoint ’s that G has matching of sizeGexist m ifif and only ifif there exist |Vif |and − monly and only ifshown there exist − monly vertex-disjoint 4.4 Miscellaneous s aTheorem matching of size m|Vifa| and ifof there |V | matching − m vertex-disjoint paths cover all themvertices in G.if there existpaths that cover all all of of the the vertices in that in G. . vertices in cover G. .all of the paths 4.4.1 Special case of CNF-SAT problem 4.4 Miscellaneous will use Google Code Jam 4.4 2008 Round 1A ‘Milkshake’ for this example. This problem requires the Miscellaneous 4.4problem Miscellaneous ous 4.4 Miscellaneous 4.4. Miscellaneous 4.4.1 Special case with of CNF-SAT estant to find a solution with the minimum number of true variables that satisfy a CNF-SAT problem up 4.4.1 Special case of CNF-SAT problem 4.4.1 Special case of CNF-SAT problem SAT problem Special case of CNF-SAT problem We will use Google Code Jam 2008 Round 1A ‘Milkshake’ problem fo 4.4.1. Special Case of CNF-SAT Problem gle Code Jam 2008 Round 1A ‘Milkshake’ problem for example. Thiswith problem requires We will use Google Code Jam 2008 Round 1Athis problem for example. This of problem requir m for1A this example. requires und ‘Milkshake’ problem this example. This requires the contestant to‘Milkshake’ find a‘Milkshake’ solution thethis minimum number true variable than Irvin GUNAWAN WeThis will problem use for Google Code the Jam 2008problem Round 1A problem for this the example. contestant to find a problem solution with the minimum number of atrue variables that satisfy a CNF-SAT problem w dinimum a solution withofThis the minimum number ofthetrue variables satisfy CNF-SAT withnumber up ables that satisfy a true CNF-SAT up number variables that satisfy a CNF-SAT problem with upwith problem requires contestant tothat find a solution theproblem minimum of true variables that satisfy a Jonathan CNF-SATIrvin problem with up to 2,000 variables (Google GUNAWAN Code 2008 Round 1A, ‘Milkshake’ problem, n.d.). The CNF-SAT is a satisfiability IrvinJam GUNAWAN UNAWANJonathan problem given in a conjunctive normal form (i.e. conjunction of disjunction of literals) which was proven to be NP-hard (Cook, 1971). Therefore, it is unlikely that there is an algorithm to solve a CNF-SAT problem with 2,000 variables in less than 8 minutes3. However, there is a special property in this problem, in which at most one unnegated literal exists in each clause. Therefore, all clauses can be converted into Horn clauses. With this property, a linear time algorithm exists. (Google Code Jam 2008 Round 1A, ‘Milkshake’ solution, n.d.). 3 In Google Code Jam, contestants are given 8 minutes to produce the output upon downloading the input. Understanding Unsolvable Problem 97 5. Conclusion In conclusion, we can use a well-known reduction technique to prove that a problem that we are currently attempting to solve is impossible (or at least it is very hard such that no people has been able to solve it for more than 40 years). In competitive programming (including IOI), understanding this technique is essential so that we will not be stuck at trying to solve an impossible problem, thus prompting us to find another way to solve the problem. To prove that a problem is NP-hard, it is good to know as many NP-hard problems as possible, so that we can reduce from any one of the problems that we know to the new problem. Some of the classic NP-hard problems include 3-SAT, Vertex Cover, Independent Set, and Subset Sum. After realizing that the problem is NP-hard, we must be able to find the special case that makes the problem solvable. We must be able to find a special property that breaks the reduction proof. Having a lot of practice on these kind of problems will help us to familiarize with the possibilities of a special case. Some of the common special cases include planar, bipartite, and directed acyclic graph. References ACM ICPC World Finals 2010 Problem Statement (n.d.). Available via internet: http://icpc.baylor.edu/download/worldfinals/problems/2010WorldFinalProblemSet.pdf ACM ICPC World Finals 2010 Solutions (n.d.). Available via internet: http://www.csc.kth.se/~austrin/icpc/finals2010solutions.pdf Bondy, J.A., Murty, U. S. R. (1976). Graph Theory with Applications, Vol. 290, London: Macmillan. CEOI 2011 Solutions (n.d.). Available via internet: http://ceoi.inf.elte.hu/probarch/11/ceoi2011booklet.pdf CEOI 2011. ‘Traffic’ Problem (n.d.), available via internet: http://ceoi.inf.elte.hu/probarch/11/trazad.pdf Cook, S.A. (1971). The complexity of theorem-proving procedures. In: Proceedings of the Third Annual ACM Symposium on Theory of Computing. ACM, 151–158. Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C. (2009). Introduction to Algorithms (3rd ed.). MIT Press. Forišek, M. (2015). International olympiad in informatics 2015 syllabus. Available via internet: https://people.ksp.sk/~misof/ioi-syllabus/ioi-syllabus.pdf Gonthier, G. (2005). A computer-checked proof of the four colour theorem. Available via internet: http://research.microsoft.com/en-us/people/gonthier/4colproof.pdf Google Code Jam 2008 Round 1A, ‘Milkshake’ Problem (n.d.). Available via internet: https://code.google.com/codejam/contest/32016/dashboard#s=p1 Google Code Jam 2008 Round 1A, ‘Milkshake’ solution (n.d.). Available via internet: https://code.google.com/codejam/contest/32016/dashboard#s=a&a=1 Halim, S., Halim, F. (2013). Competitve Programming 3. lulu.com IOI 2008, ‘Island’ Problem (n.d.). Available via internet: http://www.ioinformatics.org/locations/ioi08/contest/day1/islands.pdf IOI 2014, ‘Friend’ Problem (n.d.). Available via internet: http://www.ioinformatics.org/locations/ioi14/contest/day2/friend/friend.pdf West, D. B. et al. (2001). Introduction to Graph Theory, Vol. 2. Prentice hall Upper Saddle River. 98 J.I. Gunawan J.I. Gunawan is an undergraduate student studying Computer Science in National University of Singapore. He participated a lot of programming contests, including IOI 2012 and 2013 and ACM ICPC World Finals 2014 and 2015. He is also the lead of the Scientific Committee of Indonesian Computing Olympiad team (TOKI) training Indonesian teams for IOI in 2015–2016.