Placeholder Image

字幕表 動画を再生する

  • the primary purpose is video.

  • Syria's gonna be for analyzing not just algorithms, but also primarily pieces that are gonna be, you know, let's not just in computer science, but also for interviews.

  • And then we're gonna be starting up to something called the Big O so really quickly we're gonna be doing this all in the Jupiter notebook, primarily because it's not that difficult enough that we have to use pi charm.

  • And it's also a little bit cleaner looking.

  • So I analyzed algorithms in the first place when algorithm don't get never spoke a word.

  • It's just procedure or formula for solving a problem.

  • Some of them are so useful that we've given them names like Merge sort of bubbles sort et cetera.

  • And then one of the important things were gonna come across you can see very quickly is how can we compare the algorithms, you know, which is better, and by better it's gonna be relative term to the task at hand.

  • But typically there's gonna be two avenues for analyzing if an algorithm is better than another and that's going to be either by speed, time of completion on, that's gonna go into its scalability.

  • and also memory, its size, allotment and its requirements and so forth.

  • So really quick somethin.

  • So in this 1st 2nd Cody said, imagine keeping dysfunction.

  • This was just to finding a function called some of one.

  • It's taking one argument, and so then we have final Sum equal zero.

  • So we have an object Final sum ever, given the assignment of zero, it says for X and range and plus one.

  • So we have a for loop here.

  • Range is gonna be whatever define it for in terms of the ends and plus one equals final, some equals fun, awesome plus X And then we're returning the final sum.

  • So I'm just going thio shift, enter.

  • So that actually loads into the Jupiter notebook.

  • And then I have hear someone calling five of the argument.

  • You'll see that it prints up 15.

  • So what this did was with the object having the argument of five and the formula essentially the algorithm for this was for X and rain.

  • So for each number in range and plus one and was five, so in six you remember for range started zero.

  • So we had to add that one of wanted to really get five actual numbers.

  • So zero is not gonna have any implication for addition on the final sum of starting at zero.

  • So if we did five times four, we're gonna have 99 plus three is 12.

  • 12 plus two is 14 14 plus one is 15.

  • So, of course we got the answer to be 15th.

  • That's appropriate.

  • So let's see what this is all going towards anyway.

  • So, again, this is, uh, function that we've created to finding a sum of one.

  • And we got a result of 15 when Ann Nichols five.

  • I'm going to go down here and now for this one.

  • And let's assume that you gave me this function.

  • You called it some to also taking only one argument of end and you instead of doing a four low Penis returning and times and plus one divided by two.

  • And let's see what we get.

  • I'm gonna shift into through that as well and same argument of five, and we also get 15 same exact function.

  • If you actually did this math by hand, of course, Pem dos is gonna hold place, so parentheses.

  • You're always gonna be first, so you would have had five plus one, which is going to be 66 times five is 30 35 by two is going to be 15.

  • So what's the point of this?

  • Essential?

  • We got the same answer with two very different functions that's essential.

  • That that's that's the point of this.

  • So this is my function I created, and this is the one that you created, both getting the same result.

  • So function one is someone's gonna complain about that, right?

  • Nephew.

  • So function of someone.

  • It's using a four loop to interpret it curative Lee at across our range of plus one.

  • So here's our four lope and we're just iterating over the range that was dictated by the input end.

  • And it's adding across that range.

  • Number two is simply just taking advantage of a formula.

  • It's a formula bases off a problem.

  • Both of these are technically algorithms because remember the algorithm is this a procedure or formula for solving a problem?

  • So we're solving a problem, and here was something problem.

  • This is just more formula base, and this is an iterated four loop that we're running.

  • So now the question is gonna come.

  • How do we compare them?

  • How do we determine whose function is better mine or yours?

  • And that's gonna come relative to what it is you're trying to determine.

  • Defines is better.

  • So we have to objectively be able to compare them.

  • And the two places.

  • The two avenues I mentioned before that we could do the four is memory, which is space allocation within the computer or the time to run that much time it's gonna take to actually run that software.

  • So we're going to use built in magic magic commands in the note.

  • The Jupiter notebook.

  • Sometimes I might call it I Python.

  • That's the old connotation.

  • Expect that it was just Python and now it's multiple languages.

  • So they called Jupiter Notebook.

  • So first of this, his is a magic command using the percent side time it and I'm saying, I want you to time it for the sum of one function with an end of 100.

  • So I'm gonna shift into that and right now what it's doing, it's doing that for loop.

  • So there we go.

  • We got 100,000 loops.

  • Best of 33.7 for microseconds, poor loop, and then I'm going to do the same magic time at some two with 100 z input.

  • And then d'oh, it's doing the computation Now.

  • Took a second there, depending on your computer is going to determine if it happens faster or slower.

  • So for the same end of 100 which we know that they're gonna give me the same answer.

  • And you can ignore this for right now that's just talking about cashing best of 344.

  • But now this is nanoseconds.

  • So and I put down here just for those who may not know Micro, which is up top here is 10 to the minus six.

  • Nana was 10 to the minus nine.

  • So that means Nano is a smaller number by a factor of three.

  • And so this is faster.

  • So in the two different functions, we had function of someone of function of some too for the same end.

  • My algorithm, your algorithm, your algorithm was a function was much, much faster.

  • You were on nanoseconds.

  • I was on microseconds for time of completion.

  • But now that's not necessarily the end Albil because that's the time of completion on my computer, your computer, the time of completion might be faster.

  • Slower now, of course.

  • Granted, we're talking micro nano seconds.

  • That difference can get very large, and we have much larger inputs to deal with, and some systems will be faster or slower.

  • But at the end of the day, regardless, four lives here was gonna be slower, and that's what we try to avoid them, and especially machine and artificial intelligence.

  • So now that we have that, um, I have your smallest number is obviously faster, we know that.

  • So we can't rely on just time to run, because again, all computers, a different hardware is gonna be different somewhere fast and others.

  • We want this to be hardware independent, and that's one of the big takeaways because, as you know, hardware is constantly changing.

  • So how come we objectively determine if one function is faster or slower, or rather, is better or worse than that of the function?

  • If we can't use the time parameter per se because of the objective nature of different futures?

  • Well, that's where the big O comes in.

  • So the big O is a way that we can objectively compared the efficiency of those two algorithms.

  • So we're gonna get the number of assignments of each algorithm.

  • There's some key phrases here, but we're gonna run through this.

  • But I want you to be cognitive.

  • So we're gonna compare the number of assignments if you that each outgrow them.

  • Makes four has to undergo.

  • So for the original someone function, it's I'm going to read this and I'll go back up to it and show you what I mean.

  • The original someone functional.

  • Corrina, Simon End.

  • Plus one times we can see this from the range based function.

  • This meeting will assign the final some variable M plus one times we convince it for the problem of and size.

  • In this case, just a number end.

  • This function will take one plus and steps, and this one's gonna become meaningless.

  • So going back up to function number one or someone what it's saying here is that the allocation that this is going to that this is gonna require in terms of an assignment, it's only in the assignment.

  • Is this so if my end is one, it's gonna have to assignments is gonna have the assignment of one and then the assignment of zero, because again, we're dealing with indexing was here on its ranging If my aunt is three and I'm gonna have four it's going to be the assignments gonna be still be and plus one because whatever.

  • Then it's gonna be it's gonna be linear is the point that we're gonna be looking at here.

  • But there's only one assignment that's necessarily going on within this and a final first assignment is zero and the Met assignments gonna keep changing based on an order of end.

  • The end notation allows us to compare the solutions and algorithms relative to the size of the problem.

  • So since someone 10 and some one of 100,000 we take very different times to run.

  • But using the same algorithm, we can also note that end grows very large.

  • The plus one doesn't have much effect.

  • That's almost referring before some of these constant numbers.

  • Essentially, when you start to get the numbers like infinity or if you're familiar with calculus, make it's the limits.

  • The constance.

  • The constant numbers just drop off.

  • They no longer have a real effect on the on the ultimate coating.

  • You'll see that in just a minute.

  • So how can we how Can we still quantify this?

  • How can we still compare the functions?

  • And that's where big O notation it comes in.

  • It's describing how quickly the runtime will grow relative to the input as the implicates arbitrarily large.

  • Um, And again, this is how we're gonna measure one algorithm over another or even one you know, different coding aspects, like using numb pine.

  • An instance where so it could be active a lot faster than if you're using a built in list sequence and python using data frames instead else utilizing pandas.

  • So it's all the big O when I want you to put your head.

  • It's how well can it scale as the data increases?

  • Because Big O has a lot to do with scaling.

  • That's Callen can either be in time or can be in memory.

  • So we're comparing how quickly the runtime is going to grow, not the exact run times since those are gonna depend on the hardware.

  • So at least this way I could know it doesn't matter the system.

  • If I have two different algorithms, I can tell you that one algorithm is going to have some element of time, and this other algorithm is going to have a comparatively different relative amount of time.

  • Regardless of the hardware, one's gonna be faster than the other.

  • If I can see the code and I do the big O notation So it's the end gets arbitrarily large.

  • We're only were about the terms that we grow.

  • The fastest is that gets large.

  • So essentially you're looking at an algorithm.

  • And if you're trying Thio, which we're gonna get down to just a second, you can determine which element in that code is the driving factor.

  • Which one?

  • Still, which one's gonna actually impose the limiting behavior on the execution of that code?

  • Well, that's gonna be your big go on.

  • Everything else essentially gonna drop off and in math, that's this.

  • This idea is called asymptomatic analysis, which is just describing living in behavior.

  • So it's kind of looking at the whole picture, So we're gonna get to this guy in a second.

  • So a synthetic analysis is looking at this return here and pretty much saying who is the limiting factor in here?

  • Who's gonna limit what my end is going to be able to?

  • D'oh, Which one of these guys is gonna mess with scaling the most or of the most impact of the least impact on scaling.

  • Then you can go from there.

  • So again, which part of the album has the greatest effect on the final answer?

  • Which part of the Argo is the real bottleneck, which is the limiting factor?

  • As for this intact, someone could be said to be This is the notation here.

  • So they say, This is a big O of and Tom Cruise liner with input size, so let's go back up to someone.

  • So what we're saying is again, this was Big O.

  • If I was to do it in that notation, it was essentially just this.

  • But again, the Big O's that's that was going to be the objective nature of big a notation for this linear event.

  • But the one as N gets larger and larger and larger, this number one falls off.

  • So when N is Juan or fiber 10 he'll see an impact of the one.

  • But even just getting to 100 then 1000 this one becomes meaningless.

  • So we end up with the big O notation and and again, this is not supposed to make a lot of sense.

  • You just yet.

  • It will as we get further down when you can see the stuff in a graphical analysis.

  • So I wanted to bring this idea again of describing living behavior from a synthetic analysis standpoint.

  • So here it is, created a function called bingo with one argument, and and this is simply just returning 45 times and cubed plus 20 times and squared plus 19.

  • And if I call Big O with an end of one, I'm just gonna get 84.

  • If you wanted to do that mouthy absolutely.

  • Can just Don't forget you have to do our operations.

  • So the it's one cubed times 45 then one square times 20 and then plus the 19 they had it all together.

  • So if we just did one of the variable, we're gonna get 84.

  • So what happens if I do?

  • Just to We ought to make a joke.

  • Made it 4 to 4 59 So what?

  • I want you to see if you're just looking at these two here.

  • All we did was change end by a factor of one correct and yet our results substantial change.

  • But the point is that this 19?

  • It had an effect here, even if from percentage standpoint, when N is 1 19 had in effect.

  • But when N is just to the 19 is pretty much becoming meaningless.

  • So this would not contribute to our computational intensive time because it's not really having any kind of an overall effect.

  • It's not limiting how we're progressing in terms of scaling.

  • So what happens if we go to a bigger of 10?

  • So now we're up to 47,000.

  • So now, looking packet R r p c, I'm going to get to the second, going just from 1 to 2 to 10.

  • The 19 we already know is pretty much out of the picture.

  • 19 is not gonna make a big difference here in terms of computational intensive requirements.

  • So then the question to come down, which one of these is it?

  • I'll tell you right now we can ignore the constants, never look a constant numbers.

  • So we're really focusing on its and cubed and n squared.

  • And they were pretty much saying which one of these is gonna be the bottleneck?

  • Which one of these that the limiting factor for this particular function well, it could be seen that the 19 is and how much weight anymore we came to the conclusion or reading the 20 and squared in this case is 2000.

  • So out of 47,000 if we took out 2000 we're not that far off.

  • 45,000 if we go to the 19.

  • So again, 92,000 is not that big of a difference.

  • So we can pretty much conclude that the n squared it's not going to the living factor within this particular function.

  • So then we have the again the constant 45 don't care about per se, but the end cubed ideo.

  • And with our end of 10 it's gonna be 45,000.

  • So 45,000 and 47,000 have much more of a percentage based impact on its outcome of the performance of the calculation of that particular function.

  • So in this function, this entire piece here, you would say this is essentially gonna be your controlling big.

  • Oh, this is what's going to determine your scalability.

  • This is what's gonna terminate leavening factor.

  • This is what's going to determine who's gonna have the biggest bang for your buck within your function and which is gonna require the most computational time in your system.

  • So this part of the Argo that relies a lot to do the announcer as the date of scales, it's not gonna be the 45 again.

  • Here we have.

  • It's not me the 45 but it's gonna be the n cubed.

  • So this algorithm has an order of n cubed.

  • So it's a big oh, whoops a daisy without this in here.

  • So this is gonna be a big O on and then we'll just keep it this way.

  • That's what that would be the order for this particular function.

  • Now what I have here, this is just a big old complexity chart.

  • We have horrible, bad, fair, good, Excellent.

  • So what?

  • This is showing that these different elements and then we have the operations.

  • So if your function has a big o of one or a big old log of N which is still gonna be quite Lennier Ah, you can see that our performance here as end grows ends getting bigger, bigger, bigger, bigger, bigger, bigger.

  • And this is tthe e the operations, the amount of operation would be performed.

  • You can see that we're in the excellent range here.

  • Excellent and good range for those particular big O's.

  • But then once we start to get to this is over the function of end, which is very much like our our original function that we did someone you can see we're an affair from a performance standpoint is and grows.

  • So too does the time.

  • But the complexity of the nature that is not is not obscene.

  • And then we start to get bad.

  • Once we get thio Big o and log in.

  • And then we're getting into the horrible territory when and is squared, um, to the exponent.

  • And over here you would have n cubed and cubed is even worse than two to the end.

  • In terms of operational performance, this is something you can memorize.

  • I have two different charts here.

  • You can look at how you can go through.

  • So for the big go big go of one that's called a constant, which is exactly what we have is gonna be whatever.

  • If it's a you know, Big O's 10 then it's gonna be 10.

  • That's gonna be the constant number.

  • Lagoven logarithmic and linear.

  • We saw that lager then, and the constant and the oh, and linear, they're pretty fair in terms of your elements grocer and grows your operate operational computation intensive doesn't grow substantially that it's still it's still considered a valid function of valid formula you're gonna be using.

  • And then we go and log and log Linear, we're getting into that.

  • What was that?

  • Fair?

  • No bad.

  • So we left fair were in bed territory already just because of the amount of computational intensive that is putting on the system regardless of your system.

  • And then we have n squared and to the third.

  • And then we have to win in terms of quality cubic exponential.

  • So this is just thinks you can start to memorizing.

  • Where you're gonna be doing is this is what we're looking at when we're determining our function.

  • Where does it fall in terms of the big Oh, this is a more broken down version of the Big O, showing her one lakh of Locke and Locke out and so on, so forth going and what their actual frank, functional name is gonna be called.

  • If you were ever describing it, okay, what I have here.

  • This code I'm not gonna go through per se.

  • I'm just using this from demonstration purpose.

  • But more important, log importing dump.

  • I imported my plot live.

  • I'm gonna have my puppet in line.

  • What you're gonna see in a moment Setting up run, 10 comparisons.

  • What?

  • We're doing this.

  • We're using numb pie to create a line space 1 to 10 and then we're giving a different labels.

  • Constant log, linear log, linear quadratic cubic exponential.

  • And then what we're telling it to do here is the actual calculations.

  • Each one of these calculations is corresponding to its particular label s O.

  • Therefore, this could have been done, even like addiction.

  • Or if you're going to do key values and then we're just setting up our figure size, and we're gonna be plotting it.

  • Um, and then this is due to do.

  • This is how we're actually gonna go through the calculation piece.

  • What I'm gonna do is go through that on.

  • Here we go.

  • So what?

  • This is just another graft version showing you that the end increases with the relative run time on a particular systems on this case.

  • This is my system and it's giving you a color code.

  • Below that were constant log, linear log, linear, quadratic cubic exponential.

  • So again you can see we're in good, better, worse and then just ask my territory.

  • So even with an a four, you can see the relative runtime performance or here who were in a constant and log.

  • So we have constant longing for our relative run time.

  • As you know, you could say it's like one and change and then once we start to get up to linear log linear, even with event of four were still under 10 of a relative run time.

  • So it's not.

  • It's not crazy's guys.

  • There could be some group together, but now we're launching out of the out of the territory or with quad Cubic Exponential were just weaving with Anna.

  • Four were hitting relative runtime substantially and look without a four were looking to go off a relative run time here for cubic and we're out of the ballpark.

  • And what did we find for Cubic was, that's exactly what you to do.

  • This big Oh notation was for this particular it was cubic run, so it's big O was cubic.

  • So in terms of its relative performance, you could see with a small end.

  • You know what?

  • The end of one and end of two.

  • We saw substantial change than out of and of Tenet just skyrocketed.

  • So we're here with another 10.

  • You can see how the relative run time if we ever even get up to the cubic it just rises at exponential rises at a cubic great.

  • So clearly we want to choose out rhythms to stay away from any exponential quatre cubic behavior in terms of computational intensive, typically mathematics.

  • And you're gonna see us from doing machine learning, and I and we're gonna use we're gonna use way will do exponential, quadratic cubic behaviorist.

  • But we don't want to be doing them on large scale.

  • So if we're gonna be doing that, we want our ends to be relatively smaller.

  • S o.

  • If we keep our end small, we can keep our relative run time in a manageable fashion.

  • But again, this is exactly why if you're running certain neural networks on particular models on different peces, why you can have run times echo hours, days into weeks, depending on your system and why things like the GPU, and it's parallelism.

  • Wyatt has such a massive impact on decrease the amount of time that we can run with them, L a.

  • I and deal and even something you're going to be soon coming out, which is the NVIDIA Volta.

  • Well, it's already out.

  • One of the biggest pieces of that is it's It's ability with 10 Tsar's on dhe.

  • When you have a GPU that is primarily focused on tensor mathematics and manipulation, you're gonna find that thes scaling of that is going to be astronomical.

  • On the speed of that's gonna be a heck of a lot faster what we currently have even would say, the tight next pain running up with Pascal.

  • So it's gonna be it for today again.

  • This was beginning of algorithms, and we start with a big a notation and this this information that we're doing now.

  • It's not just for, like, say, for computer science, and it's not just for your knowledge.

  • All of this is even if you start going to interviews for computer science, you're gonna be dealing with functions or formulas that are gonna be looking where they falling on us.

  • Are they computational?

  • Lee intensive from a memory standpoint, or from a time standpoint, how could you make them better?

  • What could happen that could make him worse.

  • And how can you make them functional in terms of what they're doing?

  • Because again, you can code an incredible piece of code.

  • But if it if it can't be run on, you know, 70% of systems in the world.

  • And what good was the code?

  • So you have to keep these things somewhat logical.

  • Big O examples First for a big old one.

  • A constant numbers.

  • So we have here creating a function function is constant.

  • Gonna put values of the argument.

  • What we're doing is printing in this case, the first item on the list of values have given us the first item because we're indexing at zero.

  • It's gonna be our first items were printing out values, whatever.

  • We're gonna run through valleys of the argument and printing out the index of one.

  • So we're calling that function here function constant 12 and three.

  • So out of this list, that was we're passing through our function of funds constant.

  • Give me the index position of zero.

  • And sure enough, it gives me one because that's appropriate.

  • Now, the point of this is that it doesn't matter how large my values list becomes this values list I could have made this for and I'm still going to get one, because doesn't matter if this was infinity Digits long on Lee grabbing the first index position, which is always gonna be one.

  • And it's also in the first spot.

  • So this algorithm is only gonna grab dinner tradition zero in that list of, you know, how many times are running about how big this list is.

  • So this is a constant.

  • This is a big goal of one, and Constance is remember from the chart from yesterday have one of the lowest computation intensive impacts on a computer system in terms of performance.

  • So scalability, this is nothing.

  • This is easy as balls.

  • You could scale this as much as you want.

  • We're only grabbing the first index position.

  • So now we're gonna move on Thio and Big O event, which is course is going to be linear.

  • Zonda Constance Linear selenia is slightly above in terms of were still in good performance on a big O performance chart.

  • Eso regardless of end, we still could get fair, computational intensive out of the system, so he would've final function, and we're gonna put a list through there.

  • So we have four Val and List.

  • So that's gonna before our values in the list.

  • We want to print the values so it doesn't matter what I list is gonna be a It's simply gonna print this.

  • You know what?

  • I'm gonna d'oh let me do this So you guys can see the outputs as we run it.

  • So I don't want your I feel like your brain is cheating.

  • So you're gonna pass the list of 12 and three through my function list to find function, and all it should do is print out each one of these values within the list, So gonna shoot through there.

  • So, of course, it prints out 12 and three, so every values gonna print a list each time the list gets larger, though.

  • What's gonna happen to our when it's also gonna get larger?

  • It's not gonna be a constant.

  • It's gonna be linear.

  • So if right now, if it's three, it's gonna print out three.

  • Conversely, if it was larger, it would print out a larger list.

  • So our list growth does have an impact on the computational intensive of our system.

  • And it has a has a a competition ends of risk up.

  • So you'd say big O to the N and is a linear growth rate.

  • So as our list grows with this particular function, as our list grows, so too does the computational.

  • Not to the point that it's disastrous, though, because again, computers could do a hell of a lot of meth.

  • But again, the point is it has to do the whole list.

  • Whatever I do pass through here.

  • So that's why oh, and linear is going to be a little bit more computational intensive than No.

  • One constant.

  • So what?

  • We have every valuable print, the list each times the larger list gets, the bigger the big out.

  • Yet that's who discovered.

  • So now we're gonna go to quadratic.

  • This is gonna be oh, within its squared.

  • So we're gonna create a quadratic viggo function.

  • So in this case, we're going to do that just by doing a four loop in a four loop.

  • So we're gonna do a functional quad, gonna have a list, what we want to do is print a pair, so four Item one enlist and then four item to endless print item.

  • One print item to nothing crazy will make her a list just for fun will make it a little bit bigger.

  • I want this to be neat.

  • And then we're just gonna call our function fungus quad and then put our list through our list that we produce of 123456 So, what this is going to do?

  • It's gonna go for item number one in the list and that's gonna print one is gonna print to is gonna print three.

  • It's gonna be so it's gonna be 11121314 It is going to do this for each item on the list, as goes to just one endless too.

  • So sure enough, we have 11121314 to 1 to 2 to 3.

  • We're never dropping anything off 313 till it's creating a pairs list all the way through this.

  • But the point of the matter is that this is gonna be one iteration for the computer system for number one.

  • Let's stick assistant 11 element within our less over the first element.

  • It has to do this run, and then it has to do this run.

  • So it has to do end times end for each element that's in our list.

  • But this doesn't matter how big this is.

  • Doesn't matter if this is one number or one element.

  • Doesn't matter if it's a 1,000,000 elements.

  • Infinity elements.

  • The point is, it's always gonna have to do end times.

  • End says that we're gonna end squared.

  • That's gonna result in this.

  • That's that's exactly we're gonna we're gonna have a quadratic representation is on the graph, which is we saw from from last week.

  • You bring that up when we get into quadratic again, we can see that from our as the elements grow very quickly.

  • So you know where zero and one and two of their elements grows, air and grows.

  • The operations are gonna be, in this case, exponential ways were and squared.

  • It's because we have two loops.

  • One lesson, said the other.

  • As we said for list event items, we also performing operations for every item on the list.

  • That means a total performance and times and assignments, air and squared.

  • So if we have three assignments, show you.

  • So if we only have here we have six, so we should have 36.

  • So if you counted this down 1 to 2 hopes you should have 36.

  • Let's keep this little shorter so it's easier to see.

  • So if we have three elements, we should have 9123456789 So that's our end times N O R N squared Whatever end is gonna be n squared in terms of computational intensive for that particular system.

  • How many operations airway actually performing or performing this and operations for an operations in a loop of loops on, but says you could see how very dangerous is gonna be for large, very large imports is why big, oh, so important to be aware of when you're creating software.

  • Hence the input of three guys.

  • Nine outputs.

  • That's what I just showed above.

  • We have nine outputs for ah, in the end of three calculating scale of big oh so insignificant terms drop out of the big O notation And this is exactly what we saw yesterday when we did, uh, here we go in terms of these air called insignificant terms.

  • That 45 20 the 19.

  • But you're always gonna go on a backwards order, meaning that the lowest term is gonna be the 19.

  • And then it's gonna be our square, and that's gonna be our cube in the terms of the constant that stands before them.

  • So it's you.

  • So just going from big off one too big of two are 19 started become very insignificant.

  • And then from a big of 2 to 10 not only during 19 become insignificant, but so too did or 20 and our 45.

  • What came significant, though, was the cubic even our square started to show that it was not.

  • It was falling off rather quickly was the an increased that and squared is gonna become smaller and smaller compared to what the cube is going to contribute to the ultimate outcome of your answer.

  • So when it comes to the big O notation we only care about the most significant terms, remember, is the MPA grows larger.

  • One of the fastest growing turmoil matter.

  • This is again like taking the limits towards infinity.

  • If you're familiar with calculus, so that's that's we always want to focus on what is the most significant term.

  • And that's what we're heading on here out of this whole function.

  • This is the most significant term because as and grows, this is going to contribute the largest to the overall answer in proportionate to the other value that would reside within that function.

  • So here we're creating a new function to find print once, and it's gonna print all the items once.

  • So for the values air for about unless print develop, print list print once and there was gonna call our list.

  • What list is this one?

  • What's gonna go by our last list that we ran in the Jupiter Notebooks was gonna list 12 and three s O.

  • If you wanted to see that could also run.

  • It's gonna point the last 12 and three so we can see how the growth is linear for this particular input.

  • So this is just gonna be since it's a linear, growth is gonna be big.

  • Go to the end and you would say, Yeah, it makes sense, right?

  • For every value in the list.

  • If there's three were only running this end times event is one.

  • We're going through this once.

  • Event is, too.

  • We're going through it twice if in his three, we're going through it three times.

  • So it's a linear growth rate for the function that we're dealing with in regards to go here to funding print.

  • Three.

  • We have our list, but now we're doing is we're printing it three times.

  • So for each value that's in our list, we're doing it three times for each particular end.

  • So for our list, it goes to print.

  • If I on the list, it's gonna be one print violist.

  • 23123123 It's just printing this three times because the gun that we have three different four loops within our function there.

  • So again, this is gonna run three times For each of the ends.

  • This becomes an order of three times and now notice it's still linear.

  • It doesn't automatically becomes and Cube.

  • That would make any sense because each of these going to be run in a sequential fashion, so it's just gonna be three end, but it's still linear.

  • The important thing here is this.

  • Three times infinity is not really different than infinity, so weaken, dropping insignificant Constance.

  • And that's why this three end.

  • You'd be technically correct to say this is a big 03 to the end, as and grows you are competition test is going to be three times that in, However, as then becomes infinitive three becomes inconsequential becomes an insignificant constant.

  • So so to be a big goal of end.

  • So this is no different than this would be in terms of.

  • It's a big o notation grafted.

  • Would you say this was going to run faster than this?

  • Absolutely.

  • But we're talking very small list right now when we get to very, very large lists, those times This should still always be longer than this, but it becomes inconsequential in terms of the difference.

  • Here we have a new function, where to find a comp.

  • It's gonna take a list as an argument.

  • So now we're doing three different things, and you can ignore this right now.

  • Let's just go down to widows who are printing the list of the first position.

  • That's what we're doing first, and then we're creating a new variable called the mid Point.

  • We're gonna take the length of that list and divided by two.

  • And then we're taking a four loop for the values in the list from the beginning to the midpoint.

  • Print that value and then for acts in range.

  • 10.

  • So we're gonna go 0123456789 Print the number.

  • So I'm gonna shift enter through that so it can actually create its part.

  • Auto saving.

  • Oh, Jesus Christ.

  • I never called him.

  • Likewise a wind running.

  • I never called my actual function of what created.

  • So here I have my list.

  • I've wanted to give our 56789 10 And then I'm calling the function we just rode up above, and I'm passing through this variable.

  • So now we have 112345 And then we have the word number printed 10 times.

  • So what is the big all of this particular function?

  • So if we're looking through this again, you might recall this from yesterday.

  • All we're doing here is taking our list that we have here and pulling out the first indexed position.

  • That's gonna be a constant of one always writes their big old one.

  • That's a constant.

  • So we have here this first function is gonna print a big goal of one.

  • This is gonna be a constant, nothing special there.

  • This is just creating.

  • Ah, the variable midpoint.

  • We're taking, like the first voting by two.

  • And then we're using that in this piece here.

  • So what we're doing is all we're doing is printing the first half of the left over from the beginning of the list to the midpoint.

  • Print those values.

  • So if a list of want to do it so the mid point you're going to tell me is going to be five.

  • So go from the beginning.

  • Causes 10 divided by two is five and then go from the beginning of the list to the mid point.

  • It's gonna print one through five.

  • That's what country for this point.

  • So for this one, this is going to be that's we have here.

  • It's really doing half the list.

  • So it's big o and divided by two because whatever my end is here, my end was 10.

  • So the big day's end about by two, it's five.

  • We're gonna have an output of five different elements and then for the last one for X and range 10.

  • So we have a constant here, right?

  • Doesn't matter what this is Constantly doings printing in numbers.

  • This is gonna be o to the 10 big of 10 or a big o constant.

  • So what we have here, we have one constant we have over two, and then we have a big old town, which is also constant.

  • If we were to compare all three of those since we're doing down here with Big 01 plus and over two plus 10 what did we say, though, about constants?

  • Constants are gonna fall out as the end gets larger and larger and larger.

  • As we're scaling up, you're going to see how the number one in the number 10 are gonna quickly mean absolutely nothing to our overall answer for computational intensive on a big O.

  • And even the divided by two is gonna begin to have no effect either.

  • So what we're gonna be ending up with is a big O of end.

  • This is also going to become a linear growth rate based on the end, because the constant so they do have a meth medical impact.

  • Early on, that impact falls off dramatically as we scale up.

  • So another piece we're gonna speak about when we get to Big O is an entire big on rotation and computational intensive and algorithms is worst case versus best case.

  • There's no point in really concerned come computing a best case other than knowing what your best case could possibly be.

  • But we usually it's best to do your big A notation in a worst case scenario.

  • So that's where we usually consider it the worst possible case of an algorithm.

  • Because then you know what your worst case scenario is gonna be and you're gonna work up from there.

  • Ah, but an interview setting.

  • It's important to keep in mind that there is a worst case in the best case scenario and they cannot very completely different big old times.

  • They should have very complete different big old times.

  • So we're gonna do here is we're gonna quit a best case scenario for stuff, So I'm gonna create a function we're gonna call match your it's gonna take a list, and it's gonna take a match.

  • So we're having two different arguments on your pastor this function and then four item in the list for item.

  • If item equals match returned true.

  • Otherwise, we're gonna return flows from for the loop.

  • So I'm gonna have a list.

  • We already have a list producer.

  • Have l s t here.

  • I'm just gonna run this cell to see what our list is.

  • So it gives me the I'll put our list is one through 10.

  • All right, sweet.

  • And then what I'm doing here is I'm calling.

  • The function is creating match er and I'm saying for the first argument, it's less than that.

  • So I'm putting through here is list, and I'm putting a number one.

  • So a match of one.

  • So what is going to do?

  • Is gonna say four Item in list for number 123456789 10 if item If this equals the match and the match here.

  • That was our argument.

  • Here's matches.

  • My argument.

  • If any one of these equals this, it's gonna return true, otherwise returned.

  • False.

  • So it doesn't say it says if any item essentially, what we're doing in that list.

  • So what do you think we're gonna get for this one here?

  • Well, we're gonna run it.

  • We're gonna get true.

  • Is sure enough within this list, there is a match for the number one now.

  • The reason that this is the best case scenario is because where is the number one that we're trying to match is in the It's in the end expedition of zero.

  • It's at the very, very first of our list, so a computer's gonna go sequentially when it's dealing with the list.

  • Or, you know, when we get a different kind of algorithms, you can see now it's all we could split it.

  • We could go higher, lower and go from there and just break it down half and half and half and half.

  • But in this particular example, our list what were matching is very the first elements of the list goes is number one yet true?

  • That's our bet so that the time to compute that is very, very low Now, in terms of a false, we're just going to make sure it's working.

  • So we have our list for passing a 20.

  • There is no number 20 within our list, so we're going to get a false now.

  • This is essentially technically a worst case scenario because in order to find out if this was true or false In order to make this part of going to determine if we were gonna fall down into the true or if we're gonna jump out of the loop on return falls, the computer had to go under, had to go number one, and then I had to go to 34 had to sequentially go down this list to find that there's no number 20.

  • So in the first run match your 1st 1 we only had to go through an element of one to find the true and match her list.

  • 20.

  • We had to go through 10 different elements to find out that it's false.

  • So technically, this is a worst case scenario because we have to go through our entire data set to find out that there's no match.

  • So that's a worst case, because again the entire list must be searched and elements out of the and worst case becomes linear.

  • This is a big old one, the constant, because again, once always gonna be in the first, his exposition within this particular list.

  • Lastly, what is gonna talk on space?

  • Complex city.

  • So not only did we talk about how obviously huge time complaints, time complexity with big o notation and functions and algorithms.

  • But there's also a space complexity is also concerned with how much memory space and awkward amuses.

  • If you tried to d'oh data work with a l A.

  • I am L D l on images on image net or in any particular kind of cattle piece.

  • If you have a crappy GPO is gonna come out and say memory error because you're trying to allocate.

  • The algorithm is trying to allocate a certain amount of memory to the problem, which it does not exist.

  • So it's telling you I can't run.

  • This crap is you need more memory than what a connection, what you have.

  • So this notation of space complexity is the same.

  • But instead of checking the time of the operations were checking the size of the allocation of memory.

  • So in this quick example is creating a function called memory and we're putting it and equals 10.

  • So then, if we look at the code says four acts in range and a gay and was 10 we're gonna print memory, so we're gonna print the word, the string memories, and then we call memory 10 I was gonna be our arguments.

  • Actual me t take that out because way assigned 10 to our argument of end when I ran the coat.

  • So, of course, very complex code, right?

  • It's gonna print the word memory 10 times.

  • But if you're looking at this loop, what we have here is this first piece is a time complexity, because if N is three, then it's gonna run through this three times.

  • If Anna's infinity it's gonna run through this infinity times.

  • This is a time complexity.

  • This is out of the end because as an and grows so too.

  • With the time this is a linear growth right here.

  • It's only one element.

  • It's only one operation to run through due to make that sufficient now for print memory.

  • This is gonna come a space complexity, and we have a big old one for space complex because memory is a constant meaning that it's not printing, it's not creating 10 versions of this.

  • It's creating at once and in terms of space, complex city.

  • It's a screening, our one constant.

  • It's running at 10 times, but the point is, this is the lowest computational intensive that we can deal with because it doesn't matter if I made this as 100 and ran it not going through that for you, but it's not gonna have any kind of effects effect on the big O in regards to space complexity.

  • But we'll have effective time complexity.

  • So we have over the end for the time complexity, which we already came to that conclusion.

  • Tha space complexity and memory doesn't need to store 10 versions of memory only need to store one string.

  • That's gonna be the constant so again in terms.

  • If you said which one of these is more efficient, you would say the constant is more efficient than the time complexity.

  • So in this particular code, if you were dealing with a larger piece of code and you had time, complexities of space complexities and if you had a space complexity of big old with one a time complexity of big out of the end, if you had to manipulate some aspect of the code or destroy something you'd rather do from a space complexity standpoint, because the computational intensive of that from the big o of a constant is much lower in terms of scalability in terms of limits than the time complexity of big o N.

  • Because this, even though it's still linear, this is gonna grow in a much, much faster growth rate in terms of computational intensive than the space complexity of a constant would.

  • Now again, I don't expect all of this to sit within the first time that we're doing this.

  • But that's why you have videos.

  • You can go back and do this again and again, and we're gonna gonna have more and more examples.

  • And the whole point of this again was for algorithms for also playing with Jupiter.

  • No, but more so for algorithms and then even doing interviews, because it's beginning to M l and D.

  • L and a lot of those outward then, based on even if you're doing something with numb pyre, banners were, psychiatrists can learn.

  • It's important that you understand what that algorithm is doing to us from a complexity standpoint, to grow and trying to scale things.

  • And if you're hitting limits or walls, you'll know what those limits our walls were caused from.

  • So in python with ray sequences or three different types of Ray's, you could have a list to Raya to pull on the string.

  • Now these are all different.

  • Three types of a raise.

  • You can see that the list is going to be identified by the brackets to pull parentheses with a common between them, and then a string is identified in between parentheses with the quotations.

  • What makes all

the primary purpose is video.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

面接のためのPythonアルゴリズム (Python Algorithms for Interviews)

  • 2 1
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語