Upcoming SlideShare
×

# Elements of dynamic programming

7,871 views
7,410 views

Published on

An introductory project showing how to identify if a DP solution to a problem exists. It also discusses the essential parts of DP solutions briefly.

Published in: Education
9 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
7,871
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
0
0
Likes
9
Embeds 0
No embeds

No notes for slide

### Elements of dynamic programming

1. 1. Elements of Dynamic Programming<br />An Introduction by<br />TafhimUl Islam<br />C091008<br />CSE 4th Semester<br />International Islamic University Chittagong<br />
2. 2. What is Dynamic Programming<br />Dynamic Programming (DP) is not an algorithm. It’s a technique/approach that we use to build efficient algorithms for problems of very specific class<br />
3. 3. The Elements<br />Optimal Substructure<br />Overlapping sub-problem<br />Memoization<br />
4. 4. What is Substructure?<br />A substructure is a structure itself that helps a bigger structure of the same kind to exist.<br />The substructure does not play an auxiliary role<br />It is an essential part of the super structure<br />It is only smaller in size compared to the super structure<br />It has the same properties of the superstructure<br />
5. 5. Optimal Substructure<br />So optimal substructure is simply the optimal selection among all the possible substructures that can help a super structure of the same kind to exist<br />Example: To know how to multiply n matrices optimally we must multiply the last matrix with the optimal multiplication result of the n-1 other matrices. The base case for the recursion here is that the optimal parenthesization of <br />
6. 6. Optimal Substructure<br />To build a building with the best possible strength, we need to build each level as optimally as possible<br />To solve a mathematical problem, we all the smaller problems inside that problem to have the correct result. Each problem might depend on the previous problem solved. So we need to take care of all the problems optimally, with correct calculations.<br />
7. 7. Overlapping Sub-problem<br />Overlapping sub-problem is found in those problems where bigger problems share the same smaller problems. This means, while solving larger problems through their sub-problems we find the same sub-problems in two or more different large problems. In these cases a sub-problem is usually found to be solved previously.<br />
8. 8. Overlapping Sub-problem<br />Overlapping sub-problems can be found in Matrix-Chain-Multiplication (MCM) problem. <br />
9. 9. Cases where mistakes might occur<br />Unweighted shortest path: Find a path from u to v consisting of the fewest edges. Such a path must be simple, since removing a cycle from a path pro-duces a path with fewer edges.<br />Unweighted longest simple path: Find a simple path from u to v consisting of the most edges. We need to include the requirement of simplicity because other-wise we can traverse a cycle as many times as we like to create paths with an arbitrarily large number of edges.<br />
10. 10. Memoizaiton<br />The memoization technique is the method of storing values of solutions to previously solved problems. This generally means storing the values in a data structure that helps us reach them efficiently when the same problems occur during the program’s execution. The data structure can be anything that helps us do that but generally a table is used.<br />