Draft:Binary Paint shop problem
Submission declined on 29 September 2026 by Beta Beta Beta (talk).
Where to get help
How to improve a draft
You can also browse Wikipedia:Featured articles and Wikipedia:Good articles to find examples of Wikipedia's best writing on topics similar to your proposed article. Improving your odds of a speedy review To improve your odds of a faster review, tag your draft with relevant WikiProject tags using the button below. This will let reviewers know a new draft has been submitted in their area of interest. For instance, if you wrote about a female astronomer, you would want to add the Biography, Astronomy, and Women scientists tags. Editor resources
|
Binary Paintshop problem
[edit]Description
[edit]The binary paintshop problem is an operations research problem. Its description is simple, but finding an optimal solution can be difficult.
Let be an integer, and let the alphabet contain characters. The input is a word of length in which each character appears exactly twice. Color the two occurrences of each character differently: one blue and one red.
The goal is to color the word while minimizing the number of color changes between adjacent letters.
For example, if , the alphabet is , and the word is abacbc. One possible coloring, in order, is blue, red, red, red, blue, blue. It has two color changes, which is the minimum for this example.
A presentation of the problem can be found in this paper.
The binary paintshop problem is a special case of a more general problem in which letters may appear different numbers of times and more than two colors may be used. In that general problem, no two occurrences of the same letter may receive the same color.
History
[edit]This problem comes from the early age of car factory. At the time, changing the painting color was an expensive and long part of the production. Therefore in the production line, one goal was to reduce the amount of changes, though it was possible to invert some of the models, this being complicated we restrain the possibility to have an easy modelisation.
Computational complexity
[edit]Brute-force algorithm
[edit]Each character has two possible assignments of blue and red to its two occurrences. Thus, there are possible colorings to consider. Given one such coloring, we can check its validity and count its color changes in time. Exhaustive search therefore takes time.
NP and certificates
[edit]A decision problem is in the class NP if every “yes” instance has a certificate of polynomial length that a deterministic algorithm can verify in polynomial time.
The decision version of the binary paintshop problem asks:
- Given a word and an integer , is there a valid coloring with at most color changes?
A certificate is a coloring of the word. To verify it, check that the two occurrences of each character have different colors, then count the color changes and check that their number is at most . If the letters are indexed by an array, this takes time linear in the word length. Therefore, the decision problem is in NP.
An equivalent definition is that a decision problem is in NP if a non-deterministic Turing machine can decide it in polynomial time.
Why the two definitions of NP are equivalent
Suppose a non-deterministic Turing machine decides a problem in polynomial time. A certificate can describe one accepting computation path, including its states, transitions, and nondeterministic choices. The path has polynomial length. A deterministic verifier can check, step by step, that each transition is legal and that the path ends in an accepting state.
Conversely, suppose every “yes” instance has a certificate of polynomial length that a deterministic verifier can check in polynomial time. A non-deterministic Turing machine can guess and run the verifier on . It accepts exactly when the verifier accepts. The machine runs in polynomial time and accepts if and only if a valid certificate exists.
NP-hardness and NP-completeness
[edit]A decision problem is NP-hard if every problem in NP can be reduced to it in polynomial time. In particular, a polynomial-time algorithm for an NP-hard problem would give a polynomial-time algorithm for every problem in NP.
A problem that is both NP-hard and in NP is called NP-complete.
The Cook–Levin theorem establishes that Boolean satisfiability (SAT) is NP-complete. The proof below outlines the tableau construction.
Cook–Levin theorem
A SAT instance is a Boolean formula. The question is whether there is an assignment of truth values to its variables that makes the formula true. SAT is in NP because a truth assignment is a certificate that can be checked in polynomial time.
To show that SAT is NP-hard, take any decision problem in NP. There is a non-deterministic Turing machine that decides in polynomial time. We construct, for each input word , a Boolean formula that is satisfiable if and only if accepts . Encoding the computation
Let be the length of , and let be a polynomial bound on the number of steps taken by . We may assume that an accepting computation can be extended to exactly steps by giving accepting states transitions that leave the configuration unchanged.
Use a one-tape machine whose head moves at most one cell per step. The input is written in cells , and the head starts at cell . During steps, the head cannot leave the tape interval
The formula describes a computation table. Each row is a time step; the entries record the machine state, head position, and tape contents. Introduce Boolean variables:
- is true if tape cell contains symbol at time .
- is true if the head is at cell at time .
- is true if the machine is in state at time .
Here, , , belongs to the fixed tape alphabet , and belongs to the fixed state set . Since and and are fixed for , the number of variables is polynomial in . Valid configurations
At each time, exactly one state is active:
At each time, the head is in exactly one position:
For every time and tape cell, exactly one tape symbol is present:
Initial configuration
Let be the start state, and let denote the blank symbol. The initial state and head position are specified by
For each input position , set the corresponding tape cell to the input symbol :
All other cells in start blank:
Legal transitions
Write a transition as . For each , let be the set of allowed transitions from state reading whose destination cell belongs to .
For each time , position , state , and symbol , require that if the machine is in state at and reads , one of the allowed transitions occurs:
The last conjunction requires every tape cell other than the one under the head to keep its symbol. The disjunction represents the machine's nondeterministic choices. If no transition is available for the current state and symbol, the disjunction is false.
Acceptance
Let be the set of accepting states. Require the machine to be in an accepting state at time :
The formula has polynomial size. There are polynomially many time steps and tape cells, and the state set, tape alphabet, and transition relation are fixed for . Even the transition constraints, which can refer to every tape cell, have polynomial total size. The formula can be constructed in polynomial time. If SAT is expressed using conjunctive normal form, the formula can be converted to an equisatisfiable CNF formula of polynomial size using auxiliary variables.
Correctness
If has an accepting computation on , its configurations give values to the variables that satisfy the formula. Conversely, any satisfying assignment describes a valid sequence of configurations of on ending in an accepting state. Thus the formula is satisfiable if and only if accepts .
Therefore, every problem in NP reduces to SAT in polynomial time. SAT is NP-hard and is also in NP, so it is NP-complete.
APX, PTAS, and APX-hardness
[edit]These definitions concern optimization problems. Assume that feasible solutions can be represented and checked in polynomial time and that their objective values can be computed in polynomial time.
For a minimization problem, an algorithm is a -approximation if it returns a feasible solution of cost at most , where is the minimum possible cost and . For a maximization problem, it is a -approximation if it returns a feasible solution of value at least .
- APX
The class APX consists of the optimization problems that have a polynomial-time approximation algorithm with some fixed constant approximation factor.
- PTAS
A polynomial-time approximation scheme (PTAS) is a family of algorithms with the following guarantee: for every fixed , there is a polynomial-time algorithm that returns a -approximation. The degree of the running-time polynomial may depend on .
- PTAS reduction
A PTAS reduction transforms instances and solutions of one optimization problem into instances and solutions of another while preserving arbitrarily accurate approximation.
A problem PTAS-reduces to a problem if, for every , there are polynomial-time procedures (for fixed ) and a value such that:
- An instance of is transformed into an instance of .
- Any -approximate solution to can be transformed into a -approximate solution to .
The reduction may choose the target accuracy as a function of the desired source accuracy .
- APX-hardness
An optimization problem is APX-hard if every problem in APX PTAS-reduces to . If had a PTAS, then every problem in APX would have a PTAS. Under the standard assumption , APX-hard problems therefore have no PTAS.
A problem is APX-complete if it is both APX-hard and in APX. APX-hardness is a stronger approximation-hardness result than NP-hardness.
NP-hardness of the binary paintshop problem
[edit]Bonsma, Epping, and Hochstättler proved that the decision version of the binary paintshop problem is NP-complete and that its optimization version is APX-hard.[1] The proof below gives the reduction from vertex cover on cubic graphs.
Orientation lemma
[edit]The reduction uses an ordering and orientation of the edges of a graph.
Lemma. Every simple graph of maximum degree at most 3 has a total vertex order and an orientation of its edges such that:
- Each vertex has at most one incoming arc from a vertex earlier in the order and at most one incoming arc from a vertex later in the order.
- Every vertex of degree 2 has exactly one incoming arc.
The order and orientation can be found in polynomial time.
Proof. We use induction on . If is disconnected, apply the induction hypothesis to each connected component and concatenate their orders. Since there are no edges between components, the in-neighbors and their relative order within each component are unchanged. It therefore suffices to consider connected graphs.
The result is immediate for a graph with one vertex. For a larger connected graph, consider the following cases.
- 1. has a vertex of degree 1
Let be a leaf with neighbor . Apply induction to .
If has degree 1 in , then consists of the edge , which can be oriented arbitrarily.
If has degree 2 in , it has degree 1 in . If its existing edge is directed into , orient the new edge as . Otherwise, orient it as . In either case, has exactly one incoming arc.
If has degree 3 in , it has degree 2 in and already has exactly one incoming arc. Orient the new edge as and place last in the order. This does not add an incoming arc to .
In each case, the conditions are preserved.
- 2. has a degree-2 vertex with neighbors , where
Form . Apply induction to . Relabel if necessary so that . Replace the oriented edge between and with a directed path through , and insert between and . For example, replace by , or replace by .
The direction and relative order of the corresponding edge at each of and are preserved. The new degree-2 vertex has exactly one incoming arc.
- 3. has a degree-2 vertex with neighbors , where
Apply induction to . Rename so that the existing edge is oriented . The degree of in is at most 2, so it has at most one incoming neighbor; call it , if it has one.
Add the arcs and . If exists and , insert immediately after . Otherwise, insert immediately before . The new incoming neighbor is on the opposite side of from , if exists. Thus has at most one incoming neighbor on either side. The incoming neighbors of are unchanged, and has exactly one incoming arc, from . The conditions are preserved.
- 4. Every vertex of has degree 3
Choose a vertex and apply induction to . Its three neighbors have degree 2 in , so each has exactly one incoming neighbor there.
For each of , that incoming neighbor is either earlier or later in the order. By the pigeonhole principle, at least two of the three vertices have the same relation. Name those two , and name their incoming neighbors . Thus either and , or and .
In the first case, insert after both and ; in the second case, insert it before both. Add the arcs , , and . Each of and now has two incoming neighbors, one on either side in the order. The incoming neighbors of are unchanged, and has exactly one incoming arc.
This proves the lemma. The induction makes at most a polynomial number of graph modifications and order operations, so the ordering and orientation can be found in polynomial time.
The reduction
[edit]Take an instance of vertex cover on cubic graphs, where and . Apply the orientation lemma and renumber the vertices so that and exactly when .
At each vertex , order its three incident arcs as as follows:
- If an arc enters from an earlier vertex, place it first.
- If an arc enters from a later vertex, place it last.
- Place any remaining incident arcs in the remaining positions.
The orientation lemma guarantees that these instructions do not conflict: there is at most one incoming arc from an earlier vertex and at most one from a later vertex. Write for the letter associated with arc .
Create the letters for each vertex , the letter for each arc , and the letter for each pair of vertices with . Define the block for vertex by
An empty sequence of -letters is omitted. The constructed word is
Every letter appears exactly twice. Each appears twice in ; each appears once in the blocks of the two endpoints of arc ; and each appears once in and once in . Thus is a valid binary paintshop instance. It has length , so the construction takes polynomial time.
Correctness
[edit]For a coloring, call a gap between adjacent letters a change if the colors on the two sides differ. For a letter , let be the interval between its two occurrences. The coloring is valid if and only if every contains an odd number of changes: traversing an odd number of changes switches the color, while an even number leaves it unchanged.
Let be the minimum size of a vertex cover in . We prove that
- Lower bound
Consider any valid coloring, and let be the number of changes strictly inside block , not counting a gap between consecutive blocks. The adjacent pairs and each force a change, so .
Suppose . The interval contains the change between and must contain an odd number of changes. There can be at most one other change in the block. It follows that contains exactly one change: the one between .
Now consider an edge with , and let be its oriented arc. In block , occurs before , while occurs after it. If , there is exactly one change between these occurrences of and . In block , both and occur before . If , there are no changes between them: the only change inside is the one at , which comes after both letters.
The intervals and share the part between the occurrence of in and its occurrence in . The parts in which they differ are precisely the segment from to in and the segment from to in . Together these segments contain an odd number of changes: one in and none in . Therefore and have opposite parities, contradicting validity, which requires both to have odd parity.
Consequently, for every edge , at least one of is at least 4. The set
is therefore a vertex cover. Every block has at least two changes, and each block indexed by has at least two additional changes. Hence the total number of changes, including any changes between blocks, is at least
Thus .
- Upper bound
Let be a vertex cover of . We specify gaps at which to change color. Start the word blue and toggle the color at each specified gap.
In every block , place changes in the gaps and . If , also place two changes:
- , immediately before the first of the three -letters. This is the gap between the last -letter in the prefix and the first -letter. If there is no -letter in the prefix, use the gap between the first and the first -letter.
- , immediately after the last -letter and before the first .
For an edge whose endpoints are both in , shift one of these additional changes:
- If with , then is first among the -letters in . Move one gap to the right, immediately after .
- If with , then is last among the -letters in . Move one gap to the left, immediately before .
The ordering of incident arcs ensures that the specified letters are adjacent. The orientation lemma also ensures that at most one incoming arc from an earlier vertex and at most one from a later vertex can cause a shift at any vertex. Thus the prescribed gaps are distinct.
We check that every pair of equal letters has an odd number of changes between its occurrences.
- Each of and has exactly one change between its adjacent occurrences.
- The interval contains the change at . If , it also contains and . It therefore contains either one or three changes.
- For , where , the interval between its occurrences contains the change at . It contains no changes in the prefix of before . Any complete blocks between and contain either two or four changes, and there are no changes between blocks. Thus contains an odd number of changes.
- For an edge , where , compare and . The parts in which these intervals differ are the segment from to in and the segment from to in . The first contains the change at . Since is a vertex cover, at least one endpoint of the edge belongs to . The placement and shifting rules ensure that exactly one additional change, either or , lies in these two segments. If both endpoints are in , the change at the head of the arc is shifted out of its segment, leaving the change at the other endpoint inside. The ordering of the incident arcs ensures that shifts made for other edges do not remove this remaining change. The two differing segments therefore contain an even number of changes: the change at and exactly one additional change. It follows that and have the same parity. Since has odd parity, so does .
The specified changes therefore give a valid coloring. Each block has exactly two changes if and exactly four if . In either case, the number of changes in the block is even, so every block ends in the same color in which it began. There are no changes between blocks. The total number of changes is .
Taking to be a minimum vertex cover gives . Together with the lower bound, this proves
Conclusion
[edit]Map the cubic vertex-cover instance to the word constructed above and the paintshop threshold
The optimum-value equality gives
The construction is polynomial-time, so it is a polynomial-time many-one reduction. The decision version of the binary paintshop problem is therefore NP-hard. Since it is also in NP, it is NP-complete. The same paper proves the stronger result that the optimization problem is APX-hard.[1]
APX-hardness of the binary paint shop problem
[edit]APX-hardness
[edit]Minimum vertex cover on cubic graphs is APX-hard.[2] We use the same reduction as before.
Let be a cubic graph, let , and let be the size of a minimum vertex cover. Construct the corresponding binary paintshop word as in the previous section. Its optimum number of color changes is
Suppose there is a PTAS for the binary paintshop problem. For any , apply it to the constructed word and let be the number of changes in the coloring it returns. Then
Let be the number of changes inside block , excluding any change between blocks. As shown in the previous section, the vertices whose blocks have at least four changes form a vertex cover. Let
Each block has at least two changes. Each block in has at least two additional changes. Changes between blocks can only add to the total, so
Therefore, is a vertex cover and
A cubic graph has edges, and each vertex covers at most three edges. Thus every vertex cover has size at least
It follows that
Thus, a -approximation for the binary paintshop problem gives a -approximation for minimum vertex cover on cubic graphs. By choosing appropriately, a PTAS for the binary paintshop problem would give a PTAS for cubic vertex cover.
Since minimum vertex cover on cubic graphs is APX-hard, this approximation-preserving reduction shows that the binary paintshop optimization problem is APX-hard.
Complexity under unique game conjecture
[edit]Under [Unique games conjecture], as one can reduce min uncut problem to binary paint shop problem, one can show that, there is no constant approximation algorithm in polynomial time for the binary paint shop problem. Therefore one can only hope to use heuristic that holds on most instances, or that hold in probability assuming uniform distribution of words.
Algorithms
[edit]As the problem is NP Hard, searching a polynomial time algorithm would be a loose of time, but there exist some approximation algorithms.
References
[edit]- 1 2 P. Bonsma, T. Epping, and W. Hochstättler, “Complexity results on restricted instances of a paint shop problem for words,” Discrete Applied Mathematics, 154(9), 1335–1343, 2006.
- ↑ Paola Alimonti and Viggo Kann, “Some APX-completeness results for cubic graphs,” Theoretical Computer Science, 237(1–2), 123–134, 2000.

- Reliable sources include: reputable newspapers, magazines, academic journals, and books from respected publishers.
- Unacceptable sources include: personal blogs, social media, predatory publishers, most tabloids, and websites where anyone can contribute.
Replace any unreliable sources with high-quality sources. If you cannot find a reliable source for the material, it should be removed.