The document presents an overview of dynamic programming, highlighting its significance in solving optimization problems through a bottom-up approach. Key characteristics include optimal substructure and overlapping subproblems, illustrated with examples like the Fibonacci series and shortest path problems. It also explains techniques for storing results in memory, specifically memoization and tabulation, along with performance comparisons in calculating Fibonacci numbers.
University Visvesvaraya CollegeOf Engineering,
Bengaluru-01
TOPIC
ON
ELEMENTS OF DYNAMIC PROGRAMMING
Presented by
VISHWAJEET SHABADI
20GACS2014,
Branch: Information Technology,
UVCE, Bengaluru.
Under The Guidance of
Dr. Venkatesh
Professor,
Dept. of CSE,
UVCE, Bengaluru.
2.
INTRODUCTION OF DYNAMICPROGRAMMING
• Dynamic Programming is the most powerful design technique
for solving optimization problems. Example: Matrix Chain
Multiplication.
• Dynamic Programming is a Bottom-up approach.
• We typically apply dynamic programming to optimization
problems.
3.
CHARACTERISTICS OF DYNAMICPROGRAMMING
• Optimal Substructure: If an optimal solution contains
optimal sub solutions then a problem exhibits optimal
substructure. Example: Bellman-Ford
• Overlapping subproblems: When a recursive algorithm
would visit the same subproblems repeatedly, then a
has overlapping subproblems. Example: Fibonacci
Series
4.
OPTIMAL SUBSTRUCTURE
• Agiven problems has Optimal Substructure Property if optimal
solution of the given problem can be obtained by using optimal
solutions of its subproblems.
• The Shortest Path problem has following Optimal Substructure
property:
If a node x lies in the shortest path from source node u to destination
node v then, the shortest path from u to v is the combination of shortest
path from u to x and shortest path from x to v.
• All Pair Shortest Path
5.
ON THE OTHERHAND
• The Longest path problem doesn’t have the Optimal Substructure
property.
• Here, by Longest Path we mean longest simple path(path without
cycle) between two nodes.
• Longest paths from q to t:
q -> r -> t
q -> s -> t
• Longest path from q to r:
q -> s -> t -> r
• Longest path from r to t:
6.
OVERLAPPING SUBPROBLEMS
• DynamicProgramming is mainly used when solutions of same
subproblems are needed again and again.
• If we take an example of following recursive program for Fibonacci
Numbers, there are many subproblems which are solved again and
again.
7.
USE MEMORY
• “Rememberthe results.”
• Do not solve the same problem again, just recall it from
• Two methods of storing the results in memory:
Memoization
Tabulation
8.
MEMOIZATION
• Initialize alookup array/table with all its elements as NIL.
NIL is simply a constant value, that signifies absence of a solution.
• Call the recursive function f(n) to solve for ‘n’ using memoization.
9.
MEMOIZATION
• At everystep i, f(i) performs the following steps:
1. Checks whether table[i] is NIL or not.
2. If it’s not NIL, f(i) returns the value ‘table[i]’.
3. If it’s NIL and ‘i’ satisfies the base condition, we update the lookup table with
the base value and return the same.
4. If it’s NIL and ‘i’ does not satisfy the base condition, then f(i) splits the
problem ‘i’ into subproblems and recursively calls itself to solve them.
5. After the recursive calls return, f(i) combines the solution to subproblems,
update the lookup table and returns the solution for problem ‘i’.
TABULATION
• STEPS
a. Webegin with initializing the base values of ‘i’.
b. Next, we run a loop that iterates over the remaining
c. At every iteration i, f(n) updates the ith entry in the
by combining the solutions to previously solved
d. Finally, f(n) returns table[n].