0% found this document useful (0 votes)
9 views13 pages

Module - 4 - Part1

Uploaded by

austindsouza052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views13 pages

Module - 4 - Part1

Uploaded by

austindsouza052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Don Bosco Institute of Technology

Advanced Data structure and Analysis

Module 4: Dynamic Algorithms

Prof. Prasad Padalkar


Topics

● Introduction to Dynamic Algorithms


○ 0/1 Knapsack
○ All pair shortest path
○ Travelling Salesman problem
○ Matrix Chain Multiplication
○ Optimal Binary Search tree
Introduction to Dynamic Algorithms
● Dynamic programming is an algorithmic paradigm that divides broader
problems into smaller subproblems and stores the result for later use,
eliminating the need for any re-computation.
● If the problem abides by properties given below, only then it can be solved
using a dynamic programming paradigm:
○ Optimal Substructure: A problem is said to have an optimal substructure if we can formulate
a recurrence relation.
○ Overlapping Subproblem: A problem has an optimal substructure if we can formulate a
recurrence relation for it.
Introduction to Dynamic Algorithms
Consider Fibonacci (20) (i.e.
20th Fibonacci term).

F(n) = F(n-1) + F(n-


2),
Introduction to Dynamic Algorithms
Two patterns of solving dynamic programming (DP) problems:
Tabulation: Bottom Up

Memoization: Top Down


Introduction to Dynamic Algorithms
Factorial of a number
using a bottom-up
approach:-

In Bottom-up approach
as it starts its transition
from the bottom-most
base case dp[0] and
reaches its destination
state dp[n]
Introduction to Dynamic Algorithms
Introduction to Dynamic Algorithms

Memoization Method – Top-


Down Dynamic Programming
Introduction to Dynamic Algorithms
0/1 knapsack
For the given set of items and knapsack
capacity = 5 kg, find the optimal solution
for the 0/1 knapsack problem
0/1 knapsack
Time Complexity of 01 Knapsack K(3,3)

Formation of the recurrence relation :


K(2,2) K(2,3)
K(n,w) = K(n-1, w - wn) + P
K(n-1, w)
K(1,1) K(1,2) K(1,2) K(1,3)

If we follow brute force principle


for recursive approach then K(0,0) K(0,1)
T(n) = 2(n+1) - 1 ⇒ O(2^n)

But with dynamic programming Continue similarly to complete the tree


due to repetition of sub-problem
we reduce T(n) = O(n.w)
Thank you

You might also like