Is it NP complete to determine if a given set of strings can be arranged to form a palindrome?

Example: The strings {"German" "man" "am" "am" "I" "I" "regal" "a"} can be arranged into "I man am regal a German am I". The strings {"bat" "bat"} cannot be arranged into a palindrome, because we are not allowed to change the order of characters within strings. ("Bat tab" is not allowed.)

This reminds me of the problem of determining if a set of jigsaw puzzle pieces can all fit together, which is NP complete.

If anyone could shed some light on this problem, I would be grateful. Thank you.

  • 11,937
  • 4
  • 27
  • 78

2 Answers2


It turns out yes, this is NP-complete. The proof is a lot more boring than I would have hoped for.

Setup of proof: We show that the problem is in NP and NP-hard.

The problem is clearly in NP. A palindrome can easily be verified in polynomial time by checking the last character against the first, the second to last against the second, and so on. If one does not want to consider spaces of capitalization, spaces can be removed easily, and capital letters can easily be made lowercase.

Now we show that the problem is NP-hard with a reduction from 3-partition.

Suppose that m and n are integers, and n is divisible by 3. Suppose that l1, l2, l3, ... , ln are integers where $\frac{m}{4}$ < li < $\frac{m}{2}$ $\forall i$. Then determining if l1, l2, l3, ... , ln can be arranged into triplets li, lj, lk such that li + lj + lk = m is NP-complete. We show that for every instance of this problem, there exists an instance of the previously described palindrome problem such that a "yes" for 3-SAT means a "yes" for the palindrome problem, and a "no" for 3-SAT means a "no" for the palindrome problem.

To make such an instance, we name one string S and let it equal "aaa ... aaa,aaa ... aaa, ... ,aaa ... aaa", which is a string that consists of m a's, followed by a comma, followed by m a's, followed by a comma, and continuing this pattern until it ends with m a's. This string contains n - 1 commas. In other words, the string is n groups of m-long strings of a's, separated by commas.

Example: m = 6, n = 4
S = "aaaaaa,aaaaaa,aaaaaa,aaaaaa"

This is 4 groups of 6-long strings of a's, separated by commas.

Then we define strings si, 1 $\leq$ i $\leq$ n, to contain a number of a's equal to the value of li.
We then define strings bi = "," 1 $\leq$ i $\leq$ n - 1.

So to arrange strings S, si, and bi ($\forall$i on which these strings are defined) into a palindrome, we have to place the long string S on one side, and try to form triplets from the strings si so that each triplet has exactly m a's in it. Then we just put a comma between each triplet. So this specific type of the palindrome problem is exactly the same as a 3-SAT problem.

An actual proof would need more writing, but (I hope) I've made the main idea clear.

  • 2
    You've got the right idea except for a couple of points. The problem you are reducing from is not 3-SAT as you stated. The problem you are using is not NP-Complete. Given a set of n integers, there are only $\binom{n}{3}$ possible triplets. So, a brute force algorithm can solve this in polytime. If you apply your idea and reduce from the Partition problem, it should work. – user137481 Sep 01 '15 at 21:09
  • The problem I'm reducing from is 3-partition, which is NP complete as far as I know. I fixed that in my answer. The problem is not to find a single triplet that works, but to organize all of the strings in to triplets that have the correct total length. –  Jan 22 '17 at 05:04

Yes, there is a paper Diverse Palindromic Factorization is NP-Complete that describes it.

Briefly, the author builds a polynomial Boolean Circuit and given a sequence of strings with a specific criteria (check P.3), he adds a (Wire) (check P.3) to derive a String which form diverse palindromes.