Q. In dynamic programming, what is the purpose of the 'state'?
A.
To represent the final solution
B.
To store the results of subproblems
C.
To define the problem constraints
D.
To track the number of iterations
Show solution
Solution
In dynamic programming, the 'state' represents the results of subproblems, which are used to build up the solution to the overall problem.
Correct Answer:
B
— To store the results of subproblems
Learn More →
Q. What is the main difference between top-down and bottom-up approaches in dynamic programming?
A.
Top-down uses recursion, bottom-up uses iteration
B.
Top-down is faster than bottom-up
C.
Bottom-up is more space efficient than top-down
D.
There is no difference
Show solution
Solution
The main difference is that the top-down approach uses recursion and memoization, while the bottom-up approach builds the solution iteratively.
Correct Answer:
A
— Top-down uses recursion, bottom-up uses iteration
Learn More →
Q. What is the primary advantage of using dynamic programming over simple recursion?
A.
It uses less memory
B.
It avoids redundant calculations
C.
It is easier to implement
D.
It is faster in all cases
Show solution
Solution
Dynamic programming avoids redundant calculations by storing the results of subproblems, which makes it more efficient than simple recursion.
Correct Answer:
B
— It avoids redundant calculations
Learn More →
Q. What is the space complexity of the dynamic programming solution for the 0/1 Knapsack problem using a 2D array?
A.
O(n)
B.
O(w)
C.
O(n * w)
D.
O(1)
Show solution
Solution
The space complexity of the dynamic programming solution for the 0/1 Knapsack problem using a 2D array is O(n * w), where n is the number of items and w is the maximum weight.
Correct Answer:
C
— O(n * w)
Learn More →
Q. Which dynamic programming problem involves making decisions based on previous decisions?
A.
Fibonacci sequence
B.
Longest increasing subsequence
C.
Coin change problem
D.
Matrix chain multiplication
Show solution
Solution
Matrix chain multiplication involves making decisions based on previous decisions to determine the optimal way to multiply a chain of matrices.
Correct Answer:
D
— Matrix chain multiplication
Learn More →
Showing 1 to 5 of 5 (1 Pages)