4
$\begingroup$

Suppose there is a 0-1 string of length n. We can perform the following operation on the string: We can choose two zeros and invert the subsequence between them. The inversion includes the two zeros aswell. For example if the string is 011010, and we choose the first and fourth zeros it becomes 100110. We can also choose just one 0 and turn it into 1. It can be proved that after some iterations the whole string will only consist of 1s.

So my question is: What is the maximum number of iterations we can perform before it becomes the all 1 string.

My approach was to construct a sequence of iterations that seems to be optimal, but I can't prove that it is.

(Obviously the maximum can be achieved if we start from the all 0 string.)

If the lenght of the string is even, so n is an even number. I would choose the middle 2 bits, and change them to 11 in two iterations $(00 \rightarrow 01 \rightarrow 11)$. After that i would reset the middle by choosing the bits next to these two $(0110 \rightarrow 1001$). So I could the first step again, and so on.

If n is an odd number. Then I would do almost the same. I would convert the middle one into zero, then reset it with the two bits next to it. $( 00000 \rightarrow 00100 \rightarrow 01010 \rightarrow 01110 \rightarrow 10001 \rightarrow 10101 \rightarrow 11011 \rightarrow 11111) $

We can calculate that the number of iterations for this algorithm is: \begin{cases} 2^{{\frac{n+1}{2}}}-1, & \text{for odd } n \\ 2^{\frac{n}{2}}+2^{\frac{n}{2}-1}-1, & \text{for even } n \end{cases}

So we can conclude that the maximum number of iterations is greater than this amount. But I think this is the maximum, so this sequence of iterations optimal, but I can't prove it.

Could you please give me some hints on how to prove this, or if it is not true, give me a counterexample.

$\endgroup$
12
  • 1
    $\begingroup$ There might be some misleading in my question. I count one subsequence inversion as one iteration. So if the maximum can be achieved from the string s, and s contains l 1s. Then i can turn the all 0 string to s in l iterations, so I can do maximum+l iterations from the all 0 string. $\endgroup$
    – Joseph
    Commented Apr 14, 2020 at 13:13
  • 1
    $\begingroup$ If I am right, your strategy can be described recursively as: "to set a string of $n$ zeroes, set the $n-2$ middle bits, invert the whole string and set the $n-2$ middle bits. This leads to the recurrence for the counts: $C(n)=2C(n-2)+1$ with $C(1)=1,C(2)=2$. A possible proof method could be to show that if you change one of the extreme bits before the middle bits are all set, then the number of operations will be lower. $\endgroup$
    – user65203
    Commented Apr 14, 2020 at 14:07
  • 1
    $\begingroup$ @YvesDaoust The one contender to this strategy would be the following: Ignore the first letter and the two last letters, flip the remaining word in the longest possible way, then flip the substring from the first to the prelast letter. You end up with a word of length $n-1$ you can still flip, which however already has one 1 set. Just assuming that the resulting 1 would be a 0 makes this strategy better, so these strategies are hard to compare. $\endgroup$
    – Sudix
    Commented Apr 14, 2020 at 14:23
  • 1
    $\begingroup$ @Sudix: I wouldn't be surprised that there is a straightforward solution that we don't see. Can you beat $11$ for $000000$ ? $\endgroup$
    – user65203
    Commented Apr 14, 2020 at 15:00
  • 2
    $\begingroup$ @Sudix: the transition from row $9$ to $10$ is not correct. An extreme $1$ cannot return to $0$. We count the transitions. $\endgroup$
    – user65203
    Commented Apr 14, 2020 at 15:14

1 Answer 1

1
$\begingroup$

Let $n$ be the length of the word. For even $n$, a working idea is to build a metric for the word so that every transition increases the metric, and so that the strategy you proposed increases the metric in every step exactly by $1$.

$\endgroup$
1
  • $\begingroup$ Well done! I was able to prove it for even n with this idea. I'm pretty sure the same works for odd ns aswell. $\endgroup$
    – Joseph
    Commented Apr 14, 2020 at 22:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .