I'm researching recursive functions. I see that there is a method to solve them known as substution method. It is used like $n = 2^m$ or $n= 2^k$
For example, in this question,
$$T(n) = n^2 + \frac{n}{2} - 1 + T\left(\frac{n}{2}\right)$$
I tried to substitute $n=2^m$, which yields the following recurrence:
$$S(m) := T(2^m)$$ $$S(0) = 1$$ $$S(m) = 4^m + 2^{m-1} - 1 + S(m-1)$$
How does it become $S(m-1)$? I would say $S(2^{k}*2^{-1})$. I don't understand it.
In the same way, in other question as well,
Use substitution
$$S(n) = T(2^n) =2T\left(\frac{2^n}2\right)+2^n = 2T(2^{n-1})+2^n = 2S(n-1)+2^n $$
I don't understand how it becomes $S(n-1)$.
Could you please explain it?
$$ T\left(2^{\log_2 n}\right) = T\left(2^{\log_2 n-1}\right)+n\left(n+\frac 12\right)-1 $$
now calling $\log_2 n = z$ we have
$$ T\left(2^z\right) = T\left(2^{z-1}\right)+2^z\left(2^z+\frac 12\right)-1 $$
so the recurrence can be recast as
$$ S(z)=S(z-1)+2^z\left(2^z+\frac 12\right)-1 $$
with solution
$$ S(z) = \frac{1}{3} \left(3\cdot 2^z+2^{2 z+2}-3 z-7\right)+c_0 $$
and finally we return to $T(n)$ backwards with $z = \log_2 n$ obtaining
$$ T(n) = \frac 13\left(4n^2+3n-7\right)-\log_2 n+c_0 $$
NOTE
After substitution, $S(z) = S\left(\log_2 n\right) = T\left(2^{\log_2 n}\right) = T(n)$.
Equivalently, considering now
$$ T(n) = T\left(\frac na\right)+f(n),\ \ \ a > 0 $$
taking the subset $n = a^m$ and submitting the recurrence to this subset we have
$$ T\left(a^m\right) = T\left(a^{m-1}\right)+f\left(a^m\right) $$
considering now $S(\cdot) = T\left(a^{(\cdot)}\right)$ for clearer writing, we follow with
$$ S(m) = S(m-1) + f(a^m) $$
with solution
$$ S(m) = \sum_{k=0}^m f(a^k) $$
and returning to the original formulation
$$ S(m)=T\left(a^m\right)=T(n) = \sum_{k=0}^{\log_a n} f(a^k) $$
Note that the recurrence $S(m)$ operates in a subset of $T(n)$ but at those points they have the same value.