Estoy buscando un algoritmo eficiente para el siguiente problema o una prueba de dureza NP.
Sea Σ
Por ejemplo, para A = { { a , b } , { a , c } }
En cuanto a mi motivación, estoy tratando de representar el conjunto de bordes de un autómata finito, donde cada borde puede ser etiquetado por un conjunto de letras del alfabeto de entrada. Me gustaría almacenar una sola cadena y luego mantener un par de punteros a esa cadena en cada borde. Mi objetivo es minimizar la longitud de esa cuerda.
Respuestas:
I believe I found a reduction from Hamiltonian path, thus proving the problem NP-hard.
Call the word w∈Σ∗w∈Σ∗ a witness for AA , if it satisfies the condition from the question (for each L∈AL∈A , there's m≥1m≥1 such that {wm+i∣0≤i<|L|}=L{wm+i∣0≤i<|L|}=L ).
Consider the decision version of the original problem, i.e. decide whether for some AA and k≥0k≥0 , there's a witness for AA of length at most kk . This problem can be solved using the original problem as an oracle in polynomial time (find the shortest witness, then compare its length to kk ).
Now for the core of the reduction. Let G=(V,E)G=(V,E) be a simple, undirected, connected graph. For each v∈Vv∈V , let Lv={v}∪{e∈E∣v∈e}Lv={v}∪{e∈E∣v∈e} be the set containing the vertex vv and all of its adjacent edges. Set Σ=EΣ=E and A={Lv∣v∈V}A={Lv∣v∈V} . Then GG has a Hamiltonian path if and only if there is a witness for AA of length at most 2|E|+12|E|+1 .
Proof. Let v1e1v2…en−1vnv1e1v2…en−1vn be a Hamiltonian path in GG and H={e1,e2,…,en−1}H={e1,e2,…,en−1} the set of all edges on the path. For each vertex vv , define the set Uv=Lv∖HUv=Lv∖H . Choose an arbitrary ordering αvαv for each UvUv . The word w=αv1e1αv2e2…en−1αvnw=αv1e1αv2e2…en−1αvn is a witness for AA , since Lv1Lv1 is represented by the substring α1e1α1e1 , LvnLvn by en−1αnen−1αn , and for each vivi , i∉{1,n}i∉{1,n} , LviLvi is represented by ei−1uvieiei−1uviei . Furthermore, each edge in EE occurs twice in ww with the exception of |V|−1|V|−1 edges in HH , which occur once, and each vertex in VV occurs once, giving |w|=2|E|+1|w|=2|E|+1 .
For the other direction, let ww be an arbitrary witness for AA of length at most 2|E|+12|E|+1 . Clearly, each e∈Ee∈E and v∈Vv∈V occurs in ww at least once. Without loss of generality, assume that each e∈Ee∈E occurs in ww at most twice and each v∈Vv∈V occurs exactly once; otherwise a shorter witness can be found by removing elements from ww .
Let H⊆EH⊆E be the set of all edges occurring in ww exactly once. Given the assumptions above, it holds that |w|=2|E|−|H|+|V||w|=2|E|−|H|+|V| .
Consider a contiguous substring of w of the form ue1e2…ekv, where u,v∈V, ei∈E. We say that u,v are adjacent. Notice that if ei∈H, then ei={u,v}, because ei occurs only once, yet it is adjacent to two vertices in G. Therefore, at most one of ei can be in H. Similarly, no edge in H can occur in w before the first vertex or after the last vertex.
Now, there are |V| vertices, therefore |H|≤|V|−1. From there, it follows that |w|≥2|E|+1. Since we assume |w|≤2|E|+1, we get equality. From there we get |H|=|V|−1. By pigeonhole principle, there is an edge from H between each pair of vertices adjacent in w. Denote h1h2…hn−1 all elements from H in the order they appear in w. It follows that v1h1v2h2…hn−1vn is a Hamiltonian path in G. ◻
Since the problem of deciding the existence of Hamiltonian path is NP-hard and the above reduction is polynomial, the original problem is NP-hard too.
fuente