Group 55-1
Group 55-1
GROUP_5
Dynamic Programming
• Dynamic Programming (DP) is an algorithmic technique for
solving an optimization problem by breaking it down into
simpler sub problems and utilizing the fact that the optimal
solution to the overall problem depends upon the optimal
solution to its sub problems.
• Dynamic programming approach is similar to divide and
conquer in breaking down the problem into smaller and yet
smaller possible sub-problems. But unlike, divide and
conquer, these sub-problems are not solved independently.
GROUP_5
Dynamic Programming
The following are the steps that the dynamic programming
follows:
• It breaks down the complex problem into simpler sub problems.
• It finds the optimal solution to these sub-problems.
• It stores the results of sub problems.
• The process of storing the results of sub problems is known as
memorization.
• It reuses them so that same sub-problem is calculated more than
once.
• Finally, calculate the result of the complex problem.
GROUP_5
Divide-and-conquer
Divide-and-conquer method for algorithm design:
• Divide: If the input size is too large to deal with in a
straightforward manner, divide the problem into two or more
disjoint subproblems.
• Conquer: Conquer recursively to solve the subproblems.
• Combine: Take the solutions to the subproblems and
"merge" these solutions into a solution for the original
problem.
GROUP_5
Divide-and-conquer - Example
• For example, MergeSort
all different.
GROUP_5
Difference between DP and Divide- and-
Conquer
• Using Divide-and-Conquer to solve these problems is
inefficient because the same common subproblems have to be
solved many times.
• DP will solve each of them once and their answers are stored
in a table for future use.
GROUP_5
Dynamic Programming vs Divide &
Conquer
Divide & Conquer Dynamic Programming
Partitions a problem into independent Partitions a problemi into overlapping sub-
smaller sub-problems. problems.
Doesn't store solutions of sub- problems. Stores solutions of sub- problems: thus
(Identical sub-problems may arise results avoids calculations of same quantity twice
in the same computations are performed
repeatedly.)
GROUP_5
Approaches of Dynamic Programming
There are two approaches to dynamic programming:
➤ Top-down approach
➤ Bottom-up approach
Top-down approach:
The top-down method solves the overall problem before you
break it down into sub problems. This process works to solve
larger problems by finding the solution to sub problems
recursively, caching each result.
GROUP_5
Approaches of Dynamic Programming
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. It solves the same kind of problems
but it removes the recursion.
• If we remove the recursion, there is no stack overflow issue
and no overhead of the recursive functions. In this tabulation
technique, we solve the problems and store the results in a
matrix.
GROUP_5
Example
The following computer problems can be solved using
dynamic programming approach.
➤ Fibonacci number series
➤ Knapsack problem
➤ Tower of Hanoi
➤ All pair shortest path by Floyd-Warshall
➤ Shortest path by Dijkstra
➤ Project scheduling
GROUP_5
Advantages of Dynamic Programming
• Dynamic programming can be used to obtain local as well as
the total optimal solution.
GROUP_5
Disadvantages of Dynamic Programming
• Dynamic programming uses recursion, which requires more
memory in the call stack, and leads to a stack overflow
condition in the runtime.
GROUP_5
Thank You