1 Introduction
In our last topic summary we discussed why and how we represent running times as a function and gave high level descriptions of the tools we could use to compare those functions. To give a brief refresher:
- If we want to say that some function is
less than or equal to
another function , we’ll write or (the former is more correct in terms of notation, but the latter is more commonly used). This is read asis big-oh of
. - If we want to say that some function is
greater than or equal to
another function , we’ll write or . This is read asis big-omega of
. - If we want to say that some function is
asymptotically equal to
another function , we’ll write or . This is read asis big-theta of
.
In all of these cases, we want to be comparing functions in the way we saw them in our prior courses (CSE 123, CSE 143, or equivalent). That is, we want our definitions to allow us to compare functions by dropping non-dominant terms, ignoring constants, and then looking only at long-term behavior. This means we would compare with by simplifying to be and simplifying to be , thus concluding that or .
This is the process we want to end up with, but we need definitions that formalize this. This is because we want to be able to use this process even when the functions are not so easy to compare. For example, this process still makes it unclear how we would compare with .
2 O, ,
We now will present the formal definitions of , , and , and discuss why they result in the comparison process above.
Firstly, let’s talk about what type of thing , , and are. When we look , , and , these each are actually a set of functions, specifically:
is the set of all functions which are asymptotically upper bounded by .
- Some examples of functions that belong to this set are , , , , , , etc.
is the set of all functions which are asymptotically lower bounded by .
- Some examples of functions that belong to this set are , , , , , , etc.
is the set of all functions which are asymptotically tight bounded by .
- Some examples of functions that belong to this set are , , , , etc.
(Totally optional aside if you want to geek out about math notation with me for a bit. The formal type of , , themselves is something like functions mapping functions to sets of functions
, and we could write their type as which would read something like a function whose domain is functions mapping natural numbers to natural numbers and whose co-domain is the powerset of functions mapping natural numbers to natural numbers
.)
2.1 Formal Definitions
Here we present the formal definitions of , , and :
- We define provided that and such that it is true that .
- We define provided that and such that it is true that .
- We define provided that and .
2.2 Intuition
Let’s now discuss the intuition for how these definitions give us some of the properties we’ve mentioned to be desirable.
2.2.1 Achieving greater than, less than, and equal to
We mentioned that acts like , acts like , and acts like . Here’s where we can see these relationships in the formal definitions:
- : Ignoring all of the quantifiers for now, we see that the definition of concludes with . We are therefore checking that the value of is less than or equal to , directly corresponding to that intuitive notion.
- : Ignoring all of the quantifiers for now, we see that the definition of concludes with . We are therefore checking that the value of is greater than or equal to , directly corresponding to that intuitive notion.
- : we say that provided it is both and . Mapping back to the intuitions of and this means and respectively. Similar to when we’re comparing numbers, the only way that something can be both and another thing is if they are equal. (Important, because of the way we’re comparing, we’re not saying that and give the same output, just that in the long term their outputs are of similar magnitude.)
2.2.2 Ignoring Small Inputs
Another property we mentioned that these definitions should have is that they ignore small inputs. This was important because we might have an algorithm which is very fast for small inputs, but then scales poorly as the input size grows. In such a situation we would likely prefer the algorithm which scales better, so we hope to ignore these little input sizes.
All three of these definitions enable this in the same way. Each definition has the requirement that . We can interpret this (pronounced n sub zero
or n naught
) as the size where we stop ignoring. In other words, we’re going to ignore all input sizes smaller than this chosen value . The definitions enforce this ignoring by conditioning and on . In other words, the definitions only need the target inequality to hold for values of that are larger than , all the smaller values are ignored.
2.2.3 Dropping Constants and Non-Dominant Terms
We want our definitions to have the property that constant coefficients and non-dominant terms have no impact on the asymptotic growth. In other words, we want a function like to be considered asymptotically the same as . This behavior is accomplished using the constant value in the definition.
Let’s first look at how allows us to ignore constant coefficients. Suppose we want to compare to . Because our definition of allows us to multiply by a , we could pick to conclude , since we would have and so . Using the choice of we could show since we would have . Together, this means that . From these examples, we can see that two functions that differ only by a constant coefficient can be shown to grow at the same asymptotic rate using the constant in the definition. For this reason, we are able to ignore constant coefficients in asymptotic analysis.
Next let’s see how allows us to ignore non-dominant terms. Intuitively, what we’ll see is that adding a non-dominant term makes less of a difference asymptotically than changing a constant coefficient on the dominant term. Therefore, since we understand that we can ignore constant coefficients, we can also ignore non-dominant terms.
Let’s see an example of this. Suppose we want to compare with . Let’s start by showing that . To do this we need . To help ourselves out, we’ll first identify a new function such that and differs from by only a constant coefficient. Let’s start with . For any value of and so and so $f(n)13n^2. We can now use , and since that differs from by only a constant factor, we can conclude .
Let’s now show for and . In this case we need , so for our choice of we want and we want to differ from by only a constant factor. In this case we can select by just dropping the non-dominant terms since they only could increase the value.
3 Example Proofs
Now that we’ve seen how our definitions operate, let’s see some example proofs of , and . The definitions of and require showing that there exists values and which cause the statements (for ) or (for ) to be true. Therefore a complete proof only needs to prove any one choice of paired with , then demonstrate the target inequality holds for every value of that’s at least . The important thing to note is that you do not need to justify how or why you selected your and pair, you just need to defend that they work. In the examples below we’ll show you how I (Nathan) would go about identifying the pair, then I’ll show you how I would prove that my choice works.
3.1 Squeeze Method
In all examples we will show one way we might approach identifying and that we are calling the squeeze method
. For the squeeze method, instead of directly comparing with , we will instead identify a third function that we might call . We want this new function to be squeezed
between and , but is easier to compare to both. For example, for proofs, we want , and for it to be easier to compare with and with .
Observe that this squeeze method is mostly an approach for how we approach the problem on our scratch paper
, but may not show up when we write out our proofs.
3.1.1 Big-Oh Proofs - Squeeze Method
For each of these we’ll show for different choices of and .
3.1.1.1 ,
Nathan’s scratch paper Because we’re showing , we want . Comparing the two functions, seems to have the larger dominant term, so my strategy will be to identify a function where it’s clear that and . Specifically, I will pick to have the form so that it will be easy to compare with and easy to compare with . Because for any value of we have (multiply both sides by ) and (combine the previous two expressions) I can pick , because it’s clear that (by substituting for and for ).
Now we need to get . We could take two strategies to do this. We could either try to select an so that
overtakes, or we could select a value of so that this becomes true for all choices of (or we could mix these). To me, it seems easier to select , so I’ll go with that. Since the coefficient within is and the coefficient in is , I’ll pick so that , making it clearly larger than and therefore larger than .
Now we have our selection of and . Let’s use those to show .
Proof: By definition of , it’s sufficient to show for a choice of and . Let and . We now need to show that whenever we have that . Observe that for we have that and also . therefore . We can also see for that and so . Therefore we have , and we can conclude .
3.1.1.2 ,
Nathan’s scratch paper Because we’re showing , we want . We can’t exactly use the same strategy as before to convert all pieces to like terms because we’re subtracting (the argument we used above to do this relied on the fact that replacing gave us a larger value, but replacing for here gives us a smaller value). But keeping in mind that if and , it’s sufficient to substitute with something larger. In this case, we can just drop the since it only makes smaller. In other words, it will be good enough to show . Now we can use the same trick as the previous example, and let with .
Now we have our selection of and . Let’s use those to show .
Proof: By definition of , it’s sufficient to show for a choice of and . Let and . We now need to show that whenever we have that . Because , it’s sufficient to show . We proceed by algebra: The last expression is true for all because , and the right hand side increases with whereas the left hand side is constant. Therefore we have , and we can conclude .
Notice for this last proof that exactly the same argument would have worked with . For the sake of the proof, though, we don’t care which choices of and are used so long as they’re successful. If you want to try to fine the smallest choices, you’re welcome to, but all we care about is a successful proof.
3.1.2 Big-Omega Proofs - Squeeze Method
Next we’ll show . These proofs will operate in exactly the same way, we just need our inequality to face the opposite direction. In other words, we want ,
3.1.2.1 ,
Nathan’s scratch paper Because we’re showing , we want . Let’s try to use the strategy we applied before, which is to get more things into like terms while only making smaller. In this case, dropping the makes it smaller, so we now have . Now we could try to just replace with since that would make the expression smaller ( is smaller than ). However, that makes our expression negative, and the output needs to be a natural number by definition of . Instead, we can now use . The insight we’ll apply is that for large enough values of we can be sure that , so we can replace with to get a smaller function. All we need to do now is figure out how large needs to be before this occurs. Here, we can use the value , since once multiplying by gives a larger value than multiplying by . At this point we have that , and clearly , so everything should work out for and .
Proof: By definition of , it’s sufficient to show for a choice of and . Let and . We now need to show that whenever we have that . Certainly , so it’s sufficient to show . We can proceed using algebra: Note that whenever we have that , so we have and therefore .
Again, we could have chosen a smaller value for and the same proof would still work (namely, we could have chosen 3), but we don’t care! Our choice was still successful!
3.2 By Parts
method
In these examples we will identify our and by comparing our functions by parts
. This approach can be used for comparing to where for other functions and .
This strategy uses the following observation:
If for constants and , and for constants and , then belongs to for constant and .
Proof: We know that we have that , and similarly we have that . This means that for all values of larger than both and (i.e. larger than the ).
This means if is the sum of a bunch of other functions, we can asymptotically bound relative to by bounding each of the components of .
It’s important to recognize that the this approach is most well-suited for proofs, it’s less helpful for proofs. Let’s look at some examples first, and then see why it’s not a good fit for .
3.2.1 Big-Oh Proofs - By Parts Method
For each of these we’ll show for different choices of and .
3.2.1.1 ,
Nathan’s scratch paper Because we’re showing , we want . We can break down where , , and . Next we find choices of and to show that each of , , and belong to .
To show we need to show that . By applying algebra to simplify, this is equivalent to . This holds true with so long as , and so we will use and to show
To show we need to show that . By applying algebra to simplify, this is equivalent to . This holds true with so long as , and so we will use and to show
Finally, To show we need to show that . By applying algebra to simplify, this is equivalent to . This holds true with for all values of , and so we will use and to show
We can now use the previous three results to show . for , we will use , and so . For we will use .
Now we have our selection of and . Let’s use those to show .
Proof: By definition of , it’s sufficient to show for a choice of and . Let and . We now need to show that whenever we have that . To demonstrate this, we can break up into parts, so we’ll use . To now show , it’s sufficient to show , , and .
, which is true for all
, which is true for all
, which is true for all .
3.2.1.2 ,
Nathan’s scratch paper Because we’re showing , we want . We can break down where , , and . Next we find choices of and to show that each of , , and belong to .
To show we need to show that . By applying algebra to simplify, this is equivalent to . So therefore this holds true for any , and for any value of . We’ll use and .
To show we need to show that . Because the left hand side is negative, this is true for all values of and , so we’ll pick and (since must be positive according to the definition of ).
Finally, To show we need to show that . By applying algebra to simplify, this is equivalent to . This holds true with for all values of , and so we will use and .
We can now use the previous three results to show . for , we will use , and so . For we will use .
Now we have our selection of and . Let’s use those to show .
Proof: By definition of , it’s sufficient to show for a choice of and . Let and . We now need to show that whenever we have that . To demonstrate this, we can break up into parts, so we’ll use . To now show , it’s sufficient to show , , and .
, which is true for all
, which is true for all because the left hand side is negative while the right hand side is positive.
, which is true for all .
3.2.2 Big-Omega Proofs - By Parts Method
Now let’s see why it is challenging to use this method for . Let’s look at our example from above, and see what happens when we apply the same approach with only our inequalities held.
3.2.2.1 ,
Nathan’s scratch paper Because we’re showing , we want . We can break down where , , and . Next we find choices of and to show that each of , , and belong to .
To show we need to show that . By applying algebra to simplify, this is equivalent to . So therefore this holds true for any , and for any value of . We’ll use and .
To show we need to show that . Because the left hand side is negative, this actually can never be done! This means we’ll need to break things up differently. Forget what we did in the previous step, we’ll break up into where and .
Now let’s skip to our new . We’ll need to show that . Notice that the left hand side is constant, wherease the right hand side is increasing. This means that the only way we could make this true is if is negative, which is not allowed. At this point, though, we’re out of options for how to split it up, so we’re right back to where we started!
The intuition here is that with asymptotic notation, only the domininant term determines the asymptotic running time. This fits in well with since the non-dominant terms of should each be upper-bounded by the dominant term, which should be upper-bounded by , in other words, all of these inequalities are in the same direction. For all of the non-dominant terms of are upper-bounded by the dominant term of , which itself is lower bounded by . This means that the non-dominant terms of may compare to in any direction, making it so we cannot totally separate them into parts for our proof.
3.3 Guess and Check
or Induction Method
The last method we’ll discuss uses induction. As with any proof by induction, the proof itself is very formulaic making it relatively easy to demonstrate our goal. The key downside to induction though, it is that it is really only useful for showing the answer to be correct, not for helping to find the correct answer in the first place. This is why I’ve dubbed this the Guess and Check
method. For this method you’ll need to first use some entirely different method to select a value of and (perhaps a method from above), then you can use induction to demonstrate that this method is correct.
3.3.1 Big-Oh Proofs - Guess and Check
Method
For each of these we’ll show for different choices of and .
Our proofs by induction will proceed as follows:
- Base case: show that
- Inductive step: show that if for some we have then .
Because this is guess and check, we will not show any scratchwork here. Instead, we’ll just use a choice of and from a previous method.
3.3.1.1 ,
Proof We will apply induction to we have using and .
Base Case:
We need to show . Plugging in we get and , and so the inequality holds.
Inductive Step:
We assume , now we wish to show . Let’s begin by simplifying the left hand side.
And now the right hand side;
So it is sufficient to show . Again, let’s simplify with algebra.
This inequality holds when because then , and so the right hand side is positive. Therefore by principal of induction, for all and thus .
3.3.2 Big-Omega Proofs - Guess and Check
Method
To show by induction we proceed as follows:
- Base case: show that
- Inductive step: show that if for some we have then .
Note that this is exactly the same as the above, but with the inequality facing a different direction. Due to the similarity, we will omit examples here.
3.4 Big-Theta Proofs
Next we’ll show . To do this, we just have to do one of each of the proofs above! We need to show both that and . Importantly, these two proofs can be done completely independently. That is, we don’t need to use the same choice of and for each, we can use different ones!
3.4.1 ,
Proof: We showed above that and that , therefore .
4 Common Misconceptions
There are many misconceptions that pop up with , , and , and many of these misconceptions are seeded by or reinforced by various problem solving resources that are broadly available (such as interview prep resources, etc.). Below we have a table of misconceptions, and a discussion of how to correct them.
| Misconception | Discussion |
|---|---|
means worst caseand means best case |
This is probably the most common misconception. I believe that this stems from the (correct) understanding that means less than or equal toand means greater than or equal to. The misconception comes in, though, because of a misunderstanding of what exactly we’re comparing. When using and we’re comparing two functions, not necessarily two running times. So if we say that the worst case running time of our algorithm is we’re saying The function which we identified using a worst case runtime analysis is asymptotically upper bounded by the function .We are not saying the algorithm takes up to linear time to run. As such, it totally makes sense to say something like the best case running time of this algorithm isbecause in that case we’re saying that we performed a best case analysis on the algorithm, arrived at some function, and found that the resulting function was upper bounded by the function . |
Asymptotic analysis is the act of placing a running time into one of several buckets |
There are relatively few running times that comprise an overwhelming majority of practical algorithms. These include constant, logarithmic, linear, log-linear, quadratic, cubic, and exponential. Those, though, are not the only running times possible. Fundamentally, asymptotic analysis is a tool for comparing functions. As such, we can define for any function . For example, totally makes sense (it just so happens to be the same set as ), as does . |
| Either or | Earlier we drew an analogy between asymptotic analysis of functions and comparisons of numbers when we discussed the intuition for the definition of . There are some ways, though, where the comparisons of functions behave in ways that are quite different from comparisons of numbers. For example, for any pair of numbers and at least one of the following statements will be true: or . The same cannot be said of comparing functions. That is, we can find functions and such that neither nor . For example, we can consider and . For these functions, there is never any point where one function is forevermore greater that the other. This is because is always going to be continuously moving between and , making continuously moving between and . This means that for any choice of and any choice of we’ll be able to find a value of such that (e.g. an input where ) and one such that (e.g. an input where ). To provide a visual for how this could be the case, see the graph below, which plots and . ![]() |
