Time Complexity of a loop is considered as O(Logn) if the loop variables is divided / multiplied by a constant amount.
loop 1 ----
for (int i = 1; i <=n; i *= c)
{
// some O(1) expressions
}
loop 2 -----
for (int i = n; i > 0; i /= c)
{
// some O(1) expressions
}
Time Complexity of a loop is considered as O(LogLogn) if the loop variables is reduced / increased exponentially by a constant amount.
Here c is a constant greater than 1
loop 3 ----
for (int i = 2; i <=n; i = pow(i, c))
{
// some O(1) expressions
}
loop 4 -----
////Here fun is sqrt or cuberoot or any other constant root
for (int i = n; i > 0; i = fun(i))
{
// some O(1) expressions
}
Can anyone explain me why it is by considering the number of times the inner loop executes in these loops?
If c=1 in loop 1 and loop 2 then it will run infinite times right but it is given as logarithimic time why?
how is it O(loglogN) in loop 3 and loop 4?