Professional Documents
Culture Documents
1.Overlapping subproblems
2.Optimal substructure
6.What is an optimal substructure in dyanamic programming(DP)?
Ans.A problem is said to have optimal substructure if an optimal solution can
be constructed efficiently from optimal solutions of its subproblems.This
property is used to determine the usefulness of DP and greedy algorithms
for a problem.
7.What is overlapping subproblems in dyanamic programming(DP)?
Ans.A problem is said to have overlapping subproblems,if the problem can be
broken down into subproblems which are reused several times .This is closely
related to Recursion.
8.Explain 0/1 knapsack problem?
Ans.Given some items,pack the knapsack to get the maximumtotal
value.Each item has some weight and some value.Total weight that we can
carry is no more than some fixed number W.So,we must consider weights of
items as well as their value.
~Given a knapscak with maximum capacity W,and set S consisting of n
items.
~Each item i has some weight Wi and benifit value Bi.(Wi,Bi and W are all
integers).
ITEMS
WEIGHT (wI) BENIFIT(Bi)
2
4
This is knapsack max weight
3
3
4
W=20
5
10
This problem is called 0/1 knapsack problem because each item must
be completely accepted or completely rejected.
9.What is fractional knapsack problem?
Ans.There are 2 versions of the knapsack problem.
1)0/1 knapsack problem(SOlved with dynamic programming):Here
items are indivisible.You can take an item or not.
2)Fractional knapsack problem(Solved with a greedy algorithm):Here
items are divisible,you can take any fraction of an item.
10.Explain about floyds algorithm?
Ans.Floyd's algorithm: solving the all-pairs shortest path problem.
Let G(E,V) be a directed graph consisting of n vertices and each edge
associated with a weight.
Each edge is of a direction and has a length:
i)If there is a path from vertex i to j then there may not be a path from vertex
j to i.
ii)path length from vertex i to j may be different than path length from vertex
j to i.
OBJECTIVE:finding shortest path between every pair of vertices(i->j).
APPLICATION:table of driving distances between city pairs.