Asymptotics, Growth, and Decay
Last updated
Last updated
When considering stuff like the security and efficiency of algorithms and procedures, and in particular cryptographic schemes and block chains, we need a way to relate them to the various parameters. Consider for example a procedure that sorts an array: it is given a list of numbers, and returns them in increasing order. How can we describe "how fast" that procedure is? We can ask how fast it takes to sort ten numbers, or twenty, but that won't tell us much if in the future we want to use it to sort 1357 or 20545 numbers. We need some way to talk about how the length of the computation grows.
For this we use a function that is given the input length and outputs "how long" it would take to sort an array of this size.
Now, the term "how long" is also ill conceived. How do we count? In seconds? CPU cycles? Don't all such metrics depend on the computer running it? Can't they be different for two different lists with the same length?
The answer to all of that is yes. The whole point of discussing growth is to put that aside, and just look at the trajectory. This is often called the asymptotics of the function.
It is true that the asymptotics doesn't have all the information, but it tells us what happens in the long run. That "other part", that doesn't tell us about the rate of growth, but gives us concrete numbers (which is often just referred to as "the constants"), is also very important. But from some vantages, like the one permeating most of this book, the asymptotic point of view is the appropriate one.
To streamline the notations, computer scientists came up with a bit confusing yet very powerful notational system that captures the "type of growth" of the function while ignoring everything else.
Say that is some function that interests us, like the runtime of a sorting algorithm given the length of the list it needs to sort. As we said, is quite complicated and not even completely defined. However, we can say something like grows "at most linearly". What do we mean by that? That while might be a bit erratic and unexpected, we know that there is a function that looks like a line such that is almost always below it. This would look something like this:
This is often called the big oh notation.
Exponentials and logarithms are how we typically describe things that are large or small. Note that I did not end the latest sentence with "respectively", and this is no coincidence. When we talk about growth (that is, how fast things go to infinity), exponential growth is large, while logarithmic growth is very slow (and in between we have e.g. the polynomial growth: linear, quadratic, quartic, etc...). When we talk about decay (that is, how fast things go to zero), then exponential decay is small.
We use the notation to say that there is some line such that is below it from some point onward. In other words, we say that if there exist two numbers and such that for any sufficiently large we have that . Note that the notation hides the actual numbers and only tells us they exist. This is the power of asymptotic notation, it hides the constants and allows us to qualitatively talk about the growth trend. So yeah, the constants may change based on the exact architecture of the system that will eventually run the code, but for any system there will be some constants fitting the bill, and that is what captured by this notation.
Exercise: Prove that
Say that , then there are some and and such that for any we have that . Dividing both sides by we get that . However, for we have that , but is a constant so we can't have that for all sufficiently large .
More generally, given two functions and we can denote to mean that there are some constants and such that, for sufficiently large , it holds that . This allows us to write stuff like to say "look, I can't tell you exactly how grows, but the rate at which it grows is at most quadratic, if you put in an input three times longer, the growth in runtime is at most by a factor of three squared, that is nine".
Exercise: Prove that . More generally, prove that if and are natural numbers then if and only if .
Like the big oh notation helps us bound things from above, we have the big omega notation to bound things from below. By writing that we say that grows at least linearly, but it could actually grow faster, just like a sublinear function is still .
Exercise: Write a formal definition for
There are some constants and such that, for sufficiently large , it holds that .
Finally, we have the theta notation, which we use to say that we know exactly what the asymptotics are. In brief, we write that if it holds that both and . The notation essentially means "we might not know what is, but as long as we talk about growth rate, we can just pretend that it is ". Typically, will be much simpler than . For example, could be the running time of some complex algorithm, or the probability to revert a transaction in some concrete protocol, and instead of computing explicitly we could just prove that, say, .
Exercise: A function is called bounded if there is some such that for all . Let be bounded and let be any function, prove that .
Exercise: Find a function that is not linear, but such that .
Sometimes we don't care about growth but about decay. That is, we want to know how small gets as increases. For example, could be the probability that an attacker manages to break your encryption as a function of the length of your secret-key. We can do it using the same notation. For example, is what we mean when we say that a function decays linearly.
As an example, consider generating a secret-key. In any encryption scheme, a secret-key can be represented as a uniformly random string of bits, where the length is chosen by the user. Say we use a key of length , then how many possible keys are there? The first bit is either or , so two options. The second bit is either or too, so two more options on top of each of these two options, leading to four options, and so on. It is easy to get convinced that the number of possible keys is . Hence, the number of keys grows exponentially with .
Now say I am trying to guess your secret key. Since all the bits are uniformly random, we get that they are all equally likely, so that the probability I guess correctly (no matter how I guess) is one in , that is, which is also commonly written as . So since the possible number of keys grows exponentially (and the keys are uniform), then the probability to guess a key decays exponentially.
To be more concrete, we say that is exponential if there is some constant such that where is the infamous . Why and not any other number? Because it is comfortable. The fact is that for any number there is a number such that . (This number is called the natural logarithm of , denoted , and we will discuss it shortly.) So you can replace with any positive number larger than and obtain a completely equivalent definition.
Exercise: Let , let satisfy that there is some such that , prove that is exponential.