I have to tell the complexity of the both following algorithm :
for ( i=1; i < n; i *= 2 ) {
for ( j = n; j > 0; j /= 2 ) {
for ( k = j; k < n; k += 2 ) {
sum += (i + j * k );
}
}
}
for( int i = n; i > 0; i-- ) {
for( int j = 1; j < n; j *= 2 ) {
for( int k = 0; k < j; k++ ) {
... // some operation
}
}
}
In the first example, I know the complexity of the outer and middle loops are log(n), but I don't know how to compute the complexity for the inner one as the initialization of k change at iteration
For the second one, apparently the complexity is n^2 but I really don't understand why