Check out a free preview of the full A Practical Guide to Algorithms with JavaScript course

The "Reviewing Optimization" Lesson is part of the full, A Practical Guide to Algorithms with JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Bianca wraps up discussing the different caching techniques by reviewing the trade-off between time complexity and space complexity.


Transcript from the "Reviewing Optimization" Lesson

>> 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.

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.

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.

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.

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.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now