Sieve of eratosthenes

preview_player
Показать описание
The sieve of eratosthenes is one of the most commonly asked mathematical programs for both coding round as well as interviews for placements and internships. While i explained this algorithm, i have showed 2 optimizations with reason and example, which will immensely improve the time complexity of sieve of eratosthenes to NloglogN.This method is used to find all the prime numbers till a given number N. The range to which this sieve algo can find all primes is limited by the memory allocated for the program to run. If you have large memory then you can create large sieve using array and run this algo to find all prime numbers till N. We can also serve range query for prime numbers and return primes in given range of X to Y. CODE LINK is given below. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)

Рекомендации по теме
Комментарии
Автор

This is the only channel that has explained the concept that why to start the inner loop from i^2 & why to stop the outer loop at sqrt(n). 🤩🤩

manasvinsharma
Автор

You could write "i * i <= n" instead of "i <= sqrt(n)" or even put it into it's own variable to save computing sqrt(n) every time in the loop.

brycejohansen
Автор

I must say, you can get solution from anywhere but the thinking to solve a new problem can be easily built by looking at your approaches towards problems. Well explained.

lavishyadav
Автор

This is a very underrated channel this is a very under rated channel

abdulhannan
Автор

Buddy u r awesome, u build very deep understanding and intuition of logic. Thanks for such explanations.

upsolver
Автор

One thing is clear that u are a Genius...🔥👍🏽

vishaldevasi
Автор

The exact video I was looking for. Thanks for the great video.

md_nawshin_zaman
Автор

This is Exactly what a Good Video would look like, no extra animated stuffs only to the point. Because once the concept is clear code part is easy. Btw i would like to add here that i think sieve should me modified for odd numbers only because all the multiples of 2 i.e. 2n are anyways not prime. So Optimized Sieve = Classic Sieve + Till Root n + Odd Numbers Only.

MrMonishSoni
Автор

Tysm Sir the best explanation I ever had till now I immediately subscribed to your channel because I know this will be very very useful for me ..
Once again thank you Sir.

akansha
Автор

Great respect for you & your explanation of algorithms.🙏

ashutoshsinghpatel
Автор

sir i could not understand why we need to take upto sqrt(N) in first loop

madhupadayeswanth
Автор

Thank you so much, it helped on my C++ course

lhrvtsu
Автор

Awesome explanation for the optimization ;)

gabrieldjebbar
Автор

great job sir, well explained, easy, understandable.

surajbaranwal.
Автор

Thanks for this video but can you tell how to do this in O(n) Time complexity

sourav
Автор

that TC explanation by gfg is so complex, they haven't explained properly..

can you please make a video explaining that ?

aizadiqbal
Автор

what will be the time complexity of FIRST METHOD of sieve of eratosthenes

mohitkhandelwal
Автор

The outer for loop is making sqrt(n) iterations. So, why the complexity isn't sqrt(n)LogLogn instead?
Correct me if I am wrong.
And Thanks for such a good explanation :)

ujjwalprazapati
Автор

hey Techdose, what's the name of the software that you are using to explain your code?

melvinkimathi
Автор

Happy to see tricolors in the beginning .💜

swastikpadasalkar