Here is the Sieve of Eratosthenes algorithm to find a list of all prime numbers up to a limit N: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
The algorithm makes sense to me. I can understand how and why it works. But I have problem with its time complexity. By wiki:
The bit complexity of the algorithm is O(n (log n) (log log n)) bit operations with a memory requirement of O(n).[15]
However, it contrasts with my intuition that the time complexity of this algorithm should be O(n). I say so because if we see it from the aggregate aspect:
At the beginning, every number in the sequence [2:N] is assumed to be prime. At the end of the algorithm, each element of the sequence will be visited exactly once, to determine whether it is really prime or multiple of another prime number. Each visit takes constant time. So the final T(n) = O(n). But this is not what wiki said. I would like to know what part of my analysis go wrong.