L1-DP and Knapsack
L1-DP and Knapsack
1. Dynamic Programming
a) Design Principles and Strategy,
b) 0/1 Knapsack Problem,
c) All-pairs Shortest Path Problem
d) Resource allocation problem.
2. Backtracking, Branch and Bound with examples such as
a) Travelling Salesman Problem,
b) Graph Coloring,
c) n-Queen Problem,
d) Hamiltonian Cycles and
e) Sum of subsets.
A divide and conquer approach would repeatedly solve the common subproblems
Dynamic programming solves every subproblem just once and stores the answer
in a table
max å bi subject to å wi £ W
iÎT iÎT
n = 4 (# of elements)
W = 5 (max weight)
Elements (weight, benefit):
(2,3), (3,4), (4,5), (5,6)
for w = 0 to W
V[0,w] = 0
for i = 1 to n
V[i,0] = 0
This algorithm only finds the max possible value that can be carried in the
knapsack
– i.e., the value in V[n,W]
To know the items that make this maximum value, an addition to this
algorithm is necessary