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

  Рет қаралды 29,364

GeeksforGeeks

GeeksforGeeks

3 жыл бұрын

GeeksforGeeks presents you the Sample Video II for Essential Mathematics for CP.
Link for the course mentioned above - practice.geeksforgeeks.org/co...
Our courses : practice.geeksforgeeks.org/co...
Please Like, Comment and Share the Video among your friends.
Install our Android App:
play.google.com/store/apps/de...
If you wish, translate into the local language and help us reach millions of other geeks:
kzbin.info_cs_p...
Follow us on Facebook:
/ gfgvideos
And Twitter:
/ gfgvideos
Also, Subscribe if you haven't already! :)

Пікірлер: 41
@shashankpathak63
@shashankpathak63 3 жыл бұрын
One of the best explanation on Segmented sieve .
@GeeksforGeeksVideos
@GeeksforGeeksVideos 3 жыл бұрын
Thank you Shashank !
@johndixit57
@johndixit57 Жыл бұрын
@@GeeksforGeeksVideos best explanation
@human75788
@human75788 Жыл бұрын
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 3 жыл бұрын
Simple and perfect video. Thank u, sir. GFG has made my life easy.
@gouravkhator
@gouravkhator 2 жыл бұрын
It's the best explanation I can get for segmented sieve. Thank you so much sir for this video
@sapnilpatel1645
@sapnilpatel1645 Жыл бұрын
The Best explanation about segmented sieve. Thank you so much sir 🙂.
@leepakshiyadav1643
@leepakshiyadav1643 2 жыл бұрын
Amazing explaination 👏👏
@anuraggulati2167
@anuraggulati2167 2 жыл бұрын
this video clears all the doubts..thankyou sir🙂🙂😇🥰
@mahipalsingh-yo4jt
@mahipalsingh-yo4jt 3 жыл бұрын
great explanation!!!
@chinmaydeshpande8969
@chinmaydeshpande8969 Жыл бұрын
Best explanation Sir thank you!
@codingmaster008
@codingmaster008 2 жыл бұрын
thanks sandeep sir for the awesome explaination👍
@shivamkumarsingh667
@shivamkumarsingh667 2 жыл бұрын
Best Explanation 🙌
@HappyHappy-ih5zp
@HappyHappy-ih5zp 2 жыл бұрын
Ek baar mein samjh aa gya Thanks Sir.
@OlliS71
@OlliS71 8 ай бұрын
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.
@laraibanwar1618
@laraibanwar1618 3 жыл бұрын
Really nice sir
@sritanuchakraborty4678
@sritanuchakraborty4678 2 жыл бұрын
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 Жыл бұрын
Thanks, point 2 really helped a lot
@jdgoel4817
@jdgoel4817 3 жыл бұрын
Is that advanced programing I am just a begginer who started with ds algo
@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.
@MrMadcatsam
@MrMadcatsam 3 жыл бұрын
Is this course the first part/course in Math applied to CP? Can we expect other topics in the next course(s)?
@baldcoder_
@baldcoder_ 2 жыл бұрын
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).
@UpendraKumar-mu7mk
@UpendraKumar-mu7mk 3 жыл бұрын
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!!
@ShivamVerma-rr6nb
@ShivamVerma-rr6nb Жыл бұрын
In void sieve function it should be long long j=2*i ; j
@murtuza_shahzad
@murtuza_shahzad Жыл бұрын
I was also wondering the same thing.
@anmol3
@anmol3 Жыл бұрын
Both are correct
@chitranshjain9714
@chitranshjain9714 7 ай бұрын
for(long long j=i*i ; j
@user-wg6fs5vg3c
@user-wg6fs5vg3c 5 ай бұрын
sir in void sieve in the for loop j++ should be replaced by j += i; please correct me @GeeksforGeeksVideos
@chadmemes6905
@chadmemes6905 3 жыл бұрын
Not working for h>10^7.
@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 Жыл бұрын
can you please share the course with me :)
@dakshkalucha5408
@dakshkalucha5408 Жыл бұрын
How is space complexity theta(h)??
@nikhil6842
@nikhil6842 3 жыл бұрын
Never saw such an easy explaination for such an advanced topic
@GeeksforGeeksVideos
@GeeksforGeeksVideos 3 жыл бұрын
We glad you liked it, Geek !
@nikhil6842
@nikhil6842 3 жыл бұрын
@@GeeksforGeeksVideos please extend my thanks to Sandeep sir, for revolutionizing education industry and providing a path for us hopeless College students
@bhargavanand7325
@bhargavanand7325 Жыл бұрын
vector prime; void seive(int n) { vector isPrime(n+1,true); for(long long int i=2;i
L5 | Segmented Sieve I Raj (Striver) | Prime Numbers for CP
35:45
Советы на всё лето 4 @postworkllc
00:23
История одного вокалиста
Рет қаралды 4,5 МЛН
A little girl was shy at her first ballet lesson #shorts
00:35
Fabiosa Animated
Рет қаралды 17 МЛН
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 26 МЛН
A Beautiful Algorithm for the Primes
9:13
Aaron Learns
Рет қаралды 100 М.
L6. Sieve of Eratosthenes | Maths Playlist
18:27
take U forward
Рет қаралды 32 М.
An Exact Formula for the Primes: Willans' Formula
14:47
Eric Rowland
Рет қаралды 1,3 МЛН
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
What's Your ENGLISH LEVEL? Take This Test!
21:31
Brian Wiles
Рет қаралды 1,7 МЛН
Советы на всё лето 4 @postworkllc
00:23
История одного вокалиста
Рет қаралды 4,5 МЛН