Questions tagged [memoization]

In computing, memoization is an optimization technique used primarily to speed up computer programs by having function calls avoid repeating the calculation of results for previously-processed inputs.

In computing, memoization is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.

This tag should be used for programs that are using memoization.

Source

Wikipedia

1491 questions
-1
votes
2 answers

What is a common approach to memoize or not React components?

Let's say i have a component like this const AngelsList = ({ angels, ...otherProps }) =>
{ angels.map(angel => ) }
// some other…
Dmitry Reutov
  • 2,995
  • 1
  • 5
  • 20
-1
votes
2 answers

Memoization Practice

I am working on memoization practice in Python. The first 4 calls for the recursive function were solved immediately, but the final call takes too long to compute which is what I am trying to memoize. The output for my attempted memoized code solved…
-1
votes
1 answer

Solving multiple formulas using recursion

I have to use recursion to compute the value of the following formulas: m = 1.4 *t + 1.2*z + 0.8*l + 0.1*o o = 1.0 *g + 1.3 *g + 1.3 *f + 0.2 *t t = 0.9*g + 0.9 *f l = 1.8 *t + 1.7 *g + 0.7 *o With f= 1.4, z= 1.7, g= 1.9 I'm not sure how should…
Baha
  • 56
  • 7
-1
votes
2 answers

Runtime Error - can only concatenate list (not "int") to list

I've been doing 0-1 Knapsack problem using recursion+memoization. My Code: def knapSack(W, wt, val, n): ''' :param W: capacity of knapsack :param wt: list containing weights :param val: list containing corresponding values …
-1
votes
1 answer

Why is memoization giving the wrong output?

I am tryna solve a question using recursion+memoization. It is just modified Fibonacci with an additional start+3 step that can be done only K times. This is the recursive code I came up with: #include using namespace std; int…
P.K.
  • 379
  • 1
  • 4
  • 16
-1
votes
1 answer

Why my memoization code written in c not working?

#include #include int memo[100]; Below is the function in which memoization is used. I am trying to store the return value of redundent recursive calls in memo[n] array at the nth position. int rec(int n){ if(n<=2) …
-1
votes
2 answers

Knapstack implementation in c++ using memoization

What is the difference between doing int t[102][1002] = {-1}; vs running a for loop and doing for(int i = 0; i < 102; i++) for(int j = 0; j < 1002; j++) t[i][j] = -1; The code below does not work when the former method is used.…
-1
votes
3 answers

How can I improve my code for calculating the Nth row of Pascals Triangle while using Memoization and Recursion?

I've been revising recursion and decided to use it to calculate rows of Pascals Triangle. I've successfully created a function that generates Pascals Triangle which works for n <= 7 however it is incredibly inefficient. I am aware of the identity…
-1
votes
1 answer

Implementing memoize pattern in JavaScript for multiple values

I'm trying to play a bit and implementing a memoization pattern for multiple values using JavaScript. I managed to write the code for single value: var lazy = {}; lazy.memoization = evaluator => { const cache = new Map; return key => { …
SimonD
  • 1,441
  • 2
  • 18
  • 30
-1
votes
1 answer

Memoizing Recursive Class Instances that use Scipy Optmize

I am using Python 2.7, and have a program that solves a recursive optimization problem, that is, a dynamic programming problem. A simplified version of the code is: from math import log from scipy.optimize import minimize_scalar class vT(object): …
profj
  • 311
  • 3
  • 10
-1
votes
2 answers

How to copy an object if (and only if) it has a copy constructor?

Context: I'm trying to memoize an object of a template class. Right now, the class is a deeply nested data structure full of unique pointers, and so doesn't have a copy constructor (and so would be impossible to cache, as far as I know). However,…
-1
votes
2 answers

C++ memoization - Fibonacci function - map verus vector container execution time

I'm trying to learn memoization in C++ and have implemented two Fibonacci functions using map and vector. I've submitted them to the Coursera data structures course. The vector implementation fails due to taking too much time and the map passes OK.…
samsung gather
  • 583
  • 1
  • 4
  • 8
-1
votes
2 answers

Why is an instance variable used instead of a local variable in a module?

I saw this code for a Ruby on Rails application: module SessionsHelper def current_user @current_user ||= User.find_by id: session[:user_id] end ... end Why is an instance variable used instead of a local variable in current_user method?…
Trần Hồng
  • 91
  • 2
  • 10
-1
votes
1 answer

typescript async await operators promises and memoization pattern

I'm trying to modernize some of my code with latest TypeScript enhancements. We have a lot of memoization patterns in place. The idea is that some services have multiple subscribers and we want to make sure everybody waits on one call and doesn't…
baywet
  • 4,377
  • 4
  • 20
  • 49
-1
votes
1 answer

Solving sub-problems

When do I choose memoization over dynamic programming? They both seem to possess identical time and space complexity. What then would be the rules of thumb to prefer one over the other?
IUnknown
  • 9,301
  • 15
  • 50
  • 76