What is the log function? It's a function that we will use to help describe the complexity of many different algorithms in this class, so we should understand something about it.

Let's start by plotting one version, the log "base 2." We'll also plot a version that's rounded down (or "floored") to the nearest integer

As we can see, it's a function that starts at 0 and grows very slowly. We can define it more precisely as a function that returns how many factors of 2 go into into our number (calc students will know another definition, but this is fine for our purposes).

Actually, this leads to a very nice "programmatic" definition of this function: keep dividing our number by 2 until we get to 1, and count how many times that took. Or we can think spatially about dividing a stick in half repeatedly until we get a chunk of length 1.

Let's do something like this now in code

For example, if I gave the number 5 and I did these floor divisions, I'd get the sequence

Just as a sanity check, let's plot this against what numpy's floored version gives us

That's basically all you need to know about the log for this class!

Just one more note that another way to define the log is as the "inverse" of the exponential. So log base 2 of x is the inverse of 2 raised to the x power. Let's plot these next to each other

What we see spatially is that $2^x$ is a reflection of $\log_2(x)$ about the line $y=x$. What this means (and which we can see intuitively) is that while the log grows very slowly, the exponential grows very quickly. We're going to want to try to avoid algorithms whose complexity scales as an exponential at all costs in this class!