Prove by strong induction on n. (Note that this is the first time students will have seen strong induction, so it is important that this problem be done in an interactive way that shows them how simple induction gets stuck.)
The key insight here is that if n is divisible by 2, then it is easy to get a bit string representation of (n + 1) from that of n. However, if n is not divisible by 2, then (n + 1) will be, and its binary representation will be more easily derived from that of (n + 1)/2. More formally:
• Base Case: n = 1 can be written as 1×2^0.
• Inductive Hypothesis: Assume that the statement is true for all 1 ≤ m ≤ n, where n is arbitrary.
• Inductive Step: Now, we need to consider n + 1. If n + 1 is divisible by 2, then we can apply our inductive hypothesis to (n + 1)/2 and use its representation to express n + 1 in the desired form.
(n+1)/2 = ck ·2k +ck−1 ·2k−1 +···+c1 ·21 +c0 ·20
n+1 = 2·(n+1)/2 = ck ·2k+1 +ck−1 ·2k +···+c1 ·22 +c0 ·21 +0·20.
Otherwise, n must be divisible by 2 and thus have c0 = 0. We can obtain the representation of n + 1 from n as follows:
n = ck ·2k +ck−1 ·2k−1 +···+c1 ·21 +0·20
n+1 = ck ·2k +ck−1 ·2k−1 +···+c1 ·21 +1·20
Therefore, the statement is true.
Cited by UC Berkeley 2019 fall Discussion 02-a solution