Transcript from the "Reviewing Optimization" Lesson

[00:00:00]

>> Bianca Gandolfo: So in this section we talked about a couple different techniques for caching. And the things that you should keep in mind when using this technique is that you are trading time complexity for space complexity. So for each operation you are saving the value, and so you're creating a new data structure and adding a new value to that every time.

[00:00:28] And so you're increasing the space complexity while minimizing the time complexity, and this is really important when your function calls or any operation is expensive. And so usually that trade-off is fine. Often in interviews people joke like, there's this optimization question, how do we optimize? And there's a joke, I mean, a joke.

[00:00:49] I don't know if people really joke about interviews or algorithms with people, the thing that people always say is, you just use a hash table. This is us using a hash table. When they say use a hash table to optimize, this is really what they mean. In JavaScript, an object is essentially a hash table.

[00:01:09] And in our future course we'll talk in depth about hash tables, we'll make our own hash tables and all of that. But for what you really need to know in the real world, when they say, optimize it by adding like using a hash table, this is that technique where we're adding things to a cache, which is really just an object.

[00:01:27] And there are different ways of going about it, but it's all the same concept, which is how do we take an expensive operation and turn it into constant time or at least linear time? And that is by using a hash table.