0% found this document useful (0 votes)
33 views2 pages

Unit - III - 2marks

This document contains definitions and examples related to algorithms and dynamic programming. It defines multistage graphs, the multistage graph problem, and the knapsack problem using dynamic programming. It provides cost functions for solving the multistage graph problem using forward and backward approaches. It also defines the all-pairs shortest path problem, expected cost of an optimal binary search tree, and the travelling salesman problem. Finally, it compares greedy and dynamic programming, noting that greedy methods generate one decision sequence while dynamic programming can generate multiple.

Uploaded by

Sharma Divya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Unit - III - 2marks

This document contains definitions and examples related to algorithms and dynamic programming. It defines multistage graphs, the multistage graph problem, and the knapsack problem using dynamic programming. It provides cost functions for solving the multistage graph problem using forward and backward approaches. It also defines the all-pairs shortest path problem, expected cost of an optimal binary search tree, and the travelling salesman problem. Finally, it compares greedy and dynamic programming, noting that greedy methods generate one decision sequence while dynamic programming can generate multiple.

Uploaded by

Sharma Divya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Department of Computer Science and Engineering

CS41 - Design and Analysis of Algorithm


Assignment Questions
Unit III
1. What is multistage graph?
2. What is multistage graph problem?
3. State knapsack problem using dynamic programming.
4. What is dynamic Programming?
5. Give the cost function for multistage graph using forward approach.
6. Give the cost function for multistage graph using backward approach.
7. What is all pair shortest path problem?
8. Give a expected cost of a optimal binary tree.
9. What is travelling salesman problem?
10. Compare greedy and dynamic programming.
Keys:
1. Multistage graph:
A multistage graph G = (V, E) is a directed graph in which the vertices are
partitioned into k2 disjoint sets Vi, 1 i k. In addition, if <u, v> is an edge in
E, then u Vi and v Vi+1 for some i, 1 i k.
2. Multistage graph problem:
Finding the minimum cost path between s to t, where s is the source and t
is the sink.
3. Knapsack problem:
Maximize lij pixi
Subject to

lij wixi y

xi = 0 or 1, lij
4. Dynamic Programming
Solution to the problem can be viewed as the result of a sequence of decisions.
For Example: Knapsack Problem
We have to decide the values of xi
Here first take the decision on x1 and x2 and then x3 ..
5. Cost function for multistage graph problem using forward approach.

cost(i, j) = min { c(j,l) + cost(i + 1, l)}


lVi+1
<j,l> E
Since, cost(k-1, j) = c(j,t) if <j,t> E.

6. Cost function for multistage graph problem using backward approach


bcost(i,j) = min { bcost(i-1, l)+ c(l,j)}
lVi+1, <j,l> E

Bcost(2,j)=c(1,j) if <1,j> E
7. All pair shortest path problem
Let G=(V,E) Directed graph with n vertices.
Cost Cost Adjacency Matrix, such that cost(i,i) = 0, 1i n
cost(i,j) cost of edge <i,j>
cost(i,j) = if i j and <i,j> not in E(G)
All pair shortest path problem to determine matrix A, in which A(i,j) is
the length of the shortest path from i to j.

8. Expected cost of a optimal binary search tree


n

P level(a ) Q (level(E ) 1)
i

n 1

n 0

9. Travelling salesman problem.

The TSP can be modeled as a graph, such that cities are the graphs
vertices, paths are the graphs edges, and a path's distance is the edge's
length.

TSP tour is a cycle in a directed graph which visits each vertex exactly
once and also returns to the starting vertex.

Every tour consist of an edge <1,k> for some k in V- { 1 } and a path from
vertex k to 1.

Path from k to 1 must be a shortest path going through all vertices in V


{1,k}
g(i,S) = min{ cij + g(j,S- {j})}
jS

10. Comparison of Greedy and Dynamic programming.

In greedy method, only one decision sequence is ever generated.

In dynamic programming, many decision sequences may be generated.

You might also like