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

15 Dynamic Programming

Notes

Uploaded by

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

15 Dynamic Programming

Notes

Uploaded by

m6gjcrsnjx
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Program: B.

Tech
Course Code: AIML303/AIDS303/IOT303
Course Name: Design & Analysis of Algorithms

Dynamic Programming

By:
Dr. Monika Bansal
What is Dynamic Programming?

•Dynamic Programming (DP) is a method for


solving optimization problems by breaking them
down into simpler subproblems.

•It is used when a problem has overlapping


(dependent) subproblems and an optimal
substructure, meaning the problem can be solved by
combining solutions to smaller problems.
Key Principles of Dynamic Programming

1. Optimal Substructure:
• A problem exhibits optimal substructure if the solution to the problem
can be constructed efficiently from the solutions of its subproblems. i.e.,
best solution can be built from the best solutions to subproblems.

• Example: The shortest path problem has optimal substructure because


the shortest path between two vertices includes the shortest path
between intermediate vertices.

2. Overlapping Subproblems:
• Dynamic programming is used when the same subproblems are solved
multiple times.

• Instead of solving the same subproblem repeatedly, DP solves each


subproblem only once and stores its result in a table, saving computation
time.
Dynamic Programming – Example Problems
1. Matrix Chain Multiplication - Given a sequence of matrices 𝐴1,𝐴2,𝐴3,…,𝐴𝑛.
where: Matrix 𝐴𝑖 has dimensions 𝑝𝑖−1×𝑝𝑖. The task is to determine the optimal order
of matrix multiplications to minimize the total number of scalar multiplications.
2. Fibonacci Sequence - generating a series of numbers in which each number is the
sum of the two preceding ones.
3. 0/1 Knapsack Problem - involves a set of items, each with a specific weight and
value, and a knapsack (bag) with a maximum weight capacity. The goal is to determine
which items to include in the knapsack to maximize the total value without exceeding
the knapsack's weight capacity. The "0/1" aspect of the problem means that each item
can either be included (1) in the knapsack or excluded (0)—there's no partial
inclusion of items allowed.
4. Longest Common Subsequence (LCS) - Given two sequences (or strings), the task
is to find the length and the actual longest subsequence that is present in both
sequences in the same relative order, but not necessarily consecutively.
5. Shortest-Path Problem –All Pair
6. Rod Cutting Problem - maximize the profit obtained by cutting a rod of a given
length into smaller pieces and selling those pieces, where each piece has a different
price based on its length.
Steps to Solve Problems Using Dynamic
Programming
1. Characterize the structure of the optimal solution.

2. Define the value of the optimal solution recursively in


terms of smaller subproblems.

3. Compute the value of the optimal solution iteratively in


a bottom-up fashion.

4. Construct the optimal solution from the computed


values if required.

Note: Steps 1-3 form the basis of a DP solution, and step 4 can be omitted if only
the value of an optimal solution is required.
Comparison with Divide and Conquer

•Dynamic Programming:
• Suitable for problems with overlapping subproblems.
• Uses memoization or tabulation to store intermediate
results.
•Divide and Conquer:
• Breaks problems into independent subproblems.
• Does not reuse subproblems, hence no need for
memoization.

You might also like