![]() ![]() The above series time complexity is less than harmonic series:.i=n(if prime number), the inner loop will be executed → upper bound is 1 times.i=5, the inner loop will be executed → upper bound is (n/5) times.i=3, the inner loop will be executed → upper bound is (n/3) times. ![]() i=2, the inner loop will be executed → upper bound is (n/2) times.The inner loop at each iteration can be expressed by:.If we analyze our sieve for larger numbers then we can see.PREREQUISITE: Time complexity of the Harmonic Series is O(logN), when N is tending to infinity.Space complexity: O(1) Analysis of Time Complexity ![]() Time complexity of Sieve of Eratosthenes: Below is the implementation of the above approach C++ Implementation int checkPrime(int n) Python Implementation of Efficient Approach def SieveOfEratosthenes(n): If it is a prime number, print the number. Iterate from 2 to N, and check for prime. Explanation: All above numbers are prime which are less than or equal to 20. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |