DEV Community

Cover image for Dynamic Programming
Federico Diaz Aguirre
Federico Diaz Aguirre

Posted on

2 1 1

Dynamic Programming

Context

When facing recursive problems we quickly identify the memorization enhancement to avoid wasting cycles for past computations. But what about the underlying implementations top-down vs bottom-up?

In the video below I am comparing these two. And the drawbacks of using BFS in this particular case:

  1. Higher memory usage due to maintaining a queue and a visited set.
  2. Worse than DP for large amount values (since BFS explores level by level, it can be slow for high values).

Summary

Visual representation

Image description

Comparisson

Approach Time Complexity Space Complexity Notes
Recursive DP (Top-Down w/ Memoization) O(amount × len(coins)) O(amount) Efficient, but recursion uses stack memory
Iterative DP (Bottom-Up) O(amount × len(coins)) O(amount) Best for dense subproblem coverage
BFS (Graph Traversal) O(amount × len(coins)) (Worst case) O(amount) Can be more efficient for small values

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now

👋 Kindness is contagious

Value this insightful article and join the thriving DEV Community. Developers of every skill level are encouraged to contribute and expand our collective knowledge.

A simple “thank you” can uplift someone’s spirits. Leave your appreciation in the comments!

On DEV, exchanging expertise lightens our path and reinforces our bonds. Enjoyed the read? A quick note of thanks to the author means a lot.

Okay