P is the class of decision problems decided by a deterministic algorithm in time polynomial in the encoded input length. NP is the class whose yes-instances have complexity certificates of polynomial length that a deterministic algorithm verifies in polynomial time.
A decision problem is NP-complete if it belongs to NP and is NP-hard: every problem in NP admits a polynomial-time many-one reduction to it. Such a reduction maps an instance to an instance in polynomial time and satisfies is a yes-instance if and only if is a yes-instance. Membership in NP and NP-hardness are both required.
Run Breadth-first search separately in every component of the undirected graph. Give a starting vertex colour zero and each newly discovered neighbour the opposite colour. Reject if an edge joins two vertices with the same assigned colour; otherwise accept after all components have been explored.
If the algorithm accepts, its assignments constitute a graph colouring with two colours. If it rejects, the two search-tree paths and the conflicting edge contain an odd cycle, on which alternating two colours cannot close consistently. Equivalently, a valid graph colouring with two colours fixes the parity of every path from a component's root, so the detected conflict is impossible in a two-colourable graph. The Breadth-first search work is with adjacency lists. ThereforeThis is also the two-colourability criterion for bipartite graphs.
The displayed graph consists of three graph triangles sharing the vertex . In a graph colouring with three colours, every graph triangle uses all three colours. The edge and the edges therefore force to be the two colours different from . Likewise the graph triangle forces to be those same two colours. The third graph triangle imposes no further restriction on these four vertices. HenceBoth two-element sets and their union have cardinality two. This is a Boolean-pair colouring gadget: after fixing a palette graph triangle, the pair encodes opposite truth values.
Name the upper graph triangle's vertices , where is adjacent to and to . Name the middle left vertex and the lower right vertex . Then is adjacent to , the lower graph triangle is , and is adjacent to .
Suppose all have colour , while has a different colour ; denote the third colour by . In the upper graph triangle, and cannot have colour and are adjacent, so they have colours in some order and has colour . In the lower graph triangle, is adjacent to both and , forcing to have colour , and then must have colour . But the edge now has equal-coloured endpoints, a contradiction. ThusFor the three-colour clause gadget used in a reduction, one also needs the converse extension property for Boolean-coloured inputs. With and , every tuple other than extends. If , take ; this works regardless of . If , take . Finally, if , take . Each assignment satisfies every edge. Therefore this three-colour clause gadget realizes exactly a three-input disjunction on Boolean inputs.
The three-colourability problem belongs to NP: a colour assignment is a polynomial-length complexity certificate, and all edges can be checked in time.
For NP-hardness, reduce 3-SAT to the three-colourability problem. Start with a palette graph triangle with vertices . Its colours are necessarily distinct, and name them by these vertices. For each Boolean variable , add vertices , join them to each other, and join each to . The graph triangle is the forcing component of the Boolean-pair colouring gadget, so the two literal vertices receive opposite colours .
For each Boolean clause, attach a fresh copy of the three-colour clause gadget, identify its with the palette vertex , and identify its three input vertices with the Boolean clause's Boolean literal vertices. Copies share only palette or literal vertices. A Boolean clause with one or two Boolean literals is padded to three by repeating a literal; an empty Boolean clause can be mapped immediately to the uncolourable graph .
Any graph colouring with three colours gives a truth assignment by reading colour as true. The three-colour clause gadget forbids three false inputs, so every Boolean clause is satisfied. Conversely, any satisfying truth assignment colours the literal pairs, and the extension property proved above independently colours the fresh auxiliary vertices of each clause. Thus the entire graph is three-colourable exactly when the formula is satisfiable.
There are vertices for variables and nonempty padded clauses, and edges. The construction is a polynomial-time many-one reduction. Using the permitted NP-completeness of 3-SAT, we obtain
Articles by others on the same topic
There are currently no matching articles.