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 - Наука та технологія
Get the full course here ➡ keeponcoding.io/data-structures
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. :(
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 :(
What an amazing explanation, hope this will definitely help me in cracking my next set of problems. A big thanks!
Make a part-2 explaining some harder problems.
I second this!
@@shreephadke3679 Same
I agree, these are common examples. Good stuff tho
+1
Been trying to understand the nested for loops for a while and how they work in bubble sort. Thank you for the explanation.
Great refresher... Gotta admit, I missed the last one.
I have an exam in data structures tomorrow, you really help me a lot , thank u man you are awsome :)
Best video that helped me in my data structures course. Code examples are so helpful!
This was amazing!
Please please make more.
You are very good teacher man!
Brilliant explanations. Please cover all the big O's examples & coding exercises of cracking the coding interview.
Great explanation, thanks for sharing!
That was beautiful man, can't thank you enough, keep coding
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.
haha yea this is happened to me
I got more out of this than my last two class sessions of my teacher trying to explain it. THANK YOU
Wonderfully explained the Big 'O' Notation calculation. Thanks
Value acquired, expressing gratitude
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!
Very good explanation on application of BigO to real examples. Liked and subscribed!
What a hero you highlighted on tricks that i wasnt aware of. Much Thanks
The last one was really tricky for me thanks for the video now I'm going to ace the presentation!!!!
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
learning the big O notation from stanford algorithm class. retired from IT after 35 years. missed programming
Good stuff! Please Make part2- more compliacted and tricky examples!!!
crisp and clear explanation
Simple explanation is the best explanation and u have nailed it
thank you for your share~ best big-o examples!🤩
This is amazing, exactly what I needed.
Best explanations, specially the last one
Thank you
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
Thank youuuu I needed these code examples
This is exactly what I needed. Thank you so much!!!! :)
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....
Good explanation mate, keep it up
Thanks a lot! Solved a lot of problems in my mind :)
it should be noted that println also takes time complexity of O(n) since it has to print every character of a string individually
Bro thank you so much this makes so much sense better explanation then my professor
That was really helpful, deserve a sub and a big thumps up haha
Hey man, this was valuable. Thank you.
Thank you I wasn't sure that I understood Big O
Brilliant, best way to explain is to use examples like this to hit it home.
That last one got me too.
thanks man this really helped me
You're a life saver!!! Thank you so much!
I have my onsite with google in two hours hahaha I'm really glad I saw this
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?.
You are breaking the rule of teaching but in a good way!
super !!! Keep up good work bro...
Great video! I was hoping to see O(logn) :)
Great video! But it's scary that some of these can be in an interview
Examples with O log n and O n log n please!
Thank you!
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
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 :)
Thanks man!
in the fibonacci sequence, where are you getting the constant 2 from? (2^0, 2^1, 2^3..)?
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
thanks i have been thinking first example is O(n2) and 3rd example is O(n3) thanks for detail !
Glad to help!
Can you do tutorial on Java bitwise operators?
Nice video!!
Appreciate the video. That helped.
Awesome!!
Thanks a lot for this video
“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. 😮
Thanks for the video
My exam is tomorrow... I didn't really understand this topic until now. Thank you sir.❤
the background is lit :)
Really helpful , Plz 2nd and 3rd video .
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 :-)
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 .
Very good explanation, definitely learned from this. 👍🏻
can you plz share some reference/links to better understand last Problem time complexity, thanks in advance
You can reference the Big-O chapter in Cracking the Coding Interview
no O(logn) and O(log logn) it will be tricky with logs
Cool, thanks
Perfect
3:05 i thought you were writing outside my screen
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!
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.
these teaching videos are really helpful. If you ever needed more ideas for content, you just found it... TEACHING. :) #keeponcoding
In the last example why we don't count how many times the fib will be called?
Please make a vedio on some harder problems!!!
Nice video! I have got a similar Big O video (10 minutes long) which teaches you everything you need for your technical interview.
How about O(log(n))
"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
you are amazing
last example is quite tricky
Me at every examen ... big O :')
👍👍
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 :).
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.
I don't know if anyone will see this, but what about finding Big Omega?
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)?
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....
You could say it is the general case of a quadratic polynomial
Bik ohhh of n riiiiiii ???
(imitating my Chinese lecturer from university 5 years ago in computational methods module).
I doubt about last one
1:20 I am viewing in 1.75x speed
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
14:04
It's 2^n x 1/2
Not 2^n - 1
But it doesn't matter
2^n x 1/2 = 2^n x 2^(-1) = 2^(n-1)
That is wrong. It is indeed 2^n - 1 (no parenthesis), you need to use the geometric sum, look it up ;)
Is this pseudo code?
Need +1 Level problems
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(
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.
I appreciate the video anyway
Man, you look Iranian!
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()?
O