Finding Prime numbers - Sieve of Eratosthenes

Поділитися
Вставка
  • Опубліковано 10 січ 2025

КОМЕНТАРІ •

  • @dhariri
    @dhariri 9 років тому +111

    Best video I've found about the Sieve of Eratosthenes so far! Great work!

    • @dhariri
      @dhariri 9 років тому +4

      +David Hariri Do you have a video that compares the complexities of all major prime factorization algorithms (including brute division)?

    • @sriram8027
      @sriram8027 4 роки тому

      @@dhariri ua-cam.com/video/7CyBf-xZF4c/v-deo.html

    • @aqua6150
      @aqua6150 4 роки тому +7

      @@sriram8027 I guess he might have figured that out within this 4 years.

    • @venki2432
      @venki2432 2 роки тому +1

      Hey just reminding u it's been 6 year's 😂

    • @gaganbedi4332
      @gaganbedi4332 2 роки тому

      8:40 for i=2, we are striking off 6 elements. Here n=15, and n/2 !=6. can you please explain how n/2 n/3 ... ?

  • @sr5726
    @sr5726 9 років тому +34

    We can further optimize by reducing the number of unwanted strikes.
    If i and j are co-factors of number n i.e j x i = n , then there is no need to strike off multiples of i which are < i*i (square of i ) where j < i
    In other words the for loop for j can start at i ( when i=3 , j can start at 3 instead of 2 , because the multiples of i < (i*i) i.e for multiples of i

    • @aor6956
      @aor6956 4 роки тому +4

      start j with i *i , you will optimise it even further.

    • @shivanshbhardwaj5841
      @shivanshbhardwaj5841 4 роки тому

      then what will be the time complexity?

    • @VarsneyaSrinivas
      @VarsneyaSrinivas 3 роки тому

      @@aor6956 I was going to say this for those who are wondering about the proof here goes:
      you might think this Gentleman has asked you to skip numbers from i*2-i*(i-1) for each i but if you observe all these numbers have already been marked of by numbers from 2 to (i-1) for which we have already marked the sieve. Therefore we can start from j = i*i and still get away with it.

    • @chagantisubhash2456
      @chagantisubhash2456 2 роки тому

      @@VarsneyaSrinivas j=i*i will work. But how to prove it??

  • @deh773
    @deh773 4 роки тому +5

    I homeschool, but I knew the equation. However, I can't teach something if I can't explain it. I've been looking but none explained it so well to me. Now I can explain it to someone else. Thank you for taking your time to give a very good explanation.

  • @alexanderpetranov
    @alexanderpetranov 15 днів тому +1

    Rest in piece! You will be remembered forever through your excellent teaching🤎

  • @TomLobato
    @TomLobato 7 років тому +7

    Thanks a lot. Very very helpful lessons!
    I`ve noticed something confusing in 3:01. "If 2 is prime, then all multiples of 2 cannot be prime". Actually, any multiple of any positive integer cannot be prime, no matter if the factor is prime. Please let me know if I`m missing something.

    • @abhishiekmahajan9103
      @abhishiekmahajan9103 6 років тому

      say for eg take 4 as it is not prime and its factor is 2 .and every multiple 0f 4 will already be cancelled by the multiple of 4.

  • @SYLperc
    @SYLperc 7 років тому +2

    for any grid that is a square, you only need to work out the first row of numbers. the numbers left uncrossed in the grid will be primes.
    so for n=1,000,000, you only need to work out the first row of 1,000 to find every prime in the 1,000x1,000 grid.

  • @rishabhmalhotra1317
    @rishabhmalhotra1317 3 роки тому

    Thank you, Your legacy lives on Harshal

  • @borissklyar1415
    @borissklyar1415 8 років тому +5

    I propose much more simplier "matrix sieve" algorithm for finding prime numbers:
    In order to find all primes (up to a given limit) in the sequence S1(p)=6p+5,(p=0,1,2,3,...):
    Step 1a. Starting from 5 cross out each 5th member of the row of positive integersN(n)=0,1,2,3,4..., i.e remove the following integers: 5, 10, 15,...
    Step 1b. Starting from 5 cross out each 7th member of the row of positive integers, i.e remove the following integers: 5, 12, 19,..
    Step 2a.Starting from 23 cross out each 11th member of the row of positive integers, i.e remove the following integers: 23, 34, 45,...
    Step 2b. .Starting from 23 cross out each 13th member of the row of positive integers, i.e remove the following integers 23, 36, 49,...
    .........
    Step ia. Starting from (6i^2−1) cross out each (6i−1)th member of the row of positive integers.
    Step ib. Starting from (6i^2−1) cross out each (6i+1)th member of the row of positive integers.
    Remaining members of N(n) are indexes p of all primes (up to a given limit) in the sequence S1(p)=6p+5: p=0,1,2,3,4,...,6,7,8,9,...,11,..,13,14,....,16.....p=and primes are 5,11,17,23,29,...,41,47,53,59,...,71,...,83,89,...
    In order to find all (up to a given limit) primes in the sequence S2(p)=6p+7,(p=0,1,2,3,...):
    Step 1a. Starting from 3 cross out each 5th member of the row of positive integers, i.e remove the following integers 3,8,13,...
    Step 1b. .Starting from 7 cross out each 7th member of the row of positive integers, i.e remove the following integers 7,14,21,...
    Step 2a.Starting from 19 cross out each 11th member of the row of positive integers, i.e remove the following integers 19,30,41,...
    Step 2b. .Starting from 27 cross out each 13th member of the row of positive integer, i.e remove the following integers 27,40,53,...
    .........
    Step ia.Starting from (6i^2−1−2i) cross out each (6i−1)th member of the row of positive integers.
    Step ib.Starting from (6i^2−1+2i) cross out each (6i+1)th member of the row of positive integers.
    Remaining members of N(n) are indexes p of all primes (up to a given limit) in the sequence S2(p)=6p+7: p=0,1,2,..,4,5,6,..,9,10,11,12,...,15,16.... and primes are7,13,19,...,31,37,43,...,61,67,73,79,...,97,103,...
    C++ program:
    www.planet-source-code.com/vb/scripts/BrowseCategoryOrSearchResults.asp?lngWId=3&blnAuthorSearch=TRUE&lngAuthorId=21687209&strAuthorName=Boris%20Sklyar&txtMaxNumberOfEntriesPerPage=25

    • @josevillegas2721
      @josevillegas2721 8 років тому

      Boris Sklyar this is pretty cool, how'd you come up with this? What is the time complexity?

    • @PabitraPadhy
      @PabitraPadhy 3 роки тому

      @@josevillegas2721 : you would have found this already, but it's there in CLRS book

  • @AtifShafiinheritance
    @AtifShafiinheritance 5 років тому

    best channel for data structures

  • @manaswitadatta
    @manaswitadatta 6 років тому +13

    T(n) would be sqrt(n)log log n. Explanation was correct. Just a typo.

    • @ankitsharma8221
      @ankitsharma8221 5 років тому +1

      couldn't be. We're setting each value of primes as -1 for (n+1) times so it's O(nloglogn)

    • @mohitranka9840
      @mohitranka9840 5 років тому

      @@ankitsharma8221 Which is set part in the outer loop. The overall complexity is O(n^0.5 * log log n) + O (n)

  • @AshutoshTiwari0
    @AshutoshTiwari0 9 років тому +12

    I have been trying to find the most optimized method to find prime numbers.
    Yours was most efficient and easiest to understand so far.
    Upon experimenting, I found a more optimised solution.
    In second nested for loop where j starts from 2.
    we multiply j to i where i starts from 2 -> sqrt(n)
    Instead of using 2 we can set j = i in the second nested loop
    lets say i = 5 and j = 2 as of now
    but since 5 * 2 = 10, 5 * 3 = 15 , 5 * 4 = 20 where 10, 15, 20 are already covered by 2 and 3 respectively. there is no need to override those 0 from Prime[] array.
    we could directly go to 5 * 5 where 25 isnt marked yet 0.
    What can be the time complexity of this new approach?
    #include
    #include
    using namespace std;
    int main()
    {
    cout.sync_with_stdio(false);
    unsigned long int n = 100000;
    unsigned long int i,j;
    int boo[n];
    for(i=0;i

    • @saifrehman2776
      @saifrehman2776 7 років тому +3

      Time complexity will still be the same i.e. O(n*log logn)

    • @aarushiaiyyar
      @aarushiaiyyar 7 років тому

      Excellent! Even I want to know the time complexity of this algorithm.

  • @maheshvangala8472
    @maheshvangala8472 5 років тому

    Searching for a good video on seive method. found the best one

  • @rajeshgopidi7842
    @rajeshgopidi7842 7 років тому +26

    Is it not possible to run the second for loop from j = i instead of starting from 2?

    • @AmitCodes
      @AmitCodes 4 роки тому +4

      yes it is.
      proof: let us assume n is divisible by i*j where j < i
      So if (i*j) can divide or lets say cancel out n then n should have been cancelled out by j (because j is less than i).
      Thus not possible

    • @visheshkumar7812
      @visheshkumar7812 4 роки тому +3

      yes...infact the second loop IS started from j=i*i that's how we get the required time complexity....he made a mistake in the video

  • @herzalla9
    @herzalla9 5 років тому

    If used square root of n and j=i*i;j

  • @sanjayidpuganti8367
    @sanjayidpuganti8367 8 років тому +10

    Actually you can have a variable inside an array subscript in C/C++, given the variable is already initialized

  • @sidddddddddddddd
    @sidddddddddddddd 8 років тому

    The condition for second loops is "i*j

    • @SHUBHAMKUMAR-zc5ns
      @SHUBHAMKUMAR-zc5ns 8 років тому

      You didn't understood the algorithm properly,let's say 18 which is not a prime must have been struck off by any no. less than sqrt(18).

  • @lomeshdaheria9960
    @lomeshdaheria9960 4 роки тому

    Loved the way you explained and the optimization part as well thank you

  • @tomasz-rozanski
    @tomasz-rozanski 8 років тому +1

    You can optimise even more by changing the initialization in the inner loop. Instead of:
    j = 2
    use
    j = i

    • @Advanta09
      @Advanta09 6 років тому

      Exactly!

    • @kartikprakash4681
      @kartikprakash4681 5 років тому

      How will that make sure that we are striking off every multiple of i? Correct me if i am wrong :)

    • @kausachan4167
      @kausachan4167 3 роки тому +2

      ​@@kartikprakash4681 Okay I can explain you, lets say we're currently computing for 13
      13 * 2 = 26 (As it is 13*2, it becomes multiple of 2, so it would get striked while executing i = 2)
      13 * 3 = 39 (now 13 becomes multiple of 3 , so it would striked whiile executing i = 3)
      13 * 4 = .... (striked while executing i = 2)
      13 * 5 = .... (striked while executing i = 5)
      13 * 6 = .... (striked while executing i = 2)
      13 * 7 = .... (striked while executing i = 7)
      13 * 8 = .... (striked while executing i = 2)
      13 * 9 = .... (striked while executing i = 3)
      13 * 10 = .... (striked while executing i = 2)
      13 * 11 = .... (striked while executing i = 11)
      13* 12 = ....(striked while executing i = 2)
      13 * 13 = From here you need to start executing again
      Hope this helps !

    • @AyushRaj-pm1dz
      @AyushRaj-pm1dz 2 роки тому

      @@kausachan4167 well explained

  • @pranjalgupta9427
    @pranjalgupta9427 4 роки тому +1

    Nice explanation 😊👏

  • @kausachan4167
    @kausachan4167 3 роки тому

    j = i would be fine becoz
    For example, lets say we're currently computing for 13
    13 * 2 = 26 (As it is 13*2, it becomes multiple of 2, so it would get striked while executing i = 2)
    13 * 3 = 39 (now 13 becomes multiple of 3 , so it would striked whiile executing i = 3)
    13 * 4 = .... (striked while executing i = 2)
    13 * 5 = .... (striked while executing i = 5)
    13 * 6 = .... (striked while executing i = 2)
    13 * 7 = .... (striked while executing i = 7)
    13 * 8 = .... (striked while executing i = 2)
    13 * 9 = .... (striked while executing i = 3)
    13 * 10 = .... (striked while executing i = 2)
    13 * 11 = .... (striked while executing i = 11)
    13* 12 = ....(striked while executing i = 2)
    13 * 13 = From here you need to start executing again
    Hope this helps !

  • @gaganbedi4332
    @gaganbedi4332 2 роки тому

    8:40 for i=2, we are striking off 6 elements. Here n=15, and n/2 !=6. can you please explain how n/2 n/3 ... ?

  • @hujingtao1
    @hujingtao1 5 років тому

    your explanation is so great

  • @pookie-dev
    @pookie-dev 3 роки тому

    Really good explanation!

  • @rishabhjain2404
    @rishabhjain2404 4 роки тому +2

    thank you for explaining the logic of using sqrt(n). Noone else has explained this logic.

  • @vakhariyajay2224
    @vakhariyajay2224 2 роки тому +2

    Thank you very much. 👍 👍🔝🔝🙏🙏

  • @SmokyBigSmoke
    @SmokyBigSmoke 4 роки тому

    Thank you so much.Really great explanation.

  • @iaktech
    @iaktech 10 років тому

    You are doing a great Job man!

  • @sarcaastech
    @sarcaastech 5 років тому

    better if we use boolean array than integer it will save some time while printing the array !
    void sieve(int n)
    {
    bool prime[n+1];
    memset(prime,true,sizeof(prime);
    for(int i=2;i*i

  • @malharjajoo7393
    @malharjajoo7393 8 років тому +2

    Great video. But wikipedia seems to have one more optimization , at every prime it seems to start cancelling it's multiples from i^2 onwards...

    • @utsavprabhakar5072
      @utsavprabhakar5072 6 років тому

      Yep i saw that. Optimisations never end!

    • @malharjajoo7393
      @malharjajoo7393 6 років тому +2

      @@utsavprabhakar5072 Yeah, this video/algorithm is very very basic, there are many more optimizations on this.
      There is one simple (implementation wise) extension to get linear complexity as well..

  • @namrataswain7999
    @namrataswain7999 4 роки тому

    Amazing video. Great work :)

  • @anshumangaur7290
    @anshumangaur7290 5 років тому

    best video on Sieve of Eratosthenes :)

  • @kushsharma3716
    @kushsharma3716 6 років тому +1

    Can you please explain the meaning of the line at 5:03, i'm not getting it even after watching it several times.
    Its a humble request!

    • @AryanSinghBCS
      @AryanSinghBCS 5 років тому +1

      He has initially assumed all the numbers from 0 to n are prime, then as we know 0 and 1 are not prime so he make them 0 and then he start the loop taking i=2 to n , i hope u understood

  • @parasmalhotra7633
    @parasmalhotra7633 6 років тому

    best explained the sieve in a short duration...

  • @ashiqimran5961
    @ashiqimran5961 5 років тому

    clearly explained, good work !!!

  • @maheshvshet
    @maheshvshet 4 роки тому

    This is nice video, in the inner for loop, if j is initialized to i, we can save some more loops.

  • @RishabhLohia3
    @RishabhLohia3 8 років тому

    The first algorithm's time complexity is lesser than O(n^3/2). The inside loop has complexity sqrt(i) each time(not sqrt(n)). So it will be something like sqrt(2) + sqrt(3) + .....sqrt(n). Don't know the sum but should be lesser than n^3/2.

  • @sreekumarmenon
    @sreekumarmenon 11 років тому +10

    the first loop could also start from 2 instead?

    • @mycodeschool
      @mycodeschool  11 років тому +7

      the elements in the array may not be set as zero just with the declaration. So, anyway we would have to set value explicitly. But yes, we could do it differently.

    • @abhinavgupta6743
      @abhinavgupta6743 5 років тому +3

      @@mycodeschool we are not using index 0 or 1 so it will not effect i think

  • @hmt001
    @hmt001 8 років тому +5

    Thank you for this video :D !!! Just one question, I saw an implementation that only started marking off numbers starting from that number squared rather than from that number times 2 like you did in this video. (example: when you get to 3 and see that it is a prime you start marking from 9 rather than 6 because 6 would just be 3 times 2 and you already marked off all the multiples of 2) Is that a correct way to implement this?

  • @Hampirathna
    @Hampirathna 5 років тому

    Superb explanation

  • @utkarshsingh3541
    @utkarshsingh3541 4 роки тому

    waaaoo man ...so simplified...kudossssss

  • @SunilSingh1994
    @SunilSingh1994 8 років тому

    good explanations. Thank u so much Sir

  • @JohnnyKnight5talker
    @JohnnyKnight5talker 11 років тому

    awesome. python list size limit is ruining the problem to solve largest prime factor of a really large number using this method

  • @rajkesharwani4344
    @rajkesharwani4344 5 років тому +2

    Subtitles hide the contents which u write down the white board

  • @shubhamtripathi7928
    @shubhamtripathi7928 8 років тому +1

    Will you please a upload a video on segmented sieve too..

  • @letsthinkit6015
    @letsthinkit6015 6 років тому +1

    I have a qus here.If at first we set all the elements in the array equal to 1,how the real numbers exists in the array?

    • @ashutoshpawade8570
      @ashutoshpawade8570 5 років тому

      we are checking the indices of the array not their values

  • @obentabiayuk4780
    @obentabiayuk4780 6 років тому

    the first loop runs for (n-1) times why use O(n*sqrtn), and not O(n-1)*sqrtn for the time complexity

    • @amuzakishikawa3730
      @amuzakishikawa3730 5 років тому +1

      Valid point, I think he meant that, just slipped up

    • @manthankhorwal1477
      @manthankhorwal1477 5 років тому

      That doesnt matter ... Compiler will take same time in both of them
      (N-1)*sqrt(N)= N*sqrt(N) - sqrt(N)
      That sqrt(N) doesnt improve the time complexity

  • @prashantdas5554
    @prashantdas5554 8 років тому

    Thank you. Great explanation. :)

  • @gladyouseen8160
    @gladyouseen8160 5 років тому

    Please make video for time complexity of o(n)
    i.e. manipulated version of eratosthanes

  • @shaikjareena797
    @shaikjareena797 4 роки тому +1

    How could we know the number of loops we have to use in this program. As u have used if loop and for loop what's the difference and when to use both of them ???

  • @dhruva1221
    @dhruva1221 5 років тому

    if we are setting every array element of size n with value 1, what are we at end returning? why do we make whole array of value 1?
    Also, time complexity = O(n * log log n) + O(n) where, O(n) is highest among two, won't the complexity of whole program will be O(n)?
    About O(n* log log n ) if we are looping for sqrt(n), should not this to go by = O(sqrt(n) * log log n) ?!
    If we making whole array made up of 1, and looping through only sqrt(n), from where & what we will return as final output?eg n=100 & sqrt=10 then from where a prime numbers beyond sqrt(n) to be returned?

    • @sriram8027
      @sriram8027 4 роки тому

      ua-cam.com/video/7CyBf-xZF4c/v-deo.html

  • @ekhliousful
    @ekhliousful 7 років тому +1

    +mycodeschool can you make a video specially of O(N) & theta(N) complexity?!

  • @nomaannafi1093
    @nomaannafi1093 4 роки тому

    Where are you now? Why do you stop making videos? Please come back and start making videos again.

    • @sriram8027
      @sriram8027 4 роки тому +1

      We lost him unfortunately in an accident

    • @nomaannafi1093
      @nomaannafi1093 4 роки тому

      @@sriram8027 What!! seriously?

    • @sriram8027
      @sriram8027 4 роки тому

      @@nomaannafi1093 yourstory.com/2014/06/techie-tuesdays-humblefool

    • @sriram8027
      @sriram8027 4 роки тому

      One of the co founder is no more

  • @ok.tanmay
    @ok.tanmay 4 роки тому

    easiest explanation i found on internet

    • @Shelly888-s1r
      @Shelly888-s1r 4 роки тому

      I got the concept...but still not the code....so do I cram it or try understanding the code.....if u can help me with it....😦😦😦..pls

  • @arjunm8431
    @arjunm8431 3 роки тому

    the outer loop starts from 2 - till n so the outer loop runs n-1 times so ignoring the constant n times*sqrt(n)
    if i am correct???

  • @Aniket7Tomar
    @Aniket7Tomar 10 років тому

    in analysis of trial division we will get something like,
    n^1/2+(n-1)^1/2+(n-2)^1/2.....(n-(n-2))^1/2
    how can we get ur result n(root n) from this
    pls tell if i m wrong (i m bad at this)
    tnx

  • @94D33M
    @94D33M 6 років тому

    I dont understand which part of the code checks whether a number is prime or not? I only see code to mark numbers off, where is the actual finding whether 2 or 3 is prime or not ?

  • @rayalubaggi
    @rayalubaggi 6 років тому +6

    best video but variable or expression we can use as a size in array in c/cpp.

  • @hassanmahmoud9035
    @hassanmahmoud9035 6 років тому

    i see another optimization here you can make the second loop increment by j+=i rather than j++

    • @arten3328
      @arten3328 5 років тому

      i dont think so, we are eliminating all the multiples of i, and using j as a multiplier for every next element of i

    • @pi_rand4266
      @pi_rand4266 4 роки тому

      Your method is valid if we are just taking the conditions in j instsed of involving i

  • @KanagaveluSugumar
    @KanagaveluSugumar 9 років тому

    Very clear :) Thank you!

  • @ManojSaini_15
    @ManojSaini_15 9 років тому

    I've created the array of size 1000 but my program can't calculate the prime numbers higher than 125 that means only 30 prime numbers..if it exceeds 30 then program terminates with an option to debug. I m not able to understand what's wrong in it.

  • @Alfafoxtrot001
    @Alfafoxtrot001 7 років тому

    when you are already starting loop from 2 then why you are checking if prime[i]==1 .you have already skipped 0 and 1

  • @kushagragupta4259
    @kushagragupta4259 6 років тому

    Subtitles are covering the content of page please try to solve this problem in future videos

  • @ShaeekhShuvro
    @ShaeekhShuvro 7 років тому +2

    why using prime[n+1} instead of prime[n]?

    • @Akash-kq8lm
      @Akash-kq8lm 7 років тому +9

      because we need to include "nth" number/index....ie...index stars from 0....so if n=4 and prime[4] then it will create
      total of n-1 index ...0th 1st 2nd 3rd...n=4 and prime[4+1] we'll get 0th 1st 2nd 3rd 4th total index hope you get the point.

    • @ShaeekhShuvro
      @ShaeekhShuvro 7 років тому +2

      crystal and clear!Thanks :D

  • @michaelkaufman5119
    @michaelkaufman5119 3 роки тому

    Wildly wrong bounds for the loops.
    i := 0..sqrt(n) and
    j:= i*i...n+1 increment by i

  • @RudraSingh-pb5ls
    @RudraSingh-pb5ls 4 роки тому

    Why not O( sqrt(n).loglog(n) ) ?

  • @ivyzheng8681
    @ivyzheng8681 5 років тому

    Thank you sir.

  • @20_atulsingh57
    @20_atulsingh57 4 роки тому

    Why stopped uploading video we need your video

    • @sriram8027
      @sriram8027 4 роки тому

      We lost him in an accident

  • @dunnowut7005
    @dunnowut7005 8 років тому

    May I know why we define array of N+1 size rather than size N?

    • @shmolik930
      @shmolik930 8 років тому +1

      I'm pretty sure that's because array's are starting from 0 to n-1.
      so if ur n (the prime number you want to check) is 15 for example and you make an array of 15 cells so you will get 0-14 cells (that's 15 cells starting from 0).
      so you want to create a 16 cells array (starting from 0 to 15) in order to check if 15 is prime.
      hope you get it.

    • @dunnowut7005
      @dunnowut7005 8 років тому

      I thought you don't wanna check the the n number because it's obviously divisible by itself.

    • @philtrem
      @philtrem 7 років тому

      because we need to include index N (which represents our number N)

    • @philtrem
      @philtrem 7 років тому

      You want to include it because it's gonna get "crossed out" if it's not a prime. All numbers are divisible by themselves, what we're looking for is if they're divisible by any number that comes before them (other than 1).

  • @Atpugtihsrah
    @Atpugtihsrah 9 років тому

    Please make a video on Segmented Sieve @mycodeschool

  • @adithyasundar8904
    @adithyasundar8904 5 років тому

    Can anyone tell me if this applies for any ranges or just starting from 1 to n

    • @ayanbiswas6849
      @ayanbiswas6849 5 років тому

      To apply the logic in the user-defined range you can approach the segmented sieve concept.
      Follow the link: www.geeksforgeeks.org/segmented-sieve-print-primes-in-a-range/

  • @ravisinha1310
    @ravisinha1310 3 роки тому

    is this the voice of lord harshal??

  • @emmaautumn4666
    @emmaautumn4666 7 років тому

    what if you want to get the prime number between a two number? e.g 100 - 200

    • @TheGalactus16
      @TheGalactus16 7 років тому

      Call the method twice: return method(200) - method(100)

  • @nishantingle1438
    @nishantingle1438 6 років тому

    Can someone help me reduce the space complexity please

  • @yasahanzengin3329
    @yasahanzengin3329 7 років тому +1

    Thanks.

  • @rohankumar-of5qe
    @rohankumar-of5qe 5 років тому

    How to initialise array[n+1 in c++ ????

    • @PabitraPadhy
      @PabitraPadhy 3 роки тому

      use std::array if size is already known

  • @primakovch8332
    @primakovch8332 5 років тому

    Big theta or big oh???

  • @nakibtheexplorer5383
    @nakibtheexplorer5383 5 років тому

    for(int i=0;i

    • @arten3328
      @arten3328 5 років тому

      it is a loop used to initialize the array primes to 1, that means it is used to assign each element of the array primes to 1.
      making primes[0] = 1, primes[1] = 1 ..... primes[n] = 1.
      and later when we use the algorithms, the only numbers that are prime will have a value of 1 at its corresponding index.

  • @mahabubara1641
    @mahabubara1641 5 років тому

    I don't understand the "code implementation" part :(

    • @pranavkrishna4413
      @pranavkrishna4413 5 років тому

      bro ignore it. It is just pseudo code(just English like code :D)

  • @Ali-Intakhab
    @Ali-Intakhab 7 років тому

    in place of first for loop u can use
    max =10000;
    bool arr[max]={1};

  • @shahidabegum548
    @shahidabegum548 4 роки тому +1

    oh

  • @kirubagaran3749
    @kirubagaran3749 6 років тому

    thank you

  • @tv..6531
    @tv..6531 4 роки тому

    ua-cam.com/video/0ABnO_WoexE/v-deo.html
    를 이용하여
    1부터 1,000까지 사이에 있는
    소수의 개수(counting prime numbers)를 구하는 영상 입니다.

  • @mitultyagi3357
    @mitultyagi3357 7 років тому

    Running the programme on the computer would have been better. Still thanks for the video. Really good one about topic.

  • @devanshgoel3433
    @devanshgoel3433 2 роки тому

    thank u sir

  • @sonukumarprashant
    @sonukumarprashant 7 років тому

    nested for loop is wrong giving wrong output .It should be
    for(int i=2;i

  • @wassup102
    @wassup102 2 роки тому

    thank u

  • @pranavkrishna4413
    @pranavkrishna4413 5 років тому

    awesome

  • @bharathiDevi001
    @bharathiDevi001 5 років тому

    Here is the Program code:
    ua-cam.com/video/sx3Cw14XZoc/v-deo.html

  • @seraj_valley
    @seraj_valley 5 років тому

    great

  • @pratikshinde3402
    @pratikshinde3402 5 років тому

    2:25

  • @reshmianil4638
    @reshmianil4638 6 років тому

    Please say slowly not so fast sir

  • @travistarp7466
    @travistarp7466 5 років тому

    who the fuck uses pen and pencil to code

  • @jaydanplaza
    @jaydanplaza 8 років тому

    : (I hate it

  • @mahbubaurko8764
    @mahbubaurko8764 2 роки тому

    If i want to see the output like
    1 0
    2 1
    3 1
    4 0
    How can i write the code

  • @anuraganand7783
    @anuraganand7783 5 років тому

    Thank you

  • @preetamvarun9219
    @preetamvarun9219 5 років тому

    2:35

  • @Mythri333
    @Mythri333 10 місяців тому

    Thank you