I wanted to first preface that I'm a python-newbie and that I'm gracious for anyone who can explain it to my clearly and completely.
I was looking at the code found in the link below:
http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Python
I've just begun to understand iterators, generators and the yield command but I don't understand how the code works for the set implementation.
def eratosthenes2(n):
multiples = set()
for i in range(2, n+1):
if i not in multiples:
yield i
multiples.update(range(i*i, n+1, i))
I'm having difficulty understanding what the last line in this function does.
Additionally, can someone explain to me why this implementation is O(log(n)) time?