Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
31 views

Dynamic Programming

Dynamic programming is an approach to solve complex problems by breaking them into simpler subproblems, solving each subproblem only once, and storing the solutions to avoid repetitive computations. It is commonly used to solve optimization problems by finding the minimum or maximum solution. The key steps are to break down the problem, find optimal solutions to subproblems, store and reuse subproblem solutions rather than recomputing them, and finally calculate the result. There are top-down and bottom-up approaches, with top-down using memorization and bottom-up using tabulation.

Uploaded by

Ajit Kushwaha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Dynamic Programming

Dynamic programming is an approach to solve complex problems by breaking them into simpler subproblems, solving each subproblem only once, and storing the solutions to avoid repetitive computations. It is commonly used to solve optimization problems by finding the minimum or maximum solution. The key steps are to break down the problem, find optimal solutions to subproblems, store and reuse subproblem solutions rather than recomputing them, and finally calculate the result. There are top-down and bottom-up approaches, with top-down using memorization and bottom-up using tabulation.

Uploaded by

Ajit Kushwaha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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.

How does the dynamic programming approach work?


The following are the steps that the dynamic programming follows:

o It breaks down the complex problem into simpler subproblems.


o It finds the optimal solution to these sub-problems.
o It stores the results of subproblems (memoization). The process of storing the results
of subproblems is known as memorization.
o It reuses them so that same sub-problem is calculated more than once.
o Finally, calculate the result of the complex problem.

Approaches of dynamic programming


There are two approaches to dynamic programming:

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

o It is very easy to understand and implement.


o It solves the subproblems only when it is required.
o It is easy to debug.
Disadvantages

It occupies more memory that degrades the overall performance.

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

Multistage Graph Problem

This problem is solved by using dynamic programming method. Multistage


Graph is a directed weighted graph. All vertices are divided into stages in such a
way that vertex is connected to one edge to another edge.
Note – First stage and Last stage are represented as a single vertex from source
and sink of a graph.

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.

0/1 Knapsack problem


Here knapsack is like a container or a bag. Suppose we have given some items which
have some weights or profits. We have to put some items in the knapsack in such a
way total value produces a maximum profit.

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.

Travelling Salesman Problem

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.

You might also like