The problem is the number of iterations performed by the while loop for the given i .
At each iteration j:= j^4 and at the beginning j := 2 , therefore, after x iterations j = 2 4^x
j < i equivalent to x < log_4(log_2(i))
I would risk asserting that the complexity is O(n * log_4(log_2(n)))
You can get rid of the constant factors in the Big O notation. log_4(x) = log(x) / log(4) and log(4) is a constant. Similarly, you can change log_2(x) to log(x) . Difficulty can be expressed as O(n*log(log(n)))
source share