1

So I was looking at the various algorithms of solving Palindrome partitioning problem. Like for a string "banana" minimum no of cuts so that each sub-string is a palindrome is 1 i.e. "b|anana"

Now I tried solving this problem using interval scheduling like:

Input: banana
Transformed string:  # b # a # n # a # n # a #  
P[] = lengths of palindromes considering each character as center of  palindrome.
I[] = intervals

String: # b # a # n # a # n #  a  #
P[i]:   0 1 0 1 0 3 0 5 0 3 0  1  0
I[i]:   0 1 2 3 4 5 6 7 8 9 10 11 12

Example: Palindrome considering 'a' (index 7) as center is 5 "anana"

Now constructing intervals for each character based on P[i]:

b = (0,2)
a = (2,4)
n = (2,8)
a = (2,12)
n = (6,12)
a = (10,12)

So, now if I have to schedule these many intervals on time 0 to 12 such that minimum no of intervals should be scheduled and no time slot remain empty, I would choose (0,2) and (2,12) intervals and hence the answer for the solution would be 1 as I have broken down the given string in two palindromes.

Another test case:

String: # E # A # B # A # E #  A  #  B  # 
P[i]:   0 1 0 1 0 5 0 1 0 5 0  1  0  1  0
I[i]:   0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Plotting on graph: enter image description here

Now, the minimum no of intervals that can be scheduled are either: 1(0,2), 2(2,4), 5(4,14) OR 3(0,10), 6(10,12), 7(12,14)

Hence, we have 3 partitions so the no of cuts would be 2 either

E|A|BAEAB 
EABAE|A|B

These are just examples. I would like to know if this algorithm will work for all cases or there are some cases where it would definitely fail.

Please help me achieve a proof that it will work in every scenario.

Note: Please don't discourage me if this post makes no sense as i have put enough time and effort on this problem, just state a reason or provide some link from where I can move forward with this solution. Thank you.

quintin
  • 812
  • 1
  • 10
  • 35

1 Answers1

2

As long as you can get a partition of the string, your algorith will work.

Recall to mind that a partion P of a set S is a set of non empty subset A1, ..., An:

  • The union of every set A1, ... An gives the set S
  • The intersection between any Ai, Aj (with i != j) is empty

Even if the palindrome partitioning deals with strings (which are a bit different from sets), the properties of a partition are still true. Hence, if you have a partition, you consequently have a set of time intervals without "holes" to schedule. Choosing the partition with the minimum number of subsets, makes you have the minimum number of time intervals and therefore the minimum number of cuts.

Furthermore, you always have at least one palindrome partition of a string: in the worst case, you get a palindrome partition made of single characters.

Ilario Pierbattista
  • 3,175
  • 2
  • 31
  • 41