Check out a free preview of the full A Practical Guide to Algorithms with JavaScript course:
The "Memoization with Recursion" 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:

Binca reviews memoization and recursive approach to the "make change" problem.

Get Free Access Now

Transcript from the "Memoization with Recursion" Lesson

>> Bianca Gandolfo: So how does our makeChange brute force solution change? [LAUGH] How does it change, how does it make change? The only difference really is that you're just caching it, right? So this here, this should also be a red flag, we talked about this, this is global cache, we don't really want that.

[00:00:21] But to focus on the makeChange algorithm specifically, and not wasting a lot of time talking about memoization techniques that we mentioned earlier on how to make this better. The only change here is that we're gonna see, if it's already cached, we return it. So what this does is, as you're making these recursive calls, you're gonna short-circuit it each time.

[00:00:46] And then, what else, yeah, that's pretty much it, yeah, you just need to make sure that you cache it every time. So there's two main differences there. And then of course, you can more responsibly memoize this as well by just passing it to your memoize function. Or even just adding your cache inside of your makeChange and returning a function like we did before.

[00:01:19] And passing in the coins, so that you're not relying on this exterior data. You don't wanna hard-code it, you wanna just pass it in as arguments, it's better.