Memoization Flashcards

1
Q

What is memoization?

A

It’s a technique where the results of expensive function calls are cached and returned when the same inputs occur again.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you implement memoization in JavaScript?

A

You can store the results of a function call in a cache object and return the cached value if the same inputs are encountered again.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a cache object in memoization?

A

It’s a data structure used to store previously computed results of a function. It can be implemented using a plain JavaScript object or a Map object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the benefit of using memoization?

A

It can significantly improve the performance of functions that are called with the same inputs repeatedly, by avoiding expensive computations and returning cached results instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a potential downside of using memoization?

A

It can consume more memory if the cache object grows too large, especially if the function being memoized accepts many different input values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly