Segmented Sieve | Sample Video II for Essential Maths for CP | GeeksforGeeks

  Рет қаралды 33,942

GeeksforGeeks

GeeksforGeeks

Күн бұрын

Пікірлер: 42
@shashankpathak63
@shashankpathak63 4 жыл бұрын
One of the best explanation on Segmented sieve .
@GeeksforGeeksVideos
@GeeksforGeeksVideos 4 жыл бұрын
Thank you Shashank !
@johndixit57
@johndixit57 2 жыл бұрын
@@GeeksforGeeksVideos best explanation
@human75788
@human75788 2 жыл бұрын
With that level of explanation I solved it myself within 10 minutes. Seems like it was too easy. Awesome Sir❤
@PriyaSingh-jr6fl
@PriyaSingh-jr6fl 3 жыл бұрын
This is literally the best explanation video of gfg till now.
@cwmayank
@cwmayank 4 жыл бұрын
Simple and perfect video. Thank u, sir. GFG has made my life easy.
@gouravkhator
@gouravkhator 3 жыл бұрын
It's the best explanation I can get for segmented sieve. Thank you so much sir for this video
@sapnilpatel1645
@sapnilpatel1645 2 жыл бұрын
The Best explanation about segmented sieve. Thank you so much sir 🙂.
@sritanuchakraborty4678
@sritanuchakraborty4678 3 жыл бұрын
Great video, few things I've noticed and would like to point it out. Please correct me if I am wrong or the step is redundant: 1. For l=1, h=any number, you need to handle isPrime[l] separately. 2. We are calculating the sieve from 1 to sqrt(h)+1. If a subset of this sieve set has some elements common with the range[l,h], then the prime numbers will also be marked as false. For e.g. l=1 & h=100. n=10. prime={2,3,5,7}. While calculating sm, it will start from 2 and will mark that as false. So a condition such as if(m!=p) is necessary in order to not mark those primes as false. 3. Not really necessary, but another way to compute sm can be sm = ((l+p-1)/p)*p. You don't need the next if statement afterward. 4. A question, say l=2000, h=1e9, the isPrime vector in the segsieve function will be initialized with 99,99,98,000 elements as false. Can someone please point out where is the improvement (both in space & time) for such a huge range over a normal sieve? A naive solution could be to divide up the range into partitions, say it holds 1e7 elements(a bool vector with 1e7 elements is doable), loop over range/1e7 times and each time get the primes with updated low and high for the current range and push them back into a vector. But are there any other optimized solutions?
@dakshkalucha5408
@dakshkalucha5408 2 жыл бұрын
Thanks, point 2 really helped a lot
@anuraggulati2167
@anuraggulati2167 3 жыл бұрын
this video clears all the doubts..thankyou sir🙂🙂😇🥰
@leepakshiyadav1643
@leepakshiyadav1643 3 жыл бұрын
Amazing explaination 👏👏
@sanketkhore9400
@sanketkhore9400 Жыл бұрын
The code is wrong... In segmented we are suppose to find the primes by dividing the range in segments but in your program you are not dividing it in segments. Infact, in segmented_sieve function you are doing the same thing as that of simple sieve(If L=0 and H=100 then also you are making an array of(H-L+1) which is equal to H+1 in this case). So it is not solving the space complexity problem.
@UpendraKumar-mu7mk
@UpendraKumar-mu7mk 4 жыл бұрын
Sir, I have a test case when this code will not give desired result. Whenever l=1, sm=(l/p)*p for a prime p , will be p. So it will mark isprime[p]=false, which it should'nt.
@mralgorithms5127
@mralgorithms5127 3 жыл бұрын
when l=1 1/p = 0 as the least prime number is 2 and this an integer division (0*p)=0 so isprime[0]=false which is true as 0 is not a prime number
@vaibhavjaiswal7811
@vaibhavjaiswal7811 3 жыл бұрын
Yes you are right. I got an error with the code given by sir. I just added if(m!=p) before changing value to false, and it worked. Also you need to ignore 1 in output which is pretty easy ig.
@tanishqmahendrasaini3764
@tanishqmahendrasaini3764 3 жыл бұрын
@@vaibhavjaiswal7811 Thanks I got stuck here.
@PrinceKumar-el7ob
@PrinceKumar-el7ob 3 жыл бұрын
@@vaibhavjaiswal7811 thanks bro !! case of 1 has to handled too!!
@chinmaydeshpande8969
@chinmaydeshpande8969 Жыл бұрын
Best explanation Sir thank you!
@OlliS71
@OlliS71 Жыл бұрын
A segmented sieve is only slightly faster than a non-segemented sieve since you have only one comparison of the found prime against the root of the range. That's one jump in assembly that is almost always predicted correctly.
@codingmaster008
@codingmaster008 3 жыл бұрын
thanks sandeep sir for the awesome explaination👍
@ShivamVerma-rr6nb
@ShivamVerma-rr6nb 2 жыл бұрын
In void sieve function it should be long long j=2*i ; j
@murtuza_shahzad
@murtuza_shahzad 2 жыл бұрын
I was also wondering the same thing.
@anmol3
@anmol3 Жыл бұрын
Both are correct
@1onlyArunzz
@1onlyArunzz 4 ай бұрын
j=i*i better optimisation ;
@shivamkumarsingh667
@shivamkumarsingh667 2 жыл бұрын
Best Explanation 🙌
@HappyHappy-ih5zp
@HappyHappy-ih5zp 3 жыл бұрын
Ek baar mein samjh aa gya Thanks Sir.
@ParthArora-s2i
@ParthArora-s2i 11 ай бұрын
sir in void sieve in the for loop j++ should be replaced by j += i; please correct me @GeeksforGeeksVideos
@MrMadcatsam
@MrMadcatsam 4 жыл бұрын
Is this course the first part/course in Math applied to CP? Can we expect other topics in the next course(s)?
@mahipalsingh-yo4jt
@mahipalsingh-yo4jt 3 жыл бұрын
great explanation!!!
@hastar4329
@hastar4329 3 жыл бұрын
I have enrolled in the dsa course by gfg. I have done the first two sections and sir has only taught about the seive of eratosthenes. Is this topic explained in the course later?
@subhashpatel5861
@subhashpatel5861 2 жыл бұрын
can you please share the course with me :)
@jdgoel4817
@jdgoel4817 4 жыл бұрын
Is that advanced programing I am just a begginer who started with ds algo
@baldcoder_
@baldcoder_ 3 жыл бұрын
I don't see how this would solve the space complexity problem if the "low" is actually zero. We still need to initialize an array from zero to high (which is what we do in normal sieve).
@chadmemes6905
@chadmemes6905 3 жыл бұрын
Not working for h>10^7.
@chitranshjain9714
@chitranshjain9714 Жыл бұрын
for(long long j=i*i ; j
@laraibanwar1618
@laraibanwar1618 3 жыл бұрын
Really nice sir
@nikhil6842
@nikhil6842 4 жыл бұрын
Never saw such an easy explaination for such an advanced topic
@GeeksforGeeksVideos
@GeeksforGeeksVideos 4 жыл бұрын
We glad you liked it, Geek !
@nikhil6842
@nikhil6842 4 жыл бұрын
@@GeeksforGeeksVideos please extend my thanks to Sandeep sir, for revolutionizing education industry and providing a path for us hopeless College students
@dakshkalucha5408
@dakshkalucha5408 2 жыл бұрын
How is space complexity theta(h)??
@bhargavanand7325
@bhargavanand7325 Жыл бұрын
vector prime; void seive(int n) { vector isPrime(n+1,true); for(long long int i=2;i
L6. Sieve of Eratosthenes | Maths Playlist
18:27
take U forward
Рет қаралды 73 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Segmented Sieve
16:08
Techdose
Рет қаралды 4,3 М.
L5 | Segmented Sieve I Raj (Striver) | Prime Numbers for CP
35:45
i^i
12:27
blackpenredpen
Рет қаралды 1,2 МЛН
How to Remember Everything You Read
26:12
Justin Sung
Рет қаралды 3,1 МЛН
The mathematician who cracked Wall Street | Jim Simons
23:08
Oxford University Mathematician REACTS to "Animation vs. Math"
26:19
Tom Rocks Maths
Рет қаралды 2,3 МЛН
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН