Calculating Time Complexity | Data Structures and Algorithms| GeeksforGeeks

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ม.ค. 2025

ความคิดเห็น • 271

  • @michaelzumpano7318
    @michaelzumpano7318 4 ปีที่แล้ว +350

    Bravo, that was the clearest yet most complete 8 min intro to complexity on TH-cam. Hey, you found a good teaching algorithm - balance time and headspace efficiencies. Props.

  • @thembalamimsimango8993
    @thembalamimsimango8993 3 ปีที่แล้ว +129

    You explained ten times better than my lecturer did in just 8-minutes, thank you

  • @W3Fi
    @W3Fi ปีที่แล้ว +10

    Incredible, I find myself at a loss for words to adequately express the precision and clarity of the elucidation.

  • @kevindsa57
    @kevindsa57 2 ปีที่แล้ว +60

    After 4 years of Engineering in Computer Science this was the best explanation of Time Complexity thank you !!

    • @I_am_FRANCO
      @I_am_FRANCO ปีที่แล้ว

      engineering in cs 🤔

    • @emrahcansahinoglu2342
      @emrahcansahinoglu2342 4 หลายเดือนก่อน +3

      @@I_am_FRANCO In some countries like mine (Türkiye formerly Turkey) the major called Computer Engineering is identical to Computer Science in both curriculum and concept. However, we just took a couple of more courses (in my opinion) from Electrical and Electronics Engineering regarding to the Hardware. Even my degree is given as B.S. in Comp. Eng. I guess he may have a similar situation.

  • @meBZcookie
    @meBZcookie 4 ปีที่แล้ว +37

    6:04 Time Complexity for Sorts

  • @stith_pragya
    @stith_pragya 9 หลายเดือนก่อน +1

    Thank You So Much for this wonderful video......................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @siddharthpal7452
    @siddharthpal7452 หลายเดือนก่อน

    I was struggling to calculate time complexity from a long time . As , I was not able to understand , I was rote memorizing a lot of things . Huge thanks to you for explaining this in such a simple way .

  • @bhaskarnarayan2109
    @bhaskarnarayan2109 3 ปีที่แล้ว +85

    You could also mention the complexities like O(logn), O(nlogn) etc. and the concepts of Master Theorem. It would be better.

  • @stephenmusau2394
    @stephenmusau2394 2 หลายเดือนก่อน

    The simplest yet most comprehensive explanation that I have come across. Well done sir!

  • @ohmegatech666
    @ohmegatech666 3 หลายเดือนก่อน

    Good video. Quick correction at 5:48, O(n^c) is not exponential, it's polynomial since the exponent is a constant, like O(n^2) or O(n^3). Exponential is when the variable itself is in the exponent like O(2^n)

  • @WitchelsArtSchool
    @WitchelsArtSchool 11 หลายเดือนก่อน +1

    best video explaining complexity. the complexity of complexity have been resolved here :D

  • @alekhyarao5431
    @alekhyarao5431 11 หลายเดือนก่อน +3

    Excellent explanation and easy to understand. Thank you!

  • @outsiderthevoid8780
    @outsiderthevoid8780 3 หลายเดือนก่อน

    this guy taught me more in 8 minutes than my professor did in 3 weeks love u bro❤

  • @ObsessedMee
    @ObsessedMee 4 ปีที่แล้ว +8

    This is called clear concept 🙌✨

  • @ankishgupta1517
    @ankishgupta1517 5 ปีที่แล้ว +20

    Perfect explanation...plzz upload more videos on complexities... 👌

  • @meowrice
    @meowrice 3 ปีที่แล้ว +4

    thanks! i finally understand bigO notations! the last part also is a big bonus for me. thank you!

  • @LucusJanny
    @LucusJanny 2 ปีที่แล้ว +1

    It was the best video on TH-cam about Time complexity. Best wishes for you bro

  • @AV-mb8lv
    @AV-mb8lv 4 ปีที่แล้ว +29

    Explains O(1), O(n), O(n^2). Then says, "now let's look at the scale of diff. complexities O(1), O(log n), O(n), O(nlog n), O(n^2)"
    Wait, where are the missing bits?
    "Now you'll be able to calculate all time complexities of the algorithms"

    • @himanshukandwal8710
      @himanshukandwal8710 3 ปีที่แล้ว +1

      for(int i=0; i

    • @jqn8361
      @jqn8361 3 ปีที่แล้ว +1

      @@himanshukandwal8710 O(n), You're going through all the i elements of the list (this is repeated n times + 1 time, just before the for loop breaks), which is a function of n, and assigning them to an integer value, which takes constant time. Searching through the linked list also takes constant time. You're also printing each element, which also takes constant time. So you have T(n) = c1*(n+1) + c2 + c3 + c4 = O(n)

    • @biikaaa.6540
      @biikaaa.6540 3 ปีที่แล้ว

      @@himanshukandwal8710 O(n)

    • @harshitraj953
      @harshitraj953 3 ปีที่แล้ว

      @@himanshukandwal8710 hllo,, sir,,
      Don't act 😎Smart sir

  • @twinkleshaw693
    @twinkleshaw693 ปีที่แล้ว +1

    Best video ever watched ❤️

  • @ece547teamsioux5
    @ece547teamsioux5 4 ปีที่แล้ว +6

    Great efforts.
    Thank you:)
    Regards from USA

  • @mohammedghabyen721
    @mohammedghabyen721 4 ปีที่แล้ว +3

    Best explanation, thank u

  • @jerrybear5866
    @jerrybear5866 3 หลายเดือนก่อน

    Thank you , you saved me for exam today.

  • @aleksandrakja6792
    @aleksandrakja6792 11 หลายเดือนก่อน +7

    You explained this misery better than my teacher ever could

  • @swapnildadamode662
    @swapnildadamode662 4 ปีที่แล้ว +3

    Man! You're the best! This is what i need

  • @बिहारीभायजी
    @बिहारीभायजी 3 ปีที่แล้ว +5

    Simple and great content. I wonder how my prof taught

  • @laawuni
    @laawuni 3 ปีที่แล้ว +1

    Best so far. you saved me

  • @Tauhid214
    @Tauhid214 ปีที่แล้ว +1

    I appreciate your work. How about the for loops: for(i=1, i

  • @infi-tech3808
    @infi-tech3808 ปีที่แล้ว

    I believe there was a mistake on 4:23: The time complexity for this sequence of loops would be O(n) + O(n), which simplifies to O(2n) not 0(n)

    • @heycalvinnn
      @heycalvinnn ปีที่แล้ว +1

      You remove the constant in this case the 2 in 2n so you would be left with O(n)

  • @floki6939
    @floki6939 3 ปีที่แล้ว +1

    Precise illustration. Thank you

  • @meghaadikarinayake7067
    @meghaadikarinayake7067 11 หลายเดือนก่อน +2

    Thank you very much!!!!❤

  • @AhmedAli-kf2wg
    @AhmedAli-kf2wg 3 ปีที่แล้ว +7

    I really appreciate the way you teach us. Thanks a lot sir : >)

  • @josephbermudez9533
    @josephbermudez9533 4 ปีที่แล้ว +22

    for 4:10, it is O(2n).
    Not O(n)
    Great video, thanks!

    • @BigYous
      @BigYous 4 ปีที่แล้ว

      you drop the constants for big O

    • @resep1234
      @resep1234 4 ปีที่แล้ว

      @@BigYous but if you drop the constants it should still be n+n which is 2n

    • @arjunjain7773
      @arjunjain7773 4 ปีที่แล้ว

      You don't use constants for bigO I don't know why... It's stupid but that's just how it is

    • @ognimoddd
      @ognimoddd 4 ปีที่แล้ว +6

      @@arjunjain7773 No, it's not stupid. The constants don't affect it as input gets bigger so it is useless to keep

    • @shawmcinroy472
      @shawmcinroy472 4 ปีที่แล้ว +1

      lepke 2 is a constant...

  • @pradeepsinghrajput07
    @pradeepsinghrajput07 3 ปีที่แล้ว +5

    Really to the point and efficient explanation. Kudos

  • @manishjoshi4989
    @manishjoshi4989 4 ปีที่แล้ว +2

    one doubt in sequence time complexity you described
    c1 + c2 n + c3 n = BigO n time complexity ( doubt is after removing constant from equation why n + n is not 2n)

    • @firdousanjum7893
      @firdousanjum7893 3 ปีที่แล้ว +2

      2 is constant so remove it. It will now b o(n)

  • @aladdinalswaifi9655
    @aladdinalswaifi9655 2 ปีที่แล้ว +1

    Well done
    Very clever and clear explanation
    Many Thanks

  • @srichandana5122
    @srichandana5122 3 ปีที่แล้ว +1

    very clear and understandable .... thank u for ur vedio

  • @jamesstark4136
    @jamesstark4136 4 ปีที่แล้ว +10

    Thanks! this helped a lot for my CS 211 class.

  • @hashantha_lk
    @hashantha_lk ปีที่แล้ว

    Thanks, that was the most enlightening explanation it to complexity after lot of confusing video explanations on YT. You are the best !

  • @lakshmibonala2813
    @lakshmibonala2813 3 ปีที่แล้ว +7

    How c1+c2n+c3n = O(n)?? Is it O(2n) by removing constants.

    • @Sanatani_kanya_
      @Sanatani_kanya_ ปีที่แล้ว +4

      C1+n(C2+C3)

    • @notnemeziz
      @notnemeziz 4 หลายเดือนก่อน

      O(2n) and O(n) are the same thing....O here stands for order of...so 2n, 3n or any cn is an order of n ie O(n)

  • @LilJollyJoker
    @LilJollyJoker ปีที่แล้ว +1

    Thank You!

  • @debsankarpal763
    @debsankarpal763 ปีที่แล้ว

    Wonderful! Best explanation in 8 minutes

  • @pomegranate8593
    @pomegranate8593 4 ปีที่แล้ว +2

    when u said welcome to video i felt rly welcomed thank u my friend! also very helpful video!

    • @YeabselamKassaye
      @YeabselamKassaye 11 หลายเดือนก่อน

      😂😊😊😊😊😊😊

  • @matteooccello491
    @matteooccello491 3 ปีที่แล้ว +12

    Thanks for the video! It was clear and really practical :)

  • @AdeniranAbisolaAbiwax
    @AdeniranAbisolaAbiwax 2 ปีที่แล้ว

    This is the best explanation i have come across so far

  • @sumantabanerjee9728
    @sumantabanerjee9728 ปีที่แล้ว

    for(i=0; i

  • @neerajmahapatra5239
    @neerajmahapatra5239 3 ปีที่แล้ว

    You are very clear and easy to understand. Thanks...😍😍😍😍

  • @shambhaviraj1642
    @shambhaviraj1642 5 หลายเดือนก่อน

    wouldn't the loop at 2:56 run n+1 times for the outer loop running n times?

  • @DWEthiopia
    @DWEthiopia 3 ปีที่แล้ว +3

    4:11 - Why for sequential statements, you don't add the n's together to make O(n + n);

    • @shezitt3205
      @shezitt3205 3 ปีที่แล้ว

      I thought the same.

    • @ashwanimishra5829
      @ashwanimishra5829 3 ปีที่แล้ว +2

      When we add them they become 2n and we can ignore the constant so it all comes down to O(n)

    • @shail0124
      @shail0124 2 ปีที่แล้ว

      @@ashwanimishra5829 But this is just wrong practically. For example if 1st loop taking 1 second and other one is also taking 1 second to run then total time taken to run will be 2. But according to O(n) time taken will be 1 second

  • @jhonbhai8943
    @jhonbhai8943 3 ปีที่แล้ว +5

    I was too much Dived into his Teaching .That I heard someone sparking gas Stove lighter at 1:34😂

  • @msnraju97
    @msnraju97 2 ปีที่แล้ว

    Very good explanation, Learned in 10mins
    Indian Engineer's lives depend on GFG. without it IT industry will fall

  • @mahendrasahani9148
    @mahendrasahani9148 ปีที่แล้ว

    thank you, very good teaching algorithms

  • @DaBaSoftware
    @DaBaSoftware 2 ปีที่แล้ว +1

    Thank you for the resource!

  • @deferkings
    @deferkings 4 ปีที่แล้ว +3

    In 4:22 when calculating the time complexity of the sequential loops, once we take c1, c2, c3 aren't we left with two "n " therefore "= o(n^2) . Im not sure my logic is taking me there if someone can explain to me why I'm wrong pls thank you
    Great video btw thank you .

    • @Typw
      @Typw 3 ปีที่แล้ว +5

      it is not nested therefore it is not multiplied, it will be just c1+(c2+c3)n => O(n)

    • @-KeerthanaJ-ww7qo
      @-KeerthanaJ-ww7qo 3 ปีที่แล้ว

      Thank you dude...I too had same doubt...but u helped me... 😍

    • @-KeerthanaJ-ww7qo
      @-KeerthanaJ-ww7qo 3 ปีที่แล้ว

      @@Typw thanks a ton

    • @Ni7ram
      @Ni7ram 2 ปีที่แล้ว

      @@Typw why n instead of 2n? ive seen O(2n) lots of times, this is clearly a case

  • @hinaafzal4348
    @hinaafzal4348 2 ปีที่แล้ว

    Such a good way of teaching
    Very well done 👍👍👍

  • @Umerele1
    @Umerele1 ปีที่แล้ว +9

    man no matter how much i focus i can't understand time complexity 😥

  • @anonymoustravelvidz
    @anonymoustravelvidz 3 ปีที่แล้ว +1

    thank you, very helpful video.

  • @danialsiddiqi635
    @danialsiddiqi635 3 ปีที่แล้ว +1

    Thank you for this video.

  • @farzamafifi2257
    @farzamafifi2257 4 ปีที่แล้ว +1

    Evaluate single-core performance for integer computation. Perform two experiments: with task bound
    to the APP core and separately to the PRO core. Observe if there is a difference in measurements.
    Propose an algorithm that is able to generate a complexity of integer computation observable and
    measurable. Perform at least 10 measurements for each experiment. Consider using parts of code for
    Dhrystone benchmark its is my task is any has source code for in c ++ cause have to run in vrel

  • @mathwithmathu1755
    @mathwithmathu1755 2 ปีที่แล้ว

    Really superb and very useful. Very good explanation...

  • @studentbengal4043
    @studentbengal4043 3 ปีที่แล้ว

    Best tutorial ever on this topic...
    Thanks

  • @GGanzolo
    @GGanzolo ปีที่แล้ว

    Really good introduction of time complexity. Thank you!

  • @rahulmajumdar5525
    @rahulmajumdar5525 2 ปีที่แล้ว

    Thank you for the great explanation straight to the point.....

  • @AYESHAZAMURD-s4p
    @AYESHAZAMURD-s4p 3 หลายเดือนก่อน

    Sir what if in sequential statement the time take by each statement was n+n^2 + n^ 3 then what would be the total Time complexity...?

  • @seemarani2403
    @seemarani2403 2 ปีที่แล้ว

    Awesome explanation👌👌

  • @subbusharma3990
    @subbusharma3990 4 ปีที่แล้ว +2

    Thank you for this
    Regards from Russia

  • @atharva..deshmukh
    @atharva..deshmukh 4 ปีที่แล้ว +2

    Finally, I got something that I wanted!!

  • @johndavies729
    @johndavies729 3 ปีที่แล้ว +1

    Really well explained. Thank you!

  • @kanishkaralasi7408
    @kanishkaralasi7408 2 ปีที่แล้ว +1

    Wonderful explanation! You're the best 💯

  • @code2compass
    @code2compass 8 หลายเดือนก่อน

    How is the sequential O(n)? Does it add up all together? I thought it should be O(2n)

  • @gaziashfaq1937
    @gaziashfaq1937 9 หลายเดือนก่อน +1

    4:18 should be 2n no?

    • @yolo-ed9dk
      @yolo-ed9dk 8 หลายเดือนก่อน +1

      he already said you dont use the constant, 2n is just treated as n. The thing i am struggling with is k

  • @Reacher1998
    @Reacher1998 3 ปีที่แล้ว +1

    Helped a lot, great video 🔥

  • @gauria6688
    @gauria6688 ปีที่แล้ว

    Please make a video on space complexity

  • @martinnieva8484
    @martinnieva8484 2 ปีที่แล้ว +1

    This was a wonderful introduction! Thank you

  • @956zombie956
    @956zombie956 5 ปีที่แล้ว +11

    The best !

  • @JamesBrodski
    @JamesBrodski 3 ปีที่แล้ว +1

    Great video. Thank you so much! Very helpful

  • @isaicsefxec6721
    @isaicsefxec6721 4 ปีที่แล้ว +1

    Pls upload some video regarding to gate cs

  • @hi-tk4hu
    @hi-tk4hu 3 ปีที่แล้ว +1

    very good explanation and easy for beginners to understand thank you❤️

  • @himanshukandwal8710
    @himanshukandwal8710 3 ปีที่แล้ว

    for(int i=0; i

  • @shreyapandey1423
    @shreyapandey1423 ปีที่แล้ว

    Best lecture 😊

  • @JPN-bx3yd
    @JPN-bx3yd 4 ปีที่แล้ว +1

    This is a great explanation.

  • @AbdurRahman-op8zn
    @AbdurRahman-op8zn ปีที่แล้ว

    Excellent ! Thanks a lot.

  • @ryanmckenna2047
    @ryanmckenna2047 3 ปีที่แล้ว

    Thanks that video was incredible...your incredible!

  • @saphalvecham5539
    @saphalvecham5539 ปีที่แล้ว

    Wonderfully put

  • @gangadharaswamy8856
    @gangadharaswamy8856 3 ปีที่แล้ว +3

    I think for 3 sequential statements time complexity is 2n+1

    • @ishika6945
      @ishika6945 ปีที่แล้ว

      hey can you tell me why in 4:13 its O(n) and not O(2n) since we are adding na...i do have doubt here. i will be highly obliged if u do reply. thankyou

    • @gaminghub23
      @gaminghub23 ปีที่แล้ว

      @@ishika6945 constants aren't important and are ignored in time complexity. It would not impact much or any

    • @gangadharaswamy8856
      @gangadharaswamy8856 ปีที่แล้ว

      ​@@ishika6945
      c1+c2n+c3n take common factor here n is common so we get
      =c1+n(c2+c3)
      Ignore constants c1, c2, c3
      Then we have "n" remains
      There fore time complexity will be 0(n)

    • @gangadharaswamy8856
      @gangadharaswamy8856 ปีที่แล้ว

      ​@@ishika6945
      c1+c2n+c3n
      =c1+n(c2+c3)
      Ignore constants c1, c2, c3
      Then we have "n" remains
      There fore time complexity will be 0(n)

  • @sagarchawla4926
    @sagarchawla4926 3 ปีที่แล้ว +3

    Smooth ✨

  • @shouryaverma6313
    @shouryaverma6313 4 ปีที่แล้ว +1

    ohh finally I found what I wanted
    thanks a lot sir

  • @Rajat-up7fn
    @Rajat-up7fn 2 ปีที่แล้ว

    what will be the ans if we take int size = 1 in space complexity

  • @heywoodjablome2767
    @heywoodjablome2767 2 ปีที่แล้ว

    Some things still don't make sense to me. Where exactly did the 4*4+4 come from for your 1st space complexity example? I get that an int variable has 4 bytes but how did you end up with the operation of multiplying two 4s and then adding them to one 4?

  • @anonymouscomment1772
    @anonymouscomment1772 4 ปีที่แล้ว

    @geeksforgeeks how does 4:16 equal to O(n) instead of O(n^2)? In the prior examples nested loops it resulted in O(n^2) - is this because example at 4:16 is not a nested loop compared to prior example where they are a nested loop?

    • @lastsecond959
      @lastsecond959 4 ปีที่แล้ว +2

      Yes, for example, you have a loop from 1 to 5 and inside it, you have a loop from 1 to 10, which means you run the "loop 1 to 10" 5 times, that what makes n^2. On the other hand, 4:16 is just n because you are doing separated loops and it adds up to be 2n and you remove 2, resulting in O(n).

    • @h132wayadandekumar7
      @h132wayadandekumar7 3 ปีที่แล้ว

      I had same doubt...

    • @h132wayadandekumar7
      @h132wayadandekumar7 3 ปีที่แล้ว

      @@lastsecond959 thanks 🙂 I didn't know that we have to remove constants like 2

    • @shail0124
      @shail0124 2 ปีที่แล้ว +1

      ​@@lastsecond959 How we can remove constant like 2? Practically O(n) will give wroong answer for time taken by all statements to execute. If 1st loop is taking 1sec and other is 1sec then total will be 2 sec but according to O(n) will be 1 sec

    • @lastsecond959
      @lastsecond959 2 ปีที่แล้ว

      @@shail0124 Have you tried looking it up before replying?

  • @yaro_05
    @yaro_05 ปีที่แล้ว

    Very nice. Thanks

  • @ritikarauthan3304
    @ritikarauthan3304 2 ปีที่แล้ว

    Amazing ❤❤❤❤❤❤❤❤

  • @aswink1505
    @aswink1505 5 ปีที่แล้ว +3

    thanks for the video. Can we use inbuilt functions in Javascript like sort and reverse in the interviews? If so, what should we assume of their complexities?

    • @pepehimovic3135
      @pepehimovic3135 3 ปีที่แล้ว

      Any updates? Did you find out?

    • @TonyDUsopp
      @TonyDUsopp 2 ปีที่แล้ว

      look up Tim Sort
      If the question does not ask you to use any sorting algorithm then you may at first use built in ones, then if the interviewer asks you to optimize you can pick an algorithm that suits the question

  • @marjoriejetajobe512
    @marjoriejetajobe512 3 ปีที่แล้ว +1

    Thanks, I learned a lot!

  • @Rubyd777
    @Rubyd777 2 ปีที่แล้ว

    Why is c2n+c3n only o(n) should ot be o(2n) assuming we only ignore constant term i particular line of expresson and statement

  • @LeelaseshuKumar
    @LeelaseshuKumar 3 ปีที่แล้ว

    Thanks for the explanation of time complexity. But you missed log n and n log n

  • @sheikhjabed3967
    @sheikhjabed3967 4 ปีที่แล้ว

    Very Helpful.Thanks a lot

  • @itbamalahat2226
    @itbamalahat2226 2 ปีที่แล้ว

    is nlog(n) the same as log(n)?

  • @padigapatinarmada9729
    @padigapatinarmada9729 4 ปีที่แล้ว

    Simply superb

  • @VReckful
    @VReckful 2 ปีที่แล้ว

    at 4:19 wouldn't that be n^2?

  • @dusmannalinwad
    @dusmannalinwad 2 ปีที่แล้ว

    short and great..!!