Professional Documents
Culture Documents
11/7/2012
Dynamic Programming - II
Atul Gupta
11/7/2012
11/7/2012
11/7/2012
Knapsack Problem
Also referred as 0/1 Knapsack There are n items to pick from, of weight w1, . . . , wn and dollar value v1, . . . , vn. Find the optimal solution to fill the knapsack of size W, such that
max subjected to xi = 1 or 0 =< W
Knapsack Problem
There are two versions of this problem
Unlimited quantities of each item Fix quantities
11/7/2012
11/7/2012
11/7/2012
11/7/2012
MCM: A DP Solution
The DP relation The Algorithm
11/7/2012
Shortest Paths
All pair shortest path(APSP)
Dijkestras algorithm can be used for all vertices Time complexity of Dijketras algorithm is O(|V| |E|) (Worst case is O(n3) considering a complete graph of n nodes) Therefore, the time complexity of APSP will be O((|V|2 |E|) (Worst case is O(n4)) Can we do it better?
11/7/2012
10
11/7/2012
TSP
A DP Solution
Sub-Problems? let C (S, j) be the length of the shortest path visiting each node in S exactly once, starting at 1 and ending at j For |S| > 1, we define
11
11/7/2012
Time Complexity?
The arrangements of all sub-problems can be thought of various nodes of a DAG, and solution lies of computing some properties of this DAG
12
11/7/2012
References
Chapter 6, Algorithms by S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani
13