Big O Notation - Code Examples

Поділитися
Вставка
  • Опубліковано 20 лип 2024
  • Instagram: / keep_on_coding
    Merch: teespring.com/stores/keep-on-...
    Patreon: / keeponcoding
    My Gear: amazon.com/shop/keeponcoding
    Discord: / discord
    Twitch: / keeponcoding
    #keeponcoding #tech #programming
  • Наука та технологія

КОМЕНТАРІ • 125

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

    Get the full course here ➡ keeponcoding.io/data-structures

  • @ricardoestrella95
    @ricardoestrella95 3 роки тому +69

    Definitely you're my hero. I just reached this topic in my data structure classes last week and I didn't understand at all until now. I wish you were my teacher. :(

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

    After 4 hours of searching I got this video and finally understood the concept of Big O. Why don't you tube recommend such videos on the top :(

  • @MrElderwand
    @MrElderwand 2 роки тому +15

    What an amazing explanation, hope this will definitely help me in cracking my next set of problems. A big thanks!

  • @saideepesh6036
    @saideepesh6036 3 роки тому +156

    Make a part-2 explaining some harder problems.

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

    Been trying to understand the nested for loops for a while and how they work in bubble sort. Thank you for the explanation.

  • @azkymohamed123
    @azkymohamed123 3 роки тому +22

    Great refresher... Gotta admit, I missed the last one.

  • @sabianzhupa2823
    @sabianzhupa2823 2 роки тому +5

    I have an exam in data structures tomorrow, you really help me a lot , thank u man you are awsome :)

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

    Best video that helped me in my data structures course. Code examples are so helpful!

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

    This was amazing!
    Please please make more.
    You are very good teacher man!

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

    Brilliant explanations. Please cover all the big O's examples & coding exercises of cracking the coding interview.

  • @jorgevasquezang
    @jorgevasquezang 3 роки тому +14

    Great explanation, thanks for sharing!

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

    That was beautiful man, can't thank you enough, keep coding

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

    That is a very useful, dude! Eventually I understood why O(2n) is O(n). And the last example was really tricky. Thank you for the video.

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

    I got more out of this than my last two class sessions of my teacher trying to explain it. THANK YOU

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

    Wonderfully explained the Big 'O' Notation calculation. Thanks

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

    Value acquired, expressing gratitude

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

    came here to learn more about bigO and learned also how to draw out recursive methods! -- they always gave me a hard time; thanks a lot!

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

    Very good explanation on application of BigO to real examples. Liked and subscribed!

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

    What a hero you highlighted on tricks that i wasnt aware of. Much Thanks

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

    The last one was really tricky for me thanks for the video now I'm going to ace the presentation!!!!

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

    Gone through so many articles and tutorials and never understood this bigO.. Simple problems with breakdown really helped understand better.. Thank you.. Can we try some complex example problems please

  • @aponoypi
    @aponoypi 2 дні тому

    learning the big O notation from stanford algorithm class. retired from IT after 35 years. missed programming

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

    Good stuff! Please Make part2- more compliacted and tricky examples!!!

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

    crisp and clear explanation

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

    Simple explanation is the best explanation and u have nailed it

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

    thank you for your share~ best big-o examples!🤩

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

    This is amazing, exactly what I needed.

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

    Best explanations, specially the last one
    Thank you

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

    this is exactly what i needed. Im the type of person who can ONLY learn from examples or else i zone out
    i did find the parts with the recursive tree kind of confusing. Didnt really understand why you did what you did

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

    Thank youuuu I needed these code examples

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

    This is exactly what I needed. Thank you so much!!!! :)

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

    You know I'm starting to think you follow me around in real life. Next week I have an exam that includes a topic like algorithm analysis. Yet here you are....

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

    Good explanation mate, keep it up

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

    Thanks a lot! Solved a lot of problems in my mind :)

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

    it should be noted that println also takes time complexity of O(n) since it has to print every character of a string individually

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

    Bro thank you so much this makes so much sense better explanation then my professor

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

    That was really helpful, deserve a sub and a big thumps up haha

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

    Hey man, this was valuable. Thank you.

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

    Thank you I wasn't sure that I understood Big O

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

    Brilliant, best way to explain is to use examples like this to hit it home.

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

    That last one got me too.

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

    thanks man this really helped me

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

    You're a life saver!!! Thank you so much!

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

    I have my onsite with google in two hours hahaha I'm really glad I saw this

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

    Awesome vid. Thanks
    can u help me with this?
    im making a game for school. a card game in java. im learning a lot of stuff but i dont know much about design patterns. What design patters would you do for a card game?.

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

    You are breaking the rule of teaching but in a good way!

  • @KuldeepSingh-jg9xz
    @KuldeepSingh-jg9xz 2 роки тому +1

    super !!! Keep up good work bro...

  • @troyhackney148
    @troyhackney148 9 місяців тому

    Great video! I was hoping to see O(logn) :)

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

    Great video! But it's scary that some of these can be in an interview

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

    Examples with O log n and O n log n please!

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

    Thank you!

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

    I think the biggest mistake for Big O is that people also forget that we are after the biggest time complexity so we drop the lower time complex values.
    Ex.
    2N *2^N
    With this one 2N is a lower time complexity then 2^N so we don't really care about it and we would just drop it.
    Making the time complexity 2^N

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

      What you say works with sum or multiplication by constants but the complexity here is O(N*2^N) because it is another infinite order bigger than 2^N and you have to take it into account :)

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

    Thanks man!

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

    in the fibonacci sequence, where are you getting the constant 2 from? (2^0, 2^1, 2^3..)?

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

      because at the first level its 1, so 2^0, next level its 2, so 2^1, and next its 2^2, which is 4. He literally explained it in the video

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

    thanks i have been thinking first example is O(n2) and 3rd example is O(n3) thanks for detail !

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

    Can you do tutorial on Java bitwise operators?

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

    Nice video!!

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

    Appreciate the video. That helped.

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

    Awesome!!

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

    Thanks a lot for this video

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

    “the time complexity is based on whether or not the algorithm changes based on the input”.
    if the input doesn’t affect the algorithm then it is constant time. 😮

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

    Thanks for the video

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

    My exam is tomorrow... I didn't really understand this topic until now. Thank you sir.❤

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

    the background is lit :)

  • @178fahimahmed7
    @178fahimahmed7 3 роки тому

    Really helpful , Plz 2nd and 3rd video .

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

    8:38 Recursive Fibonacci sequence... Ouch, my eyes. You should've shown the iterative implementation too, it would've been very beneficial.
    Nevertheless, it was a great video. I'm looking forward to part 2 :-)

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

    Just finishing my coding boot camp and trying to understand this....I know it's big for interviews but I want to have a strong understanding it. New to all this...seems difficult a bit .

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

    Very good explanation, definitely learned from this. 👍🏻

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

    can you plz share some reference/links to better understand last Problem time complexity, thanks in advance

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

      You can reference the Big-O chapter in Cracking the Coding Interview

  • @dharsan.s7937
    @dharsan.s7937 3 роки тому +2

    no O(logn) and O(log logn) it will be tricky with logs

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

    Cool, thanks

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

    Perfect

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

    3:05 i thought you were writing outside my screen

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

    Question: 3:27 - can you please elaborate on why a constant doesn't make much difference? It seems like we would keep it since if n=1000 iterations, then for 2n, that would be 2*1000, which is 2000, as opposed to 1000. Or 20n throughout a program, then won't 20*1000 be MUCH different than just 1000 alone? I likely don't have the mental framework necessary to find this intuitive, so could someone explain it or direct me to a resource? Thanks!

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

      It is very possible for O(N) code to run faster than 0(1) code for specific inputs. Big O just describes the rate of increase.
      For this reason, we drop the constants in runtime. An algorithm that one might have described as 0(2N) is actuallyO(N).
      Many people resist doing this. They will see code that has two (non-nested) for loops and continue this 0(2N). They think they're being more "precise:'They're not.

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

    these teaching videos are really helpful. If you ever needed more ideas for content, you just found it... TEACHING. :) #keeponcoding

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

    In the last example why we don't count how many times the fib will be called?

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

    Please make a vedio on some harder problems!!!

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

    Nice video! I have got a similar Big O video (10 minutes long) which teaches you everything you need for your technical interview.

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

    How about O(log(n))

  • @mikaelaq.purugganan4367
    @mikaelaq.purugganan4367 2 роки тому

    "It's not about writing code anymore" I agree. I really need to grow and mature now. It's not really about 'just' writing a code now. aaah

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

    you are amazing

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

    last example is quite tricky

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

    Me at every examen ... big O :')

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

    👍👍

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

    Awesome video. You said when you have 2^0 to 2^n-1 ... technically is equal to 2^n I need help on the math behind this :).

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

      Note that 2^0 = 2^1 - 1. Now assume 2^0 + 2^1 + 2^2 + ... + 2^(n-2) = 2^(n-1) - 1. Then 2^n - 2 = 2 * (2^(n-1) - 1) = 2 * (2^0 + 2^1 + 2^2 + ... + 2^(n-2)) by our assumption. Therefore, by the rules of exponents 2^n - 2 = 2^1 + 2^2 + 2^3 + ... + 2^(n-1), which implies 2^n - 1 = 1 + 2^1 + 2^2 + 2^3 + ... + 2^(n-1). Since 2^0 = 1, it follows that 2^n - 1 = 2^0 + 2^1 + 2^2 + 2^3 + ... + 2^(n-1). This is called a proof by induction. We proved that if the result is true for (n - 1), then it is also true for n. Additionally, we showed that the results is true for n = 0. Thus when n = 1 we know the result is true for (n - 1) since n - 1 = 0, so it must be true for n = 1 as well. We can continue this logic so that the result is true for any integer n.

  • @904hattrick8
    @904hattrick8 2 роки тому

    I don't know if anyone will see this, but what about finding Big Omega?

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

    O(a*b)? first time i'm seeing this. i don't see anything that resembles it on the wikipedia page for big o or other resources i use. what is it called? ie constant, logarithmic, polynomial, etc. what's the name of O(a*b)?

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

      It is just like n^2... But think of this in this way...if you had to traverse through a matrix with rows and columns equal to n,then time complexity would be n^2 right...but what if the matrix has different rows and columns..say no.of rows=a and no.of columns=b...then total input size is a*b right?? .. because the program has to run a*b times to traverse through the entire matrix...hope you understood this....

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

      You could say it is the general case of a quadratic polynomial

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

    Bik ohhh of n riiiiiii ???
    (imitating my Chinese lecturer from university 5 years ago in computational methods module).

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

    I doubt about last one

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

    1:20 I am viewing in 1.75x speed

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

    would have been nice if u just retyped that code and then put it on screen instead of a low resolution photo but otherwise good

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

    14:04
    It's 2^n x 1/2
    Not 2^n - 1
    But it doesn't matter

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

      2^n x 1/2 = 2^n x 2^(-1) = 2^(n-1)

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

      That is wrong. It is indeed 2^n - 1 (no parenthesis), you need to use the geometric sum, look it up ;)

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

    Is this pseudo code?

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

    Need +1 Level problems

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

    I wish you did Python. I aVOID java like the plague. I bet your channel would blow up if you did :). I think the way you go through stuff in your examples gives allot more insight and is more absorbable(

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

    Dont you all think its crazy how you get good videos like this, and some (4) twat(s) who click dislike. I mean yeah, maybe they just dislike the video sure, but why click it, so toxic.. I mean fair enough he could make money via the videos but they are also massively helping potentially millions of people, if they are interested.

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

      I appreciate the video anyway

  • @mohammad-karbalaee
    @mohammad-karbalaee 2 роки тому

    Man, you look Iranian!

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

    public class StringStack
    {
    private String[] values;
    public StringStack(int maxSize)
    { values = new String[maxSize]; }
    public int size()
    {
    int count = 0;
    for(int in=0; in < values.length; in++)
    if(values[in] != null)
    count++;

    return count;
    }

    public void push(String data)
    {
    int top=0;
    if(size() < values.length)
    {
    top = size();
    values[top] = data;
    }
    }
    public String pop()
    {
    int top = size()-1;
    String data = "";

    data = values[top];
    values[top] = null;

    return data;
    }
    }
    What will be the growth function and Big o notation of size(),push(),pop()?

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

    O