You are on page 1of 3

1.What is a dynamic programming, how can it be described?

Ans.Dynamic programming is an algorithm design technique for


optimization problems:often minimizing or maximizing.Like divide and
conquer,dp solves problems by combining solutions to sub-problems.A given
problem is divided into sub-probems.The sub-problems are if necessary
again divided into some subproblems.The sub-problems are then solved and
stored for future reference,so as to avoid solving the same problem again.
Applications are 1.OBST
2.0/1 knapsack problem
3.Floyd's algorithm(All pairs shortest path)
2.What is an Optimal Binary Search Tree(OBST)?
Ans.An Optimal Binary Search tree is a Binary Search tree for which the
nodes are arranged on levels such that the tree cost is minimum and it
depends on probability of searching an internal node and probability of
searching an external node.
3.Difference between Dynamic programming(DP) and Divide and
conquer(DAC)?
Ans.Like divide and conquer,dp solves problems by combining solutions to
sub-problems.Unlike DAC subproblems arent independent here
->Sub problems may share sub-sub problems.
->However,solution to one subproblem may not affect the solutions to other
subproblems of same program.
4.What are the steps involved in DP?
1.Characterize structure of an optimal solution.
2.Define value of an optimal solution recursively.
3.Compute optimal solution values either top-down with caching or botomup in a table.
4.Construct an optimal solution from computed values.
5.What are the 2 main properties of a problem that suggest the given problem
can be solved using DP?
Ans.DP is an algorithmic technique that solves a given complex problem by
breaking it into ssubproblems and stores the results of subproblems to avoid
computing the same results again.Following are 2 main properties of a
problem that suggest a given problem can be solved using DP:

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.

You might also like