KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is the most elegant way to implement dynamic programming algorithms that solve problems with overlapping subproblems ? In imperative programming one would usually create an array indexed (at least in one dimension) by the size of the problem, and then the algorithm would start from the simplest problems and work towards more complicated once, using the results already computed. The simplest example I can think of is computing the Nth Fibonacci number: int Fibonacci(int N) { var F = new int[N+1]; F[0]=1; F[1]=1; for(int i=2; i<=N; i++) { F[i]=F[i-1]+F[i-2]; } return F[N]; } I know you can implement the same thing in F#, but I am looking for a nice functional solution (which is O(N) as well obviously).
Tags (comma-separated)
Save Edits
Cancel