Skip to main content
529 votes
15 answers
318k views

I just started Python and I've got no idea what memoization is and how to use it. Also, may I have a simplified example?
blur959's user avatar
  • 5,649
3 votes
2 answers
165 views

When looking up memoization in Haskell, I found this bit of code: memoized_fib :: Int -> Integer memoized_fib = (map fib [0 ..] !!) where fib 0 = 0 fib 1 = 1 fib n = ...
Alfy B's user avatar
  • 167
369 votes
12 answers
153k views

What is the difference between memoization and dynamic programming? I think dynamic programming is a subset of memoization. Is it right?
Sanghyun Lee's user avatar
  • 23.4k
0 votes
1 answer
154 views

I have a mathematical function called in render loop (240Hz). It's a function of some (atomic) state that very rarely changes. It calls 3 times to std::log, twice to std::sqrt, once to std::sin. When ...
Tom Huntington's user avatar
298 votes
20 answers
282k views

Consider the following: @property def name(self): if not hasattr(self, '_name'): # expensive calculation self._name = 1 + 1 return self._name I'm new, but I think the ...
Tobias's user avatar
  • 4,382
234 votes
21 answers
206k views

I have a set of integers. I want to find the longest increasing subsequence of that set using dynamic programming.
Tony's user avatar
  • 2,493
279 votes
10 answers
236k views

The bottom-up approach (to dynamic programming) consists in first looking at the "smaller" subproblems, and then solve the larger subproblems using the solution to the smaller problems. The top-down ...
Guest's user avatar
  • 3,207
146 votes
11 answers
99k views

I'm writing a class in python and I have an attribute that will take a relatively long time to compute, so I only want to do it once. Also, it will not be needed by every instance of the class, so I ...
mwolfe02's user avatar
  • 24.3k
80 votes
15 answers
42k views

Is there a way to memoize the output of a function to disk? I have a function def getHtmlOfUrl(url): ... # expensive computation and would like to do something like: def getHtmlMemoized(url) = ...
seguso's user avatar
  • 2,333
2 votes
2 answers
102 views

I have a simple scenario in which I want to access my store.entities, but only those which are active. I understand the following is bad because a new reference is given each time: const ...
kiwikodes's user avatar
  • 774
0 votes
2 answers
90 views

I have an app with cards. Cards are fetched with useInfiniteQuery from React Query. I fetch new card each time I reach the end of the list. Backend sends offset and limit based responses of this ...
magrega's user avatar
  • 263
1 vote
2 answers
164 views

Problem: Given an array that sums to 0, find the maximum number of partitions of it such that all of them sum up to 0 individually. Example: input: [-2, 4, -3, 5, -4] output: 2 (which are [[5, -2, -3]...
figs_and_nuts's user avatar
0 votes
1 answer
105 views

Just by using the commented code instead of making the recursive calls inside the max function, leads to incorrect result particularly with the following test case int main() { Solution obj = ...
Mohamed Samir's user avatar
0 votes
0 answers
55 views

How can the following recursion + memoization code be converted into a tabulation format dynamic programming solution? The code is working but I want to improve it. The challenge I am facing is ...
Elias El hachem's user avatar
151 votes
8 answers
31k views

Any pointers on how to solve efficiently the following function in Haskell, for large numbers (n > 108) f(n) = max(n, f(n/2) + f(n/3) + f(n/4)) I've seen examples of memoization in Haskell to ...
Angel de Vicente's user avatar

15 30 50 per page
1
2 3 4 5
102