Given a recursive program with the following recurrence relation:
\[\begin{array}{l}
{C_n} = 3{C_{\frac{n}{3}}} + 1,n > 1\\
{C_1} = 1
\end{array}\]
Solve the recurrence relation to find the complexity of the program
I have a solution by placing sub-hidden as follows:
\[\begin{array}{l}
{C_n} = 3{C_{\frac{n}{3}}} + 1\\
\Rightarrow {C_{{3^k}}} = 3{C_{{3^{k - 1}}}} + 1\\
\Leftrightarrow {C_{{3^k}}} = 3\left( {3{C_{{3^{k - 2}}}} + 1} \right) + 1 = {3^2}{C_{{3^{k - 2}}}} + 3 + 1\\
\Leftrightarrow {C_{{3^k}}} = {3^2}\left( {3{C_{{3^{k - 3}}}} + 1} \right) + 3 + 1 = {3^3}{C_{{3^{k - 3}}}} + {3^2} + 3 + 1\\
\Leftrightarrow {C_{{3^k}}} = ...\\
\Leftrightarrow {C_{{3^k}}} = {3^k}{C_1} + {3^{k - 1}} + ... + {3^2} + 3 + 1 = {3^k} + {3^k} - 1 = {3^{k + 1}} - 1\\
{C_n} = 3n - 1
\end{array}\]
Complexity of the program: \[{\rm O}(n)\]
I want to ask everyone if there is any other solution method that directly uses integer values of n without sub-implicit, a general solution
\[\begin{array}{l}
{C_n} = 3{C_{\frac{n}{3}}} + 1,n > 1\\
{C_1} = 1
\end{array}\]
Solve the recurrence relation to find the complexity of the program
I have a solution by placing sub-hidden as follows:
\[\begin{array}{l}
{C_n} = 3{C_{\frac{n}{3}}} + 1\\
\Rightarrow {C_{{3^k}}} = 3{C_{{3^{k - 1}}}} + 1\\
\Leftrightarrow {C_{{3^k}}} = 3\left( {3{C_{{3^{k - 2}}}} + 1} \right) + 1 = {3^2}{C_{{3^{k - 2}}}} + 3 + 1\\
\Leftrightarrow {C_{{3^k}}} = {3^2}\left( {3{C_{{3^{k - 3}}}} + 1} \right) + 3 + 1 = {3^3}{C_{{3^{k - 3}}}} + {3^2} + 3 + 1\\
\Leftrightarrow {C_{{3^k}}} = ...\\
\Leftrightarrow {C_{{3^k}}} = {3^k}{C_1} + {3^{k - 1}} + ... + {3^2} + 3 + 1 = {3^k} + {3^k} - 1 = {3^{k + 1}} - 1\\
{C_n} = 3n - 1
\end{array}\]
Complexity of the program: \[{\rm O}(n)\]
I want to ask everyone if there is any other solution method that directly uses integer values of n without sub-implicit, a general solution