How do we determine which code is better?
maybe it is easier to read or is code two better?
Big O is a way to mathematically figure out which of these two is better, which one runs more efficiently.
obviously, we want our code to run as quickly as possible, be as efficient as possible. This is what is called time complexity.
But we don't measure time, complexity in time, we measure it in the number of operations, and the reason we do that is if you took the same code and we ran it on a faster computer.
Space Complexity is the amount of memory that something uses.
while you know code1 is very fast and runs in 15 seconds are comparatively fast, however it may uses a lot of memory.
And then we reset all of this and we look at code2, and while that runs a really long time, full minute maybe it uses less memory.
And if this is what's most important to you, maybe code two is better.
It's up to the situation that we running code. We are going to look mostly at time complexity, but space complexity also important. So we should know about in the case of what if we care about space complexity more?
When you're dealing with this kind of notation, there are three Greek letters that you'll consistently see.
They are Omega, Theta and Omicron. Omicron is better known as O as in Big O.
Let's say we're going to build a for loop to iterate through this array until we find a particular number.
Assume that we're looking for the number 1.
If we're looking for the number one,
this(1) is our best case with the least number of iterations through the array because if there is less repetitation we get more efficiency.
This(7) would be our worst case
and this (4) would be our average case
this best case is represented with the Greek letter Omega.
This average case is represented with the Greek letter Theta,
and our worst case is represented with Omicron or O
Big O is always going to be worst case. So when we measure Big O, we are always measuring worst case.