36: Logarithms. It’s How Our Bodies Work.
Take Up Code - En podcast af Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes
Kategorier:
Have you ever thought about why you can’t see stars during the day? Do they somehow know when to dim themselves? How about why car headlights are so much brighter at night? Or why you can only hear a pin drop in a silent room? Does the pin make less noise just because somebody is talking? All of our body senses are like this. The brighter, or heavier, or louder, or sweeter, or smellier something is, then the more difficult it becomes to distinguish small changes. When a room is very quiet, then we can pick out the small sound that the pin makes. But a loud room needs a louder pin or we just won’t hear it. Our body is logarithmic. This episode will prepare you for the next several episodes where we’re going to start talking about how to store information and which approach to take. Logarithms will help you understand how fast certain operations can be. This is not a math lesson even though you might remember logarithms from a high school math course. I’m not going to make you memorize a bunch of formulas. Just one simple concept. It’s a concept so simple that it matches every one of our body senses. If you can understand that headlights are brighter at night, then you can understand this concept. What’s the one concept you need to know? The logarithm of a number increases much slower than the number itself as the number gets bigger. That’s it. The audio goes into more details about this and gives you some examples. There’s a little multiplication involved but it’s trivial. You can listen to the full episode or read the full transcript below. Transcript Maybe you remember logarithms from high school math classes but that doesn’t matter. We’re not going to study math here. This episode will explain the basic concepts of what logarithms are and how you can use them. The simple answer is that logarithms count multiplications. What does that mean? Well, two times two times two is eight so the logarithm base two of eight is how many times two must be multiplied by itself in order to get eight. This is three. The important point for this discussion is that 3 is less than 8. In general, the logarithm of a number is usually much less than the number itself. You can see this if we take it further. Try multiplying 2 by itself 8 times and you’ll get 256. So the log base two of 256 is only 8. If we continue this and multiply by 2 another 2 more times, we get 512 and then 1024. So while the number that we’re calculating the log of went from 256 all the way to 1024, the log itself only went from 8 to 10. This is the concept that you need to understand. The log of a number grows much slower than the number as that number increases. The reason this is important is because there are usually multiple approaches you can take when programming a solution to a problem. These different approaches are designed to work best under specific circumstances and knowing when to use one design vs. another could mean the difference between your program taking 10 seconds vs. taking 1024 seconds. If your solution takes one second for each item that it needs to process and you’re looking for just one item out of 1024 items, then it’s going to take up to 1024 seconds. Sure you might be able to speed this up a bit with a faster computer. Maybe you can get it down to just 900 seconds. But knowing this concept of logarithms might give you the clue you need to take a different approach that only needs the log of 1024 in seconds to complete. This solution will then only need 10 seconds. That’s a huge difference that completely leaves even the faster computer far behind. How is it possible that one solution can be so much better than another? Let’s take a simple example of looking up a word in a dictionary. You want to find the word kangaroo. How would you begin? Well you could start on page one and scan through all the words and then go to page two, then three, etc. If