Good morning. This is my first question in a StackExchange forum. Let me know if I'm doing anything incorrectly (posting in the wrong forum, etc.).
Prove that in a bit string, the string 01 occurs at most one more time than the string 10.
I wish to use structural induction for this proof.
Let Σ* be the set of all strings over the alphabet Σ. Let P(w) be the proposition "in the bit string w, the string 01 occurs at most one more time than the string 10".
Basis step: P(λ), where λ is the empty string, is true, because there are 0 strings 01 and 0 strings 10.
Recursive step: Here, I have to show that, if P(w) is true for some arbitrary w belonging to Σ*, then P(wx) is true, where x belongs to Σ. In other words, wx (the bit string w with one more bit x added to it) also has at most one 01 more than 10.
Suppose that P(w) is true. Then, in the bit string w, the string 01 occurs at most one more time than the string 10.
The bit string w can only end in 0 or in 1. When the bit x (which can be 0 or 1) is added, four possibilities occur:
1) w ends in 1 and x ends in 0. In this case, P(wx) is true, because wx has no extra 01's.
2) w ends in 0 and x ends in 0. In this case, P(wx) is also true.
3) w ends in 1 and x ends in 1. In this case, P(wx) is also true.
4) w ends in 0 and x ends in 1.
We have a problem in the last case, because there is one "01" added. By the inductive hypothesis, if w has at most one extra 01, then the proof would fail.
To complete the proof, I have to show that, if w ends in 0, it cannot have more 01's than 10's.
Here is an informal attempt. I will try to build w adding bits to it, and show that, if it ends with 0, for every 01 there will be a 10:
Suppose w is initially one or more 0's. If I add one or more 1's, then there would be one 01. If I add one 0, there will be one 10 to balance with that 01. If I keep adding 0's, the situation won't change. The only way to add one extra 01 would be to add one or more 1's. If I add one or more 0's to the end, one more 10 will be added and the number of 10's and 01's will be equal again.
By the above reasoning, if w ends in 0 and begins in 0, the number of 10's will always equal the number of 01's.
If w begins in one or more 1's, I can add 0 and apply the same reasoning as above, only that there will be one extra 10.
Is this reasoning consistent? How can I show this formally?
Thank you in advance.