Which of the following option is correct regarding dynamic programming?
(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.
Answer: (B)
Explanation: (A) 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.
(B) 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.
(C) 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, only option (B) is correct.
Quiz of this Question
Share your thoughts in the comments
Please Login to comment...