Midterm 2
Midterm 2
Question 1 2 3 Total
Marks /5 /5 /8 /18
Q1) In a twist to the fractional Knapsack problem, we allow the repetition of i.e. we can use any
number of copies of a certain element if we wish. What will be the new greedy algorithm for this
modified fractional knapsack? Give a pseudo-code. [5 Marks]
In array S, fill into S[i] : the optimal sum of a subarray ending at A[i]. In array P, fill into P[i]: the starting
index of the optimal array ending at A[i] [5 Marks]
Solution:
S[]
P[]
In other words you want to find out for each vertex u, which vertices are reachable from vertex u. Give an
efficient algorithm that computes the transitive closure of a given graph G(V,E). [8 Marks]