What is a good example of prefix induction? the Wikipedia article for Mathematical induction introduces a few variations of the classic principle, such as the strong induction. The strong induction comes with a few examples, namely the closed form of the Fibonacci sequence and the factorization of integers into prime numbers. For these two examples, a classic induction would be more complicated or unnatural, necessitating to rewrite the property $P(n)$ we are considering.
The article also presents the prefix induction which can be written as:

Let $P(n)$ be a property depending on an integer $n\geqslant 0$. If

*

*$P(0)$ is true and


*if $P(k)$ is true for some $k\geqslant 0$, then $P(2k)$ and $P(2k+1)$ are also true,
then $P(n)$ is true for any $n\geqslant 0$.

It is clear to me that the prefix induction works but the article does not give any situation where this form of induction would be useful, more useful and more natural than the classic form of induction.
What is a good example of use of prefix induction?
 A: Based on the form of prefix induction, it indicates to me that a good place to use it would likely be where $P(2k)$ and $P(2k+1)$ depend directly on $P(k)$, and with the binary format of $n$ possibly also being involved in some way to help ensure there is a closed form solution available to prove. Using these ideas, I tried several things to come up with the following which I believe is a fairly good example of a use for prefix induction.
Define the function $P$ to be $P(0) = 1$ and for $n \in \mathbb{N}^0$
$$P(n) = 
\begin{cases}
P\left(\frac{n}{2}\right), & \text{if $n$ is even} \\
2P\left(\frac{n-1}{2}\right), & \text{if $n$ is odd}
\end{cases}
\tag{1}\label{eq1}$$
The binary expansion of each $n$ is given by $n = \sum_{i=0}^j a_i2^i$ where $j = 1$ for $n = 0$ and $j = \left\lfloor \log_2{n} \right\rfloor + 1$ for $n \gt 0$, with $a_i \in \{0,1\}$. Prove that for all $n \in \mathbb{N}^0$
$$P(n) = 2^m \text{ where } m = \sum_{i=0}^j a_i \tag{2}\label{eq2}$$
For $k = 0$, $a_0 = 0$ so $m = 0$ giving $P(0) = 1 = 2^0$, so your step $1$ is confirmed. Next, with step $2$, consider $P(k)$ is true for some $k \ge 0$. The first part of \eqref{eq1} gives $P(2k) = P(k)$. If $k$ has $m$ binary digits of $1$, note the binary representation of $2k$ has the same digits as $k$ with the indices shifted up by $1$ and $a_0 = 0$. Thus, the sum of the binary digits is still the same, i.e., $m$, and, thus, $P(2k) = P(k) = 2^m$ showing that \eqref{eq2} holds. The second part of \eqref{eq1} gives that $P(2k + 1) = 2P(k)$. With $2k + 1$, all of the binary digits of $k$ are shifted up by $1$ and $a_0 = 1$, so if $k$ has a sum of binary digits of $m$, then $2k + 1$ has a sum of binary digits of $m + 1$. Thus, $P(2k + 1) = 2P(k) = 2(2^m) = 2^{m + 1}$, showing that \eqref{eq2} still holds. In summary, this shows that step $2$ is also true.
Since both steps $1$ and $2$ are proven, by prefix induction, then \eqref{eq2} holds for all $n \ge 0$.
Update: This problem can be made somewhat more general by having $P(0) = b$ and $P(n) = cP\left(\frac{n-1}{2}\right)$ for $n$ being odd in the second part of \eqref{eq1}. This will then give that $P(n) = bc^m$ in \eqref{eq2}. In the problem above, $b = 1$ and $c = 2$. I considered using this more general case above instead but thought that using simple, specific values will help to focus on the prefix induction procedure.
A: Suppose you want to prove that merge sort is $O(n\log n)$; that is, that the merge sort algorithm sorts a list of $n$ distinct natural numbers in $O(n \log n)$ steps.
Prefix induction allows you to prove this pretty easily.
The base case is trivial. For the induction step, fix $k \in \mathbb{N}$ and assume that merge sort sorts a list of $k$ distinct natural numbers in $O(k \log k)$ steps. Then


*

*Given a list of length $2k$, the algorithm first splits it into two lists of length $k$ (1 step), sorts each list ($O(k\log k)$ steps each by the induction hypothesis) and then merges the two lists together $O(2k)=O(k)$ steps). So the algorithm terminates in
$$1+2 \cdot O(k\log k) + O(k) = O(k \log k) = \boxed{ O((2k) \log (2k)) }$$
steps.

*Likewise for a list of length $2k+1$, except the $(2k+1)^{\text{st}}$ number is handled separately (e.g. merge it in at the end, which certainly doesn't increase the complexity).
So by prefix induction, the number of steps is $O(n\log n)$.
