The Ultimate Big O Notation Tutorial (Time & Space Complexity For Algorithms)

Поділитися
Вставка
  • Опубліковано 20 лип 2024
  • Free DSA Mini-Course: backtobackswe.com
    Try Our Full Platform: backtobackswe.com/pricing
    📹 Intuitive Video Explanations
    🏃 Run Code As You Learn
    💾 Save Progress
    ❓New Unseen Questions
    🔎 Get All Solutions
    Big O notation is very important for software engineering interviews. It really shows your capacity to critically think like an engineer.
    The question that Big O answers is this: “how does the speed of this algorithm SCALE as the input to the system SCALES." That is it. It is a question of scale, not precise numbers. This is why we drop constants.
    More precisely it is saying that if we give this algorithm VERY LARGE input, what will the UPPER BOUND of the runtime be? What will that tail behaviour be dictated by?
    We say O(N) but what is n? Never say "n" without knowing what n is. Know what n is. Is it the string length? Is it the array length? Is it the number of nodes in the tree? What is it?
    When we talk Big Oh we normally calculate the worst case and state that as the time complexity, hence giving it an upper bound that it cannot cross and hugs closely.
    Space is calculated just like time complexity, do not be confused, but the question shifts to: “how does the space usage of this algorithm SCALE as the input to the system SCALES."
    I know you want to memorize the "shape" and "pattern" of certain code but do not do this. Understand what is happening.
    You will actually need to know what is going on to know them in their worst, average, and best case (although we care most about the average and worst).
    It will help you find the optimal solution if you know the best complexity you can reach, it implies a method you can use that famously has that time complexity.
    If you hear log(n) you know that the solution will use binary search or some algorithm that halves the input somehow...
    In an interview you can't guess and that is the whole point of this, you will be put on the spot and have to explain. Explain confidently, be precise.
    If you don't understand why something has the complexity it has don't be ok with not understanding, understand it, find out why and really think about what is happening. This will make you a stronger thinker and be able to tackle harder and harder problems.
    Also, recursive and backtracking complexities are harder to calculate so just practice, those come with time and experience. Don't be discouraged...
    +++++++++++++++++++++++++++++++++++++++++++++++++++
    HackerRank: / @hackerrankofficial
    Tuschar Roy: / tusharroy2525
    GeeksForGeeks: / @geeksforgeeksvideos
    Jarvis Johnson: / vsympathyv
    Success In Tech: / @successintech
  • Наука та технологія

