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

Speeding up solution to algorithm

Working on the following algorithm: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able…
segue_segway
  • 1,490
  • 1
  • 22
  • 40
-1
votes
2 answers

Implementing memoization in recursive code break functionality

I can't seem to figure out what broke my code. I wrote a code that takes a pyramid: [[1], [2,3], [4,5,6], [7,8,9,10]] Starting from the head (pyramid[0][0]) calculates the maximum sum possible to achieve by moving to either the item below, or…
-1
votes
1 answer

Which is more expensive in terms of memory and speed Lists or dictionaries in Python

I am testing memoization code on my computer. I have arrays of range 100000. With the following code. def fact1(n): if n<1: return 1 else: fa=1 for i in range(1, n+1): fa*=i return fa Using memoization…
Annapoornima Koppad
  • 1,376
  • 1
  • 17
  • 30
-1
votes
1 answer

What's wrong in this recursive algorithm?

Problem statement: An N-element permutation is an N-element sequence of distinct numbers from the set {1, 2, ...,n}. For example the sequence 2,1,4,5,3 is a 5-element permutation. P is an N-element permutation. Your task is to sort P in ascending…
Saksham
  • 197
  • 3
  • 11
-1
votes
1 answer

Runtime complexity of recursive memoized solution for boolean parenthesization

This is a classic algorithm problem. The DP solution is indeed n^3. I'm using recursion with memoization below. I need some detailed explanation of what is the runtime of the code below? I'm not satisfied with the current answer. Can someone help?…
-1
votes
2 answers

Can anyone Explain what is memoization?

The following stats are Fibonacci function call stats Here are some Stats I got after running profiler [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765] 57358 function calls (68 primitive calls) in 0.211…
Dlucidone
  • 1,091
  • 9
  • 23
-1
votes
2 answers

calculating catalan numbers using memoization

I am tring to use memoization in order to calculate catalan numbers, but it just does not seem to work, what do I need to change? def catalan_mem(n, memo = None): if n==0: return 1 if memo == None: memo = {} b=0 if n…
shaked
  • 87
  • 1
  • 4
-1
votes
1 answer

Implementation details of memoizing procedure from Tcl wiki

I am currently trying to understand the implementation details of the following memoizing procedure as shown in several variants in the Tcl wiki: proc memoize {} { global memo set cmd [info level -1] if {[info level] > 2 && [lindex [info…
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
-1
votes
1 answer

wrong output for memoization solution of knapsack issue

I need to solve the knapsack problem recursively, memoized and with dynamic programming. Currently I'm stuck at the memoized method (and partially the dynamic programming method). I adapted the code from what I found elsewhere on the internet.…
enenra
  • 111
  • 1
  • 11
-1
votes
1 answer

Memoization in javascript to prevent repeat

I was looking into memoization and it simply confuses me. I've been trying to work on this example but I can't help but understand it quite clearly. This is what I came up with. function memoize(x) { //var x = [] check = function() { …
stoiven
  • 31
  • 7
-1
votes
5 answers

Recursive solution for 3n+1

I just like to do simple recursion. For a number if it is even then it'll approach to (number/2) and if odd then to (3*number+1). How many time it'll occur to reach 1. for 10 10-> 5-> 16-> 8-> 4 -> 2 ->1 total process 6 long arr[10000]; long…
LogicalAnt
  • 907
  • 3
  • 12
  • 28
-1
votes
1 answer

Weird speed results for memoized fibonacci function in Javascript

I put together simple memoization example and run few performance tests but do not understand why on Chrome memTestHalfAssed is the fastest, even though fibonacciH calls inside are not memoized. Tests are at http://jsperf.com/moize-test function…
spirytus
  • 10,726
  • 14
  • 61
  • 75
-1
votes
2 answers

What Makes the Code Faster

Originally I was testing out how adding some codes that caches the result will impact the initial calculation time. I create a simple recursive function that calculates factorials: function fac(n){ return n <= 1 ? 1 : fac(n-1) * n; } Then I add…
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
-1
votes
2 answers

finding the min number of moves by greedy algorithm

There is a 2-d grid which contains chocolates in random cells.In one move ,i can take all the chocolates contained in one row or in one column.What will be the minimum number of moves required to take all the chocolates? Example:cells containing…
RKTSP
  • 99
  • 1
  • 8
-1
votes
3 answers

count number of basketball plays when given the final score

Given the final score of a basketball game, how i can count the number of possible scoring sequences that lead to the final score. Each score can be one of: 3 point, 2 point, 1 point score by either the visiting or home team. For…
eli
  • 490
  • 1
  • 3
  • 22