Double summation for with the outer sigma for gap and the second for series

41 Views Asked by At

Given an array of size $n$. I have the following series $\sum_{k=1}^{n-1} (n-k)$ with $k$ denoting gap of size $1$ to calculate the time complexity of an algorithm of two for loops. I want now to add an outer sum to change $k$ with terms of a sequence of gap values. My sequence is the Knuth sequence $S = \frac{3^k-1}{2}$ with max term isn't larger than $\frac{n}{3}$. In code, it is computed this way: for (h = 1; 3*h +1 <= n-1; h = 3*h + 1); which means $h \leq \frac{n-2}{3}$. So, I want to sum for all $k \in S = \{1, 4, 13, 40, 121, ...,\}$ with basically something like $\sum \sum_{k=1}^{n-1} (n-k) = a \times n^{3/2} + ...$ with the outer sum representing the for loop code I included above. For each iteration, I do $k = h$, and then I get the sum, and finally I get the sum of all. how to do that?

I tired the following, but not sure if that s correct:

$\sum \:_{h=1}^{log_3\:\left(\frac{2}{3}n+1\right)}\sum _{k=0}^n\left(n-\left(\frac{3^h-1}{2}+k\right)\right)$

This $h\:\le \:log_3\:\left(\frac{2}{3}n+1\right)$ comes just from the constraint that $\frac{3^h-1}{2} \leq \frac{n}{3}$