Last Updated : 17 Dec, 2018

Consider the following statements regarding dynamic programming Which of the following is correct?

(A) In a top-down approach to dynamic programming, the larger subproblems are solved before the smaller ones.
(B) Dynamic programming is used to find the longest path from a given vertex S to a given vertex t in a weighted directed acyclic graph when negative edge weights are present.

(C) Dynamic programming is more closely related to BFS than it is to DFS.
(D) All of the above are correct.


Answer: (B)

Explanation: I – False: The larger problems depend on the smaller ones, so the smaller ones need to be solved first. The smaller problems get solved (and memoized) recursively as part of a larger problem.
II – True: The fact that some edges have negative edge weights doesn’t affect anything. So, Dynamic programming is used to find the longest path from a given vertex S to a given vertex t in a weighted directed acyclic graph, when negative edge weights are present.
III – False: DFS is more closely related. The top-down approach to dynamic programming is effectively performing DFS on the subproblem dependence graph. The bottom-up approach means solving subproblems in the order of a reverse topological sort, which is also related to DFS.
So, option (B) is correct.

Quiz of this Question


Share your thoughts in the comments