Calculating Time Complexity | Data Structures and Algorithms| GeeksforGeeks

Поділитися
Вставка
  • Опубліковано 30 вер 2024

КОМЕНТАРІ • 260

  • @studyIBwithBothra
    @studyIBwithBothra 10 місяців тому +150

    bro drink some water

    • @alihajali896
      @alihajali896 7 місяців тому +17

      bro my eye scaned the comment unintentionally, and I just couldn't unhear it any more 😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂

    • @isaacdarko1744
      @isaacdarko1744 7 місяців тому +2

      Same😂😂😂😂😂😂

    • @WeyardWiz
      @WeyardWiz 7 місяців тому

      😂

    • @jackobmike4626
      @jackobmike4626 7 місяців тому

      😂😂😂😂😂

    • @AnharAnsari
      @AnharAnsari 6 місяців тому +1

      I came here to study..now I can't stop laughing

  • @michaelzumpano7318
    @michaelzumpano7318 4 роки тому +326

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

  • @lakshmibonala2813
    @lakshmibonala2813 2 роки тому +6

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

    • @Sanatani_kanya_
      @Sanatani_kanya_ Рік тому +4

      C1+n(C2+C3)

    • @notnemeziz
      @notnemeziz 15 днів тому

      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)

  • @Umerele1
    @Umerele1 Рік тому +3

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

  • @thembalamimsimango8993
    @thembalamimsimango8993 3 роки тому +114

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

  • @bhaskarnarayan2109
    @bhaskarnarayan2109 3 роки тому +79

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

  • @tylerbakeman
    @tylerbakeman 6 місяців тому +1

    It's fast, which is great. But, you also don't explain things: "In big-O, you can ignore all of these constants"... no you can't; in that special case, you can; though, in general, you cannot.

    • @ruthy08
      @ruthy08 2 місяці тому

      In general, constants are completely ignored in Big O. Those constants can be significant when viewing it from a non-o perspective. Big O drops the constant because it's not what it was designed for.
      In big O, O(10¹⁰⁰n) is still just O(n). Linear time. O(10¹⁰⁰) is still just O(1), constant time. So, no, it's not just this one case. It's universal.

  • @jhonbhai8943
    @jhonbhai8943 3 роки тому +5

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

  • @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

  • @duhaqurashi4193
    @duhaqurashi4193 3 роки тому +1

    Bruh you licking the mic or something?

  • @meBZcookie
    @meBZcookie 4 роки тому +33

    6:04 Time Complexity for Sorts

  • @ankishgupta1517
    @ankishgupta1517 4 роки тому +19

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

  • @kevindsa57
    @kevindsa57 2 роки тому +52

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

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

      engineering in cs 🤔

    • @emrahcansahinoglu2342
      @emrahcansahinoglu2342 14 днів тому +1

      @@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.

  • @aleksandrakja6792
    @aleksandrakja6792 7 місяців тому +6

    You explained this misery better than my teacher ever could

  • @manishjoshi4989
    @manishjoshi4989 3 роки тому +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)

  • @thephelps
    @thephelps 6 місяців тому

    How did my professor overcomplicate this?

  • @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...

  • @officialspock
    @officialspock 4 роки тому +24

    I thought you're going to explain the other complexity as well like O(log n), O( n log n) etc...

    • @ozz961
      @ozz961 4 роки тому +8

      i wanted that ffs

  • @billsharon6949
    @billsharon6949 Місяць тому +1

    Nice explanation now drink some water

  • @donpikot3d-stl-4dl2combina5

    Can you do some formula in odd even betting? Like the interesting mall game? I am your new subscriber.. I hope you will reply sir. Thank you!

  • @W3Fi
    @W3Fi Рік тому +9

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

  • @ujjwaltyagi3537
    @ujjwaltyagi3537 Рік тому +1

    Who also notice lighter sound at 1:34

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

    This video explains only O(1),O(n) and O(n^2)
    Don't waste your time if your looking for other time complexity

  • @alakhwat4200
    @alakhwat4200 Рік тому

    What is "Big O" ??? Where do You get it from?? From where are you getting those equations from??
    Nothing Makes Sense...
    Oh My GOD...
    😭😭😭
    Edit :. Ok i watched the whole video and now i understand a lot of it. Lol

  • @ghad6799
    @ghad6799 Рік тому

    -Take these UA-cam instructors (ones that have genuine skill, no nepotism, racism, ageism etc)
    -Hire them into university with proper wage.
    -Keep facilities basic and dedicated to teaching skills only
    -Any student can afford.
    -stop paying garbage universities for slides
    ???
    -profit
    -better world, degeneracy removed, education system overhauled. No students struggle. Utopia

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

    Great efforts.
    Thank you:)
    Regards from USA

  • @rahmannfahim
    @rahmannfahim 7 місяців тому +4

    Any one from AIUB?🙂

  • @956zombie956
    @956zombie956 4 роки тому +11

    The best !

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

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

  • @AhmedAli-kf2wg
    @AhmedAli-kf2wg 2 роки тому +7

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

  • @mirzaadilbeg9209
    @mirzaadilbeg9209 3 роки тому +11

    For Example, 3 (Sequential Statements) should not be "2N" ?? because we are adding up.

    • @amanbutt7460
      @amanbutt7460 3 роки тому +6

      2 is again a constant.. I think that's why he dropped it

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

      @@amanbutt7460 but statement is c1+c2n+c3n so we will drop the constant and it will become n+n which is 2n

    • @Nikhil-Tomar
      @Nikhil-Tomar Рік тому +12

      @@mirzaadilbeg9209 and when it will be n+n=2n we will not consider 2 and still only have O(n) left

    • @EUROSPORTS4TECH
      @EUROSPORTS4TECH Рік тому

      Love from Pakistan well brother he is generalized it like it will be usable in every algorithm

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

    i understood this in bigO(n) time lol

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

    Why didn't you explain what is this beautiful 'k' character in formulae means?

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

    Simple and great content. I wonder how my prof taught

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

      As time moves 💕

  • @matteooccello491
    @matteooccello491 3 роки тому +11

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

  • @code2compass
    @code2compass 4 місяці тому

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

  • @ObsessedMee
    @ObsessedMee 3 роки тому +8

    This is called clear concept 🙌✨

  • @deferkings
    @deferkings 3 роки тому +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 2 роки тому

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

    • @-KeerthanaJ-ww7qo
      @-KeerthanaJ-ww7qo 2 роки тому

      @@Typw thanks a ton

    • @Ni7ram
      @Ni7ram Рік тому

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

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

    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 2 роки тому +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

  • @alekhyarao5431
    @alekhyarao5431 7 місяців тому +3

    Excellent explanation and easy to understand. Thank you!

  • @stith_pragya
    @stith_pragya 5 місяців тому +1

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

  • @Crayola24pcs-vr6bl
    @Crayola24pcs-vr6bl Рік тому

    Repent and forsake your sins and follow Jesus now he's coming

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

    Wow sitting in class 1hr 30 m and watch a 8m video…

  • @shambhaviraj1642
    @shambhaviraj1642 Місяць тому

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

  • @mohammedghabyen721
    @mohammedghabyen721 3 роки тому +3

    Best explanation, thank u

  • @adarshsalukhe9205
    @adarshsalukhe9205 Рік тому

    Can anyone plz explain space complexity again not got that 4*4+4

  • @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)

  • @jamesstark4136
    @jamesstark4136 4 роки тому +10

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

  • @amit-kumar-yadav
    @amit-kumar-yadav 3 роки тому +1

    You reached us wrong in sequential statement . Complexity will be O(n+n)
    Am I correct or not??

    • @amit-kumar-yadav
      @amit-kumar-yadav 3 роки тому

      4:20

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

      I also have confusion in sequential statement. He took constant C out, so logically it has to be O(n+n) as a consequence, NO?

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

    complex code examples make the videos in TC&TP

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

    Thank you for this
    Regards from Russia

  • @WitchelsArtSchool
    @WitchelsArtSchool 7 місяців тому +1

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

  • @Rajat-up7fn
    @Rajat-up7fn Рік тому

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

  • @donpikot3d-stl-4dl2combina5

    Interesting mall 2015 game..

  • @bilaalmunir3414
    @bilaalmunir3414 Рік тому

    If i

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

    Great video. Thank you so much! Very helpful

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

    i love u dude.

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

    Artificial intelligence🤖🤖 ka support dilva do phir sari duniya following👌 karegi😇😇😇😇 apney subscribe wale ko 👌👌👌

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

    watch abdul dari algo videos and you will become master

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

    u rock man

  • @sagarchawla4926
    @sagarchawla4926 3 роки тому +3

    Smooth ✨

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

    thank you, very helpful video.

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

    Pls upload some video regarding to gate cs

  • @nanuvishwakarma1935
    @nanuvishwakarma1935 8 місяців тому

    Bewakhoof saratime barbad 😡kardiya

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

    Thanks man

  • @Rubyd777
    @Rubyd777 Рік тому

    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

  • @twinkleshaw693
    @twinkleshaw693 Рік тому +1

    Best video ever watched ❤️

  • @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?

  • @gauria6688
    @gauria6688 Рік тому

    Please make a video on space complexity

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

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

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

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

  • @mahija2873
    @mahija2873 3 роки тому +1

    👏

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

    thank you! very helpful video

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

    dog, the prof explained that in like one every week for 3-4 weeks and i just understood it better here after 8 minutes :D

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

    Thank you for this video.

  • @gaziashfaq1937
    @gaziashfaq1937 5 місяців тому +1

    4:18 should be 2n no?

    • @yolo-ed9dk
      @yolo-ed9dk 4 місяці тому +1

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

  • @floki6939
    @floki6939 3 роки тому +1

    Precise illustration. Thank you

  • @aswink1505
    @aswink1505 4 роки тому +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 2 роки тому

      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

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

    for(int i=0; i

  • @atharva..deshmukh
    @atharva..deshmukh 3 роки тому +2

    Finally, I got something that I wanted!!

  • @infi-tech3808
    @infi-tech3808 8 місяців тому

    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 8 місяців тому +1

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

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

    my computer gets disability benefits everytime I visit ur site, why?

  • @jalalshah2346
    @jalalshah2346 Рік тому

    In Sequencial example why is the time complexity not equal to n+n?

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

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

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

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

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

    Well done
    Very clever and clear explanation
    Many Thanks

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

    Thank you for the resource!

  • @sumantabanerjee9728
    @sumantabanerjee9728 Рік тому

    for(i=0; i

  • @amrutapatil1417
    @amrutapatil1417 3 роки тому +3

    simple and sweet!

  • @RavindraSingh-oe6mk
    @RavindraSingh-oe6mk 4 роки тому +3

    Real decent.

  • @goksucanciftci9663
    @goksucanciftci9663 3 роки тому +1

    very nice

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

    Really to the point and efficient explanation. Kudos

  • @Tauhid214
    @Tauhid214 Рік тому

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

  • @LucusJanny
    @LucusJanny Рік тому

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

  • @meghaadikarinayake7067
    @meghaadikarinayake7067 8 місяців тому +1

    Thank you very much!!!!❤

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

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

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

    Tere toothbrush me salt hai?

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

    Thanks that video was incredible...your incredible!

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

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

  • @LilJollyJoker
    @LilJollyJoker 9 місяців тому +1

    Thank You!