Dynamic Programming: An Approach to Solving Computing Problems

Sometimes in computer science, you will run into problems. You can divide these into subproblems, which can, in turn, be divided into smaller subproblems. If the smaller subproblems overlap, then you can save the result in memory for future reference. This way, you don’t need to compute the same result multiple times, thus increasing the efficiency of the program substantially. This way of solving these problems is referred to as dynamic programming.

Dynamic Programming – Learn to Solve Algorithmic Problems & Coding Challenges. | Video: freeCodeCamp.org

In this article, you will learn what dynamic programming is. I will also show how to compute Fibonacci numbers, which is a simple problem that dynamic programming can solve. I will compare the dynamic programming solutions to the naive solution that uses recursion. These examples are written in Python syntax. Finally, I’ll also give some general pointers to keep in mind when attempting to solve problems using dynamic programming

Dynamic programming

Dynamic programming is an efficient method for solving computing problems by saving solutions in memory for future reference. When you have overlapping subproblems, you can apply dynamic programming to save time and increase program efficiency. 

More From Artturi Jalli: Python Cheat Sheet: A Handy Guide to Python


What Types of Problems Can Dynamic Programming Solve?

Dynamic programming is typically a way to optimize solutions to certain problems that use recursion. If a recursive solution to a problem has to compute solutions for subproblems with the same inputs repeatedly, then you can optimize it through dynamic programming. As mentioned earlier, in this case, you would simply save the result of the computation for use later if and when it’s needed. This optimization can reduce the time complexity of an algorithm from exponential time to polynomial time. This means that the number of computations n scales like a polynomial expression instead of scaling like an exponential expression as n increases. In general, polynomial expressions grow much slower than exponential expressions.

There are two conditions that need to be satisfied to use dynamic programming:

  1. Overlapping subproblems
  2. Optimal substructure property


What Are Overlapping Subproblems?

I alluded to

Read More... Read More

Gatsby makes a new approach to web development easy

Commentary: Jamstack’s modern approach to web development used to come with a caveat. With Gatsby 4, that caveat is gone.

Image: NDAB Creativity/Shutterstock

Must-read developer content

So much of what we consider enterprise software today was once derided as hobbyist toys. Though it’s not exclusively an open source phenomenon, it’s perhaps most obvious in open source projects like Linux or MySQL, which seem so inappropriate for serious enterprise use at first, then grow to become defaults for enterprise use. Something similar is happening in web development. 

SEE: The best programming languages to learn–and the worst (TechRepublic Premium)

Not so long ago, static site generator (SSG) frameworks like open source Gatsby were considered limited to simple applications like blogs or documentation sites. The problem was performance. SSGs were lightning fast because they rendered websites as files, but that speed broke down once a website moved beyond 10 to 1,000 pages and scaled to 10,000 or 100,000 pages. Suddenly the compilation process got really slow. 

Well, that was then, and this is now.

Projects like Gatsby increasingly challenge the notion that enterprises would need, much less want, a heavy-duty, all-in-one-but-master-of-none CMS like WordPress or Sitecore. Not when they can get best-of-breed: a headless CMS like Contentful as a back-end, API-driven content store; Stripe for payments, Gatsby for front-end presentation, etc. Indeed, this relatively new Jamstack approach may be setting a new standard for web development. Perhaps most importantly for developers, with Gatsby 4, there’s no longer a need to bet on SSG over server-side rendering (SSR). With Gatsby 4, you can have both.

Start small, go big

But that’s not where developers start. The world has lived in traditional CMSes for so long that developers will usually turn to something like WordPress for their work projects. WordPress, for example, is the CMS behind 39.6% of websites. When developers build for fun, however, they look to something like Gatsby, an open source framework for building websites with React. Gatsby is also the name of the company that does most of the development on the project, while also offering a cloud service to

Read More... Read More