Dynamic Programming
Dynamic Programming
“The definition of dynamic programming says that it is a technique for solving a complex
problem by first breaking into a collection of simpler subproblems, solving each subproblem
just once, and then storing their solutions to avoid repetitive computations.”
The main use of dynamic programming is to solve optimization problems. Here, optimization
problems mean that when we are trying to find out the minimum or the maximum solution
of a problem.
o Top-down approach
o Bottom-up approach
Top-down approach
The top-down approach follows the memorization technique, while bottom-up
approach follows the tabulation method.
Advantages
Bottom-Up approach
The bottom-up approach is also one of the techniques which can be used to
implement the dynamic programming. It uses the tabulation technique to implement
the dynamic programming approach
This problem is solved by using tabular method, so we draw a table contain all
vertices(v), cost(c) and destination(d).
Formula-
1.Cost(stage number , vertex).
2. Cost(v, d) + cost(Stage+1, vs) where vs is vertex of the stage.
All-Pairs Shortest Paths
The all-pair shortest path algorithm is also known as Floyd-Warshall algorithm
is used to find all pair shortest path problem from a given weighted graph. As a
result of this algorithm, it will generate a matrix, which will represent the
minimum distance from any node to all other nodes in the graph.
For example, the weight of the container is 20 kg. We have to select the items in such
a way that the sum of the weight of items should be either smaller than or equal to
the weight of the container, and the profit should be maximum.
Problem Statement
A traveler needs to visit all the cities from a list, where distances between all the cities are
known and each city should be visited just once. What is the shortest possible route that he
visits each city exactly once and returns to the origin city?
Solution
Travelling salesman problem is the most notorious computational problem. We can use brute-
force approach to evaluate every possible tour and select the best one. For n number of
vertices in a graph, there are (n - 1)! number of possibilities.
Sum of Subsets Problem: Given a set of positive integers, find the
combination of numbers that sum to given value M.