No video

Sieve of eratosthenes

  Рет қаралды 56,263

Techdose

Techdose

Күн бұрын

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 :)
CODE LINK: gist.github.com/SuryaPratapK/...
TIME COMPLEXITY PROOF: www.geeksforgeeks.org/how-is-...

Пікірлер: 96
@manasvinsharma1740
@manasvinsharma1740 3 жыл бұрын
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). 🤩🤩
@techdose4u
@techdose4u 3 жыл бұрын
🔥
@anshumaan1024
@anshumaan1024 Жыл бұрын
bhai mene gfg ki video dekhi..dimaag crash kr gya tha
@md_nawshin_zaman
@md_nawshin_zaman Жыл бұрын
The exact video I was looking for. Thanks for the great video.
@ashutoshsinghpatel196
@ashutoshsinghpatel196 Жыл бұрын
Great respect for you & your explanation of algorithms.🙏
@brycejohansen7114
@brycejohansen7114 3 жыл бұрын
You could write "i * i
@pragyan394
@pragyan394 2 жыл бұрын
The compiler would optimise that by itself
@lavishyadav6756
@lavishyadav6756 4 жыл бұрын
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.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@abdulhannan288
@abdulhannan288 2 жыл бұрын
This is a very underrated channel this is a very under rated channel
@vishaldevasi3500
@vishaldevasi3500 2 жыл бұрын
One thing is clear that u are a Genius...🔥👍🏽
@upsolver2342
@upsolver2342 2 жыл бұрын
Buddy u r awesome, u build very deep understanding and intuition of logic. Thanks for such explanations.
@techdose4u
@techdose4u 2 жыл бұрын
Welcome 😀
@user-lh7rv1ts3u
@user-lh7rv1ts3u 2 жыл бұрын
Thank you so much, it helped on my C++ course
@mdzaid3792
@mdzaid3792 3 жыл бұрын
The explanation is literally Supercalifragilisticexpialidocious 🔥🔥🔥
@techdose4u
@techdose4u 3 жыл бұрын
What's this word bro 😅
@surajbaranwal56.
@surajbaranwal56. 2 жыл бұрын
great job sir, well explained, easy, understandable.
@anuragsoni2256
@anuragsoni2256 3 жыл бұрын
Very nice problem. Thanks!
@gabrieldjebbar7098
@gabrieldjebbar7098 3 жыл бұрын
Awesome explanation for the optimization ;)
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@Justdoing185
@Justdoing185 2 жыл бұрын
Excellent explanation sir
@mounikanandimalla9321
@mounikanandimalla9321 3 жыл бұрын
That was a super explanation:)
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@akansha1127
@akansha1127 3 жыл бұрын
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.
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@DEEPAKSAHU-ou4jy
@DEEPAKSAHU-ou4jy 2 жыл бұрын
ek no guruji
@sourav9135
@sourav9135 3 жыл бұрын
Thanks for this video but can you tell how to do this in O(n) Time complexity
@MrMonishSoni
@MrMonishSoni 3 жыл бұрын
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.
@techdose4u
@techdose4u 3 жыл бұрын
Right. The numbers are already marked and so will not be processed again. I think you are suggesting to jump in values of 2 rather than 1 right ? It's a good idea to not even have to check it :)
@MrMonishSoni
@MrMonishSoni 3 жыл бұрын
@@techdose4u Ya I mean i have read it somewhere on wiki page i think because it effects on the time/space complexity. Although there are much complex sieves which are still more optmized, and i didnt get that, but as far as this video goes. this is perfect. Thanks.
@MrMonishSoni
@MrMonishSoni 3 жыл бұрын
@@techdose4u Also Prime Numbers are utterly the most important concept like i have came after going through some project Eulers problem and what i had observed is that it take huge understanding of just basic maths like prime numbers to just implement an efficient algorithm. Because the Numbers on project Eulers goes upto millions for primes just to make sure you dont write an inefficient code. ;) :)
@techdose4u
@techdose4u 3 жыл бұрын
I will cover that when I start Number theory playlist :) Concepts of primes and complex sieves.
@shivrajahirwar4334
@shivrajahirwar4334 3 жыл бұрын
very nice explanation:)
@mohitkhandelwal5050
@mohitkhandelwal5050 3 жыл бұрын
what will be the time complexity of FIRST METHOD of sieve of eratosthenes ??????
@techamet428
@techamet428 3 жыл бұрын
beautifully explained
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@tanmaytyagi7031
@tanmaytyagi7031 3 жыл бұрын
Very nicely explained ❤️
@techdose4u
@techdose4u 3 жыл бұрын
Thanks 😊
@karankanojiya7672
@karankanojiya7672 2 жыл бұрын
TYSM SIR! Respect ++ !
@madhupadayeswanth1865
@madhupadayeswanth1865 Жыл бұрын
sir i could not understand why we need to take upto sqrt(N) in first loop
@Amaim123
@Amaim123 3 жыл бұрын
Well explained
@melvinkimathi8924
@melvinkimathi8924 2 жыл бұрын
hey Techdose, what's the name of the software that you are using to explain your code?
@jigyasakodnani3872
@jigyasakodnani3872 3 жыл бұрын
Thanks for this video, you're explanation is amazing 😃
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@AinasDiaries
@AinasDiaries 3 жыл бұрын
At 3:52 why take j
@ruthvikmankari1340
@ruthvikmankari1340 3 жыл бұрын
Thank You
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@vijaykumarlokhande1607
@vijaykumarlokhande1607 3 жыл бұрын
where is segmented sieve with O(n) complexity?
@herculean6748
@herculean6748 Жыл бұрын
Thanks
@techdose4u
@techdose4u Жыл бұрын
Welcome :)
@sahilgore7645
@sahilgore7645 2 жыл бұрын
how to prove that the factor
@swastikpadasalkar5765
@swastikpadasalkar5765 4 жыл бұрын
Happy to see tricolors in the beginning .💜
@techdose4u
@techdose4u 4 жыл бұрын
😅
@sivaganesh4489
@sivaganesh4489 4 жыл бұрын
Awesome please do more videos on these type of questions
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@ujjwalprazapati8480
@ujjwalprazapati8480 3 жыл бұрын
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 :)
@ganeshkamath89
@ganeshkamath89 2 жыл бұрын
I think that is because each identified number goes and marks all other multiples, thus iterating till end.
@mandeep2192
@mandeep2192 4 жыл бұрын
explained beautifully...
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@harsimrankaur653
@harsimrankaur653 4 жыл бұрын
Great explanation!
@neghatnazir1668
@neghatnazir1668 4 жыл бұрын
thanks for this video its helpful
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@aryaman_godara
@aryaman_godara Жыл бұрын
your color scheme was already aligned for "Independence day : azadi ka amrit mahotsav" 😂😂 kool video though
@chiranjeevichiru8327
@chiranjeevichiru8327 2 жыл бұрын
J=j+i; how it increment
@harshpatel1385
@harshpatel1385 4 жыл бұрын
god bless you
@techdose4u
@techdose4u 4 жыл бұрын
:)
@ALEEMKHAWAR1
@ALEEMKHAWAR1 2 жыл бұрын
here I know only why to start inner loop from i^2 & outer loop upto SQRT N
@divyanshusalve8173
@divyanshusalve8173 4 жыл бұрын
Nice video, although I came to see geeksforgeeks version of optimized version sieve of eratosthenes, I got a hint from this video about gfg's solution. A like for that also..
@techdose4u
@techdose4u 4 жыл бұрын
Nice
@harshpatel1385
@harshpatel1385 4 жыл бұрын
plz make playlist on dynamic,tree,graph
@techdose4u
@techdose4u 4 жыл бұрын
Doing so
@Cybernetic1
@Cybernetic1 4 жыл бұрын
You are the best 💝💌
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@vickycsk1998
@vickycsk1998 7 ай бұрын
it is not applicable for 10^12
@MohamedMahmoud-dn5pm
@MohamedMahmoud-dn5pm 4 жыл бұрын
good way.....thanks
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@sarthakgupta1263
@sarthakgupta1263 4 жыл бұрын
amazing exlpanations
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@sambhumahato8320
@sambhumahato8320 4 жыл бұрын
Awesome❤️
@techdose4u
@techdose4u 4 жыл бұрын
:)
@khageswarmalakar2011
@khageswarmalakar2011 3 жыл бұрын
Thank you
@techdose4u
@techdose4u 3 жыл бұрын
Welcome
@utubecom9185
@utubecom9185 4 жыл бұрын
Sir, i have a doubt and i have put that doubt on candy distribution problem video . Sir i am waiting for the reply .......
@techdose4u
@techdose4u 4 жыл бұрын
Okay let me check.
@shashib16
@shashib16 4 жыл бұрын
what if, N=40 and 35 is not divisible by 2 & 3.
@techdose4u
@techdose4u 4 жыл бұрын
Then you will mark mutiples of next prime number which is 5.
@happypuppy3281
@happypuppy3281 4 жыл бұрын
Please Make a video on sieve of atkins.
@techdose4u
@techdose4u 4 жыл бұрын
Yea sure
@supernova7870
@supernova7870 4 жыл бұрын
First viewer
@techdose4u
@techdose4u 4 жыл бұрын
:)
@harshpatel1385
@harshpatel1385 4 жыл бұрын
can you make video of solution of leetcode
@techdose4u
@techdose4u 4 жыл бұрын
I will do it whenever I get time.
@shaswatdas6553
@shaswatdas6553 3 жыл бұрын
Python code incoming.. from math import sqrt def sieve(n): if n < 2: return [] ar = [True for i in range(n+1)] p = [] for i in range(2, int(sqrt(n))+1): if ar[i] is False: continue for j in range(i**2, n+1, i): ar[j] = False p=[i for i in range(n) if i>=2 and ar[i]] return p n = 19 print(sieve(n))
@techdose4u
@techdose4u 3 жыл бұрын
👍
@mdfahadkhan518
@mdfahadkhan518 2 жыл бұрын
No ,, your logic is wrong. We can continue the loop till Square Root of number
Permutation Sequence | Leetcode #60
18:17
Techdose
Рет қаралды 55 М.
A little girl was shy at her first ballet lesson #shorts
00:35
Fabiosa Animated
Рет қаралды 17 МЛН
Sieve of Eratosthenes - Find All Prime Numbers up to N
7:41
Profound Academy
Рет қаралды 516
The Selberg sieve (Lecture 1) by Stephan Baier
1:12:21
International Centre for Theoretical Sciences
Рет қаралды 2,2 М.
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 784 М.
BREAKING Chess Drama As Niemann Rips Into Magnus Carlsen
8:25
Epic Chess
Рет қаралды 52 М.
SHA: Secure Hashing Algorithm - Computerphile
10:21
Computerphile
Рет қаралды 1,2 МЛН
Magnus Carlsen, Hans Niemann Drama Just Got Much Worse
31:16
GothamChess
Рет қаралды 243 М.