Quiz2
Quiz2
1. Though there may be an exponential number of subproblems, Dynamic Programming (DP) CO3, K1
may achieve polynomial running time. What are the reasons?
A. There is only a polynomial number of distinct subproblems
B. DP computes the solution to each subproblem once and stores it for subsequent
look-up
C. DP uses iteration instead of recursion
D. DP solves the problem bottom-up
2. Compared to Dynamic Programming, memoization CO3, K2
A. solves exactly the same number of subproblems
B. solves at most the same number of subproblems
C. solves at least the same number of subproblems
D. solves different number of subproblems
3. In how many different orders can the chain of matrix multiplications A × B × C × D be CO4, K3
evaluated?
A. 2
B. 3
C. 4
D. 5
4. Suppose binomial coefficient nk is calculated using dynamic programming, and C[k, n] is
CO4, K2
stored in a table where k is the row index and n is the column index. Then the table is filled
A. row by row, from left to right in each row
B. row by row, from right to left in each row
C. column by column, from top to bottom in each column
1
D. column by column, from bottom to top in each column
5. The input is x1 , . . . , xn , and y1 , . . . , ym . A subproblem is x1 , . . . , xi and y1 , . . . , yj . What is CO2, K3
the total number of subproblems?
A. O(mn)
B. O(m2 )
C. O(n2 )
D. O(m + n)
6. If the dependency among the subproblems is as shown in the figure, how many subproblems CO3, K3
do exhaustive search and DP solve?
A. 12, 7
B. 7, 12
C. 12, 12
D. 7, 7
7. Floyd-Warshall algorithm recurses on CO4, K2
A. the maximum number of intermediate vertices permitted in the path
B. the set of intermediate vertices permitted in the path
C. the ordered set of intermediate vertices permitted in the path
D. the neighbors of the end vertex of the path
8. Find the number of different shortest paths from point A to point B in a city with perfectly CO1, K3
horizontal and vertical streets as shown in the figure. No path can cross the fenced off area
shown in grey in the figure.
A. 31
B. 17
C. 9
D. 8
2
9. Four people wish to cross a bridge. It is dark, and it is necessary to use a torch when crossing CO3, K3
the bridge, but they have only one torch between them. The bridge is narrow, and only two
people can be on it at anyone time. The four people take different amounts of time to cross
the bridge; when two cross together they proceed at the speed of the slowest. The first person
takes 1 minute to cross, the second 2 minutes, the third 5 minutes and the fourth 10 minutes.
The torch must be ferried back and forth across the bridge, so that it is always carried when
the bridge is crossed. What is the optimal time and the time taken by greedy approach that
chooses the fastest persons?
A. 17 minutes, 19 minutes
B. 19 minutes, 22 minutes
C. 17 minutes, 22 minutes
D. 19 minutes, 19 minutes
10. What is the strategy that extends a partial structure by a sequence of steps, keeping it optimal CO3, K2
at each step, to make a globally optimal structure?
A. Optimization
B. Greedy
C. Dynamic Programming
D. Exhaustive search
11. Dijkstra’s algorithm for Single Source Shortest Path greedily adds to the Shortest Path (SP) CO3, K2
tree
A. the fringe vertex nearest to the SP tree
B. the fringe vertex nearest to the source
C. the next vertex in the graph nearest to the source
D. the next shortest edge in the graph
12. Prim’s algorithm for MST greedily adds to the partial tree CO3, K2
A. the fringe vertex nearest to the partial tree
B. the fringe vertex nearest to the source
C. the next vertex in the graph nearest to the source
D. the next shortest edge in the graph that does not form a cycle
13. Removing an edge from an MST (Minimum Spanning Tree) T of a graph and adding a new CO2, K2
edge from the graph produces a tree T 0 that costs
A. more than T
B. less than T
3
C. the same as T
D. depends on the weight of the new edge added
14. Shortest path tree in Dijsktra’s algorithm for SSSP can be represented in an array using CO4, K2
A. child pointers from each node
B. child pointer and next sibling pointer
C. parent pointer from each node
D. array of vertices in the order they are selected
15. It is possible to implement Union-Find data structure to achieve CO4, K2
A. O(1) for union and O(log n) for find
B. O(1) for find and O(log n) for union
C. O(1) for both union and find
D. O(n) for find and O(log n) for union
17. Suppose you are given a sequence of integers separated by + and − signs; for example: CO3, K3
1+3−2−5+1−6+7
1.4.1, 2.3.1
4
You can change the value of this expression by completely parenthesizing it in different ways.
For example:
((((((1 + 3) − 2) − 5) + 1) − 6) + 7) = −1
((1 + 3 − (2 − 5)) + ((1 − 6) + 7)) = 9
(((1 + (3 − 2)) − (5 + 1)) − (6 + 7)) = −17
Given a list of integers separated by + and − signs, we want to compute the maximum possi-
ble value the expression can take by adding parentheses. Design an algorithm using DP. What
is the structure in which you store the solutions to subproblems and in which order you store
them? Analyse the algorithm.
Hint: Store the integers in an array A[1..N] and the operators in an array S[1..N-1]. A
recurrence relation for the maximum value of an expression using A[i..j] and S[i..j-1]
is given by
a) Describe a greedy algorithm to make change, assuming there are four denominations
of coins with values 25, 10, 5, 1 rupees. Prove that your algorithm yields an optimal
solution.
b) Suppose that the available coins have the values c0 , c1 , . . . , ck for some integers c > 1
and k ≥ 1. Show that the obvious greedy algorithm always yields an optimal solution.
c) Describe a dynamic programming algorithm that yields an optimal solution for an ar-
bitrary set of coin values.
2.1.3, 2.4.1, 2.4.3