I want to analyze the runtime of this algorithm:
int fun (int arr[], int n) {
int result = 1;
int i, j;
if (n == 1)
return 1;
else {
result = fun(arr, 2n/3);
for (i = 1; i <= sqrt(n); i=i*2);
for (j=0; j<sqrt(n)/i; j++)
result += arr[j];
return result;
}
}
I can see that the runtime recurrence should be something like
$\qquad\displaystyle T(n) = T\left(\frac{2n}{3}\right) + \Theta(X)$
where $X$ is the time of the extra operations per recursion.
I can also see that the extra operations are:
$\qquad\begin{align*} \sum_{i=1}^{\log(\sqrt{n})} \sum_{j=0}^{\frac{\sqrt{n}}{i}}1 &= \sum_{i=1}^{\log(\sqrt{n})}\frac{\sqrt{n}}{i} \\ &= \sqrt{n} \cdot \sum_{i=1}^{\log(\sqrt{n})} \frac{1}{i} \\ &= \sqrt{n}\cdot \log(\log(\sqrt{n})) \end{align*}$
So all in all:
$\qquad\begin{align*} T(1) &= 1 \\ T(n) &= T\left(\frac{2n}{3}\right) + \sqrt{n}\cdot \log(\log(\sqrt{n})) \end{align*}$
But I could not continue from here to solve this recursion.