КОМЕНТАРІ • 291

  • @JasonOgasian
    @JasonOgasian 4 роки тому +156

    The way the camera moves and the speaker is acting makes it feel like someone is about to bust in and erase all his whiteboards at any moment 😂
    Great video!

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому +9

      Hahahaha that was the case. 2nd video I ever did

    • @naskavian7041
      @naskavian7041 4 роки тому +14

      This is the Blair Witch Project of Big O :)

  • @geraldcerna516
    @geraldcerna516 3 роки тому +72

    I think this is one of those videos that will really keep you up rather than making you want to go to sleep. It's not boring. And the explanations are so lit.

  • @bakor-org
    @bakor-org 5 років тому +56

    Simply the best explanation on the whole internet. I really like how he points out what he has done wrong in the past so we don't do the same. Thank you. :)

  • @BackToBackSWE
    @BackToBackSWE  5 років тому +43

    Table Of Contents: (I want to redo this video, the video is overexposed in lighting)
    Messing Around 0:00 - 0:17
    Big O Introduction 0:17 - 0:43
    O(n^2 )Bounding Example 0:43 - 1:33
    Upper Bounding 1:33 - 1:51
    The O(n) Mistake 1:51 - 2:38
    Notating min() & max() 2:38 - 2:56
    O(1) "Constant time" 3:07 - 3:46
    O(log(n)) 3:46 - 5:43
    O(n) "Linear time" 5:43 - 6:30
    O(n * log(n)) 6:32 - 8:09
    O(n^2) 8:09 - 9:09
    O(2^n) "Exponential time" 9:09 - 9:40
    O(n!) "n-factorial" 9:40 - 10:55
    Considering Tradeoffs 11:01 - 11:34
    Why To Optimize Time 11:34 - 11:58
    Space Complexity 12:02 - 14:38
    DO. NOT. GUESS. 14:44 - 15:40
    Leveraging Our Complexities 15:40 - 16:30
    Wrap Up 16:30 - 16:59
    HUGE IDEA. Time complexity must be at least the space complexity. If you deduce a complexity and this does not happen then something is wrong. This is because to use space we must use time (space is tightly bound to the time that it takes to use it). Due to this relationship, space ALWAYS has at least a loose lower bound on time if not very close.
    I will make a part 2 to this video to expand with nuances like this in complexity theory.

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

      Back To Back SWE excellent explanation God bless🙏🏼

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

      thanks

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

    THE BEST, CLEAREST BIG-O VIDEO BREAKDOWN YOU WILL FIND ON UA-cam!!!
    Thank you so much for making this, it has really helped me understand things better!

  • @brAzzi64
    @brAzzi64 4 роки тому +81

    Never seen that many whiteboards before.

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

    This is the kind of video by which people like me, who are introducing to this world, will buy access to your platform, never stop making them, excellent explanation bro, I finally understood this concept.

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

    Dude, this video introduction to Big O is what I needed! Blessing from the gods!

  • @aloewishus
    @aloewishus Рік тому +2

    A tripod is a portable three-legged frame or stand used as a platform for supporting the weight and maintaining the stability of some other object. In photography, a tripod is used to support, stabilize and elevate a camera, a flash unit, or other photographic equipment. Tripods are available in various sizes and materials and can be purchased from many retailers such as Amazon and Best Buy.

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

      🤣exactly my feeling right now while suffering from a headache after watching this.

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

    Love your energy bro! Thank you for your great explanations to so many concepts

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

    Finally an introduction to Big O that actually makes sense!! Thank you.

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

    thank you soooo much!!! seeing you so passionately talking about this encourages me to learn more about it. great great work

  • @lien-chinwei4815
    @lien-chinwei4815 5 років тому +3

    Thank you for the first 11 min presenting solid examples related to each big Oh. Fantastic work.

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

    Thank you! It helps me (a beginner) get a brief understanding of all those concepts in such an easy way.

  • @lazymacs2823
    @lazymacs2823 3 роки тому +12

    Nerd: "you can't buy time"
    RTX3090: allow me to introduce myself

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

    This video is one of the most complete and engaging i have seen

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

    Thanks for the tutorial - thumbs-up given. The most important comment you made was toward the end of the video: it is impressive to state the space-time complexity. For interviews, it always helps to create an air of authority, regardless of how practical it would be to write production code that relies on the what you are being tested, which in all likelihood you never will :)

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

    I just love these videos, the presentation style really resonates with me. Great job.

  • @pavithravenkatesan7216
    @pavithravenkatesan7216 5 років тому +4

    Very simple to understand. The teaching method is unique and efficient :) Thanks a lot for doing this :)

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

    From the bottom of my heart, thank you so much for the gold knowledge

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

      Thank you, glad you liked it 😀
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends 😀

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

    Ben, you are the MAN. I wish I could attend a Bootcamp taught entirely by you. I go to Columbia and it's extremely difficult to keep up with the speed at which the curriculum is taught. Your videos really help create a baseline of understanding.

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

      haha, I am but a man, a lot of videos left to make

    • @user-gp8fr1nd3w
      @user-gp8fr1nd3w 4 роки тому

      oh my god same I got to Columbia now. Were you doing data structures?

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

    Wow bro you really kill the n * log (n) part. Thank you!

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

    Great video❣️
    Helped me alot
    I have watched many videos on big O notation but no1 has ever explained it in this easy and simple manner
    Great job sir👍❣️

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

    wow! It is the ultimate Big O notation tutorial. Awesome work, please keep doing the same. Thanks a lot.

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

    Out of the ones I checked out, this actually explains WHAT the concept is before jumping into some arbitrary code. Thanks!

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

      Glad to hear that

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

      Subscribe to our DSA course with a flat 30% discount for some amazing content b2bswe.co/3HhvIlV

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

    Thanks for making this interesting presentation! I love your energy!

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

    Again, I love these videos. Thank you very much!

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

    Your videos have been really helpful to me and it seems like some of the things that trip me up sometimes also tripped you up as well.

  • @VictorGarcia-si8wy
    @VictorGarcia-si8wy 2 роки тому

    "We can buy memory, but we can't buy more time." That's some deep stuff right there.

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

    Such a great and helpful video. You explained this sos well

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

    I love this channel. I wish I could like videos multiple times haha.

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

    Great video it really clarifies Big O in relation to the search types

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

    Thanks for uploading videos like this!

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

    This is the best explanation! thank you so much!

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

    Thanks you
    My all doubt about algorithmic complexity is now cleared🙂

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

    Subscribed you did a good job explaining the material thanks

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

    To be honest, this is by far the best one!
    now please make a vid where you go through actual code, I am talking about actual code, not some rubbish nested for loops just to print the name or number. That will help in practically applying these concepts.

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

    Love this guy! Keep it up!

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

    Great explanation! Thank you.

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

    Prepping for Fall hiring season. Botta watch/learn from your videos

  • @moddatrucka
    @moddatrucka 4 роки тому +30

    Good Explanation! A camera tripod would have helped though :)

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому +17

      this was my second video ever jeez guys

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

    Amazing explanation!! great job!!

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

    very good explanation, watch your video everyday on my train to office is my habits now.

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

    Watching this was fun. Thank you!

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

      Thank You, Glad you liked it.
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends :)

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

    amazing energy and well explained. huge thanks!

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

      Thank you, glad you liked it 😀
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends 😀

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

    Cool! Great job, thank you!

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

    Is the triangular work @ 8:45 a graph of number of comparisons (y) vs index (x) ? That's how you would get a triangle imo. Also from what i know about work (from physics) work is calculates as the area under the graph. Since it is a right angle triangle, we can calculate the area as 1/2 * base * height which equals n^2/2 which then gives us the complexity of n^2.

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

    What an amazing lad. Hope he reaches heights. thanks for the clear explanation

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

      Thank you, appreciate it 😄 Also check out our Free 5 Day DSA Interview Prep Mini-Course - backtobackswe.com/ 🎉

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

    Great video, interview bytes at last on (15:43) was really impressive..

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

    Clear and precise. If I get an A on my final tomorrow, I'll dedicate it to you.

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

    Thanks for saving my life!

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

    That was AWESOME ✌🏻👨‍💻🔥🔥🔥🔥

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

    Holy shit. It makes sense. Didn’t expect that. Thanks lol.

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

    My god im so glad I found this channel.

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

    very helpful thanks for making this video.

  • @emekatimothyiloba699
    @emekatimothyiloba699 5 місяців тому

    Thanks. You are a great teacher

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

    Thanks for this video!

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

    could u make another video with a detailed explanation for the space complexity
    ?
    Thanks, Sai

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

    Amazing content!

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

    Very good explanation...unlike other videos I can relate to ur teaching cause u stress on the points which u urself found difficult to understand

  • @123Azns
    @123Azns 5 років тому +4

    amazing!!! Better than stackoverflow, and professors that taught me.

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

      haha, I'm working on redoing this video. It is badly exposed.

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

      Back To Back SWE hahah could you give more examples in the new vid?

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

      @@123Azns yeah. it will be amazing.

  • @user-vq6yi7se2r
    @user-vq6yi7se2r 3 роки тому

    Great one!!!!!!!!!

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

    Great explanation, thank you

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

    The clarity!

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

    This is the best video on big Oh.. I also like ur style bro

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

    I am glad you didnt use a potato to record this, instead you opted for a bowl of jello. I was dizzy at times, but overall. Great content!

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

    Sir, can we say O(log(n)) means "half of n or half of the common runtime" of the algorithm? So, if anyone asks that what is O(n*log(n)), we can say its O(n*(n*1/2)) which is O(1/2*n^2) and drop the constant which becomes O(n^2)?? Means O(n*log(n)) = O(n^2)???

  • @abdullahclementabdulshekur6736

    very clear and on point

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

      Happy Holidays! Really glad to help 🎉 Do you know about the BacktoBackSWE 5 Day Free Mini Course? Check it out here - backtobackswe.com/

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

    Hi mate, have you seen the Berlekamp-Massey algorithm? The time complexity is defined as O(n^2), where n is the input data. Can I asume the same space complexity?

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

      No I haven't :/

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

      No worries. I was doing this analysis and basically the time complexity can be calculated according to biggest tasks involved, where n^2 steps are taken. When calculating the space complexity is a different story because, I was mainly considered the vectors that I used, in my case 4.

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

    the best explanation of big O thanks! camera wasn't stable enough :/

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

    thank you!

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

    This man doesn't use dots for bullet points he uses transmutation circles

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

    Thanks!

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

    5:59 really helped things click for me, thanks!

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

    I just felt like i watched video at 2x speed. so much useful content in so less time.

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

    Studying the behavior and complexity of algorithm can be super confusing, especially considering mathematics is involved and not all developers are well schooled beyond basic algebra.
    This is a pretty good introduction in my opinion, to get your head around the basics.

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

    Simplest explanation of Big O period.

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

    Thank you!

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

    thanks a lot brother.......n im your new subscriber!

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

    Nice job!

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

    dude i love you

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

    revisiting thanks !!

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

    This video is GOATED

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

    It forms what it look like a triangle--> Didn't understand this point for O(n2), how it formed a triangle?

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

    what year are you? great video btw!

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

    Subscribed ❣️✨

  • @HN-if9qt
    @HN-if9qt 4 роки тому

    At 8:34, how did you go from 3 comparisons of an array to form a triangle?

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

    Thanks for share it

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

    Talking about time complexity, it's great to watch your video and do some further study on it because it's almost a basic skill during interviews. At least from my previous interview experience, both facebook and bloomberg interviewers were willing to know if I could accurately state time & space complexity. Highly recommend Cracking the Code Interview Chapter VI. Big O, where you would deeply understand the practical ways of solving this issue.
    The answer here clearly explained how we should calculate time complexity for the recursion calls: stackoverflow.com/questions/43298938/space-complexity-of-recursive-function

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

      Nice, thank you for sharing.

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

      new WhizBangArray(n) # picks the best container type for n

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

      "They don't OOP!?"

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

      Come on lazy iterator! 😜

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

      I got the job!

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

    wonderful!

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

      Thank you, glad you liked it 😀
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends 😀

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

    Doesnt that make nlogn then 8 times 3 making it 24 as complexity????

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

    greate explanation

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

    In O(n) complexity, when it is 3*n the linear graph line doesn't become sterper but shifts up 3 units.
    Great explanation!

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

      What? Can you timestamp it? Multiplication by a constant factor makes a line steeper. Shifting up is addition.

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

      @@BackToBackSWE Yeah! Sorry, I was just confused between multiplication and addition on functions. You again made it clear. Thanks alot!

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

    thanks a lot!!!♥

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

    Awesome video! I got very dizzy watching it though :( still thanks the content is great!!

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

    8:08 woah woah... no need to get personal

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

      old video - sorry if I said something weird

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

      @@BackToBackSWE lmao no u just said an O notation of n^2 was innefficient
      i cant do better >:

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

    Very good! I just wish the video footage wasn't shaky!

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

      Glad it was helpful and sorry about the footage! 😄 Also check out our FREE DSA Interview Prep Mini-Course - backtobackswe.com/ 🎉

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

    love you man...

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

    Bruh I need more practice on this! What can I do?

  • @AshishSingh-753
    @AshishSingh-753 4 роки тому +1

    Hey your are best content creator