If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!
Showing posts with label dynamic programming. Show all posts
Showing posts with label dynamic programming. Show all posts

Wednesday, April 4, 2012

Using breadth-first-search to solve dynamic programming problem

The previous implementation was using depth-first-search and might be improved by switching to breadth-first-search.


Dynamic Programming to the rescue

In my previous blog post I crafted a solution together that created a graph of all possible paths starting from the initial node. Next I filtered out the ones not ending at the goal node. For the paths that were left over I finally calculated the total path cost. As the number of lanes increases you will see that the number of possible paths grows exponentially and my previous code will run into timeouts.

So now i present the same solution but drastically improved using dynamic programming.