patternModerate
Solving a recurrence relation with √n as parameter
Viewed 0 times
solvingwithrecurrencerelationparameter
Problem
Consider the recurrence
$\qquad\displaystyle T(n) = \sqrt{n} \cdot T\bigl(\sqrt{n}\bigr) + c\,n$
for $n \gt 2$ with some positive constant $c$, and $T(2) = 1$.
I know the Master theorem for solving recurrences, but I'm not sure as to how we could solve this relation using it. How do you approach the square root parameter?
$\qquad\displaystyle T(n) = \sqrt{n} \cdot T\bigl(\sqrt{n}\bigr) + c\,n$
for $n \gt 2$ with some positive constant $c$, and $T(2) = 1$.
I know the Master theorem for solving recurrences, but I'm not sure as to how we could solve this relation using it. How do you approach the square root parameter?
Solution
In your comment you mentioned that you tried substitution but got stuck. Here's a derivation that works. The motivation is that we'd like to get rid of the $\sqrt{n}$ multiplier on the right hand side, leaving us with something that looks like $U(n) = U(\sqrt{n}) + something$. In this case, things work out very nicely:
$$\begin{align}
T(n) &= \sqrt{n}\ T(\sqrt{n}) + n & \text{so, dividing by $n$ we get}\\
\frac{T(n)}{n} &= \frac{T(\sqrt{n})}{\sqrt{n}} + 1 &\text{and letting $n = 2^m$ we have}\\
\frac{T(2^m)}{2^m} &= \frac{T(2^{m/2})}{2^{m/2}} + 1
\end{align}$$
Now let's simplify things even further, by changing to logs (since $\lg \sqrt{n} = (1/2)\lg{n}$). Let
$$\begin{align}
S(m) &= \frac{T(2^m)}{2^m} & \text{so our original recurrence becomes}\\
S(m) &= S(m/2)+1
\end{align}$$
Aha! This is a well-known recurrence with solution
$$
S(m)=\Theta(\lg m)
$$
Returning to $T(\,)$, we then have, with $n=2^m$ (and so $m=\lg n$),
$$
\frac{T(n)}{n} = \Theta(\lg\,\lg n)
$$
So $T(n) =\Theta(n\,\lg\,\lg n)$.
$$\begin{align}
T(n) &= \sqrt{n}\ T(\sqrt{n}) + n & \text{so, dividing by $n$ we get}\\
\frac{T(n)}{n} &= \frac{T(\sqrt{n})}{\sqrt{n}} + 1 &\text{and letting $n = 2^m$ we have}\\
\frac{T(2^m)}{2^m} &= \frac{T(2^{m/2})}{2^{m/2}} + 1
\end{align}$$
Now let's simplify things even further, by changing to logs (since $\lg \sqrt{n} = (1/2)\lg{n}$). Let
$$\begin{align}
S(m) &= \frac{T(2^m)}{2^m} & \text{so our original recurrence becomes}\\
S(m) &= S(m/2)+1
\end{align}$$
Aha! This is a well-known recurrence with solution
$$
S(m)=\Theta(\lg m)
$$
Returning to $T(\,)$, we then have, with $n=2^m$ (and so $m=\lg n$),
$$
\frac{T(n)}{n} = \Theta(\lg\,\lg n)
$$
So $T(n) =\Theta(n\,\lg\,\lg n)$.
Context
StackExchange Computer Science Q#6410, answer score: 16
Revisions (0)
No revisions yet.