memoization

What is memoization?

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? ...

Memoization in static Objective-C class

Say I have a class method like + (double)function:(id)param1 :(id)param2 { // I want to memoize this like... static NSMutableDictionary* cache = nil; // // test if (param1,param2) is in cache and return cached value, etc. etc // } Thanks!! ...

Haskell caching results of a function

I have a function that takes a parameter and produces a result. Unfortunately, it takes quite long for the function to produce the result. The function is being called quite often with the same input, that's why it would be convenient if I could cache the results. Something like let cachedFunction = createCache slowFunction in (cachedFu...

In-Database Memoization - a good idea? Any experiences?

Hi All, I have an idea I have yet to implement, because I have some fear I may be barking up the wrong tree... mainly because Googling on the topic returns so few results. Basically I have some SQL queries that are slow, in large part because they have subqueries that are time-consuming. For example, they might do things like "give me...

Functional languages & support for memoization

Do any of the current crop of popular functional languages have good support for memoization & if I was to pick one on the strength of its memoisation which would you recommend & why? Update: I'm looking to optimise a directed graph (where nodes could be functions or data). When a node in the graph is updated I would like the values of ...

What would be the time complexity of counting the number of all structurally different binary trees?

Using the method presented here: http://cslibrary.stanford.edu/110/BinaryTrees.html#java 12. countTrees() Solution (Java) /** For the key values 1...numKeys, how many structurally unique binary search trees are possible that store those keys? Strategy: consider that each value could be the root. Recursively find the size of the le...

Tail-recursive pow() algorithm with memoization?

I'm looking for an algorithm to compute pow() that's tail-recursive and uses memoization to speed up repeated calculations. Performance isn't an issue; this is mostly an intellectual exercise - I spent a train ride coming up with all the different pow() implementations I could, but was unable to come up with one that I was happy with t...

Is something along the lines of nested memoization needed here?

System.Transactions notoriously escalates transactions involving multiple connections to the same database to the DTC. The module and helper class, ConnectionContext, below are meant to prevent this by ensuring multiple connection requests for the same database return the same connection object. This is, in some sense, memoization, altho...

C# Memoization of functions with arbitrary number of arguments

I'm trying to create a memoization interface for functions with arbitrary number of arguments, but I'm failing miserably I feel like my solution is not very flexible. I tried to define an interface for a function which gets memoized automatically upon execution and each function will have to implement this interface. Here is an example w...

Arrays in scheme / Memoization

How can I use arrays in scheme? In particular, I'm attempting to implement a recursive fibonacci procedure using memoization. Do arrays even exist in scheme? If not, how can I implement memoization? ...

Project Euler #14 and memoization in Clojure

As a neophyte clojurian, it was recommended to me that I go through the Project Euler problems as a way to learn the language. Its definitely a great way to improve your skills and gain confidence. I just finished up my answer to problem #14. It works fine, but to get it running efficiently I had to implement some memoization. I could...

Computing map: computing value ahead of time

I have a computing map (with soft values) that I am using to cache the results of an expensive computation. Now I have a situation where I know that a particular key is likely to be looked up within the next few seconds. That key is also more expensive to compute than most. I would like to compute the value in advance, in a minimum-pr...

How can memoization be applied to this algorithm?

After finding the difflib.SequenceMatcher class in Python's standard library to be unsuitable for my needs, a generic "diff"-ing module was written to solve a problem space. After having several months to think more about what it is doing, the recursive algorithm appears to be searching more than in needs to by re-searching the same area...

What is memoization good for and is it really all that helpful?

There are a few automatic memoization libraries available on the internet for various different languages; but without knowing what they are for, where to use them, and how they work, it can be difficult to see their value. What are some convincing arguments for using memoization, and what problem domain does memoization especially shine...

Memoization Handler

Is it "good practice" to create a class like the one below that can handle the memoization process for you? The benefits of memoization are so great (in some cases, like this one, where it drops from 501003 to 1507 function calls and from 1.409 to 0.006 seconds of CPU time on my computer) that it seems a class like this would be useful. ...

Memoization & Project Euler Problem 15 in Haskell

I've been learning some Haskell, and doing project Euler problems as I go. I'm not really bothered about the answer to the Euler Problem (which I can happily brute force, or do it in some other language), but the method. I'm stuck on doing Problem 15 in reasonable time. It asks for the number of non-backtracking routes from top-left to ...

Combine memoization and tail-recursion

Is it possible to combine memoization and tail-recursion somehow? I'm learning F# at the moment and understand both concepts but can't seem to combine them. Suppose I have the following memoize function (from Real-World Functional Programming): let memoize f = let cache = new Dictionary<_, _>() (fun x -> match cache.Try...

Lisp style question: memoization (caution: contains the solution for project euler #14)

Hello, I am just trying to learn some Lisp, so I am going through project euler problems. I found problem no. 14 interesting (so if you are planning to solve this problems stop reading now, because I pasted my solution at the bottom). With my algorithm it was so slow, but after using memoization (I copied the function from Paul Graham's...

Caching function results in PHP

I'm making a simple tool to cache function results It look like: global $function_results; $function_results = array(); function getMembers($conditions, $default = array('order' => 'name', array('abc', 'def'))){ //****Help need from here****** //make unique id from parameters value and function name //ex: $uid; //****...

In Scala 2.8, what type to use to store an in-memory mutable data table?

Each time a function is called, if it's result for a given set of argument values is not yet memoized I'd like to put the result into an in-memory table. One column is meant to store a result, others to store arguments values. How do I best implement this? Arguments are of diverse types, including some enums. In C# I'd generally use Da...