Dynamic Programmingο
Dynamic Programming is often presented as a challenging mathematical formulation. Because of its mathematical abstraction, it can be off putting. And yet itβs an awesome and very useful algorithmic strategy, worth exploring and appreciating.
Consider a collection (a set, if you like) of π items. Each item has a value π£π and a weight π€π . Here, 1β€πβ€π . The contrived example used in most textbooks, is the collection of artifacts in a museum. Is there a combination of some museum items whose total weight does not exceed a limit and their total value is the most of any such combination we could think of?
Of course, no one writes algorithms because they want to plan a museum heist. The problem exemplified above, in terms of questionable morality, belongs to a broader group of optimization problems under constraints. In the case of the museum heist, we try to optimize the value of what we can take within the weight limit of what we can carry.
Without a weight limit, we can take everything. But when we impose a weight limit, πΏ , we must consider only the combination of items that maximize value while complying with the limit condition.