Q1. Memoization vs. Tabulation
What is the primary difference between memoization and tabulation techniques in dynamic programming?
- Memoization is bottom-up, while tabulation is top-down.
- Memoization stores results of subproblems, while tabulation builds a table iteratively.
- Tabulation uses recursion, while memoization uses iteration.
- There is no difference; they are interchangeable.
Q2. Fibonacci Sequence - DP
Which of the following is the time complexity of a dynamic programming solution for calculating the nth Fibonacci number?
- O(2^n)
- O(n log n)
- O(n)
- O(log n)
Q3. 0/1 Knapsack - State Definition
In the 0/1 Knapsack problem, what does the state dp[i][w] typically represent?
- The maximum value obtainable with items up to index i and a maximum weight of w.
- The minimum weight required to obtain a value of w with items up to index i.
- The total weight of items up to index i, given a capacity of w.
- The number of items selected up to index i, with a weight limit of w.
Q4. Longest Common Subsequence - Recurrence
What is the correct recurrence relation for the Longest Common Subsequence (LCS) problem, where s1 and s2 are the strings, and i and j are their respective indices?
- dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + (s1[i] == s2[j])
- dp[i][j] = dp[i-1][j-1] + (s1[i] == s2[j] ? 1 : 0)
- dp[i][j] = max(dp[i-1][j], dp[i][j-1], dp[i-1][j-1] + (s1[i] == s2[j] ? 1 : 0))
- dp[i][j] = min(dp[i-1][j], dp[i][j-1])
Q5. Coin Change - Optimization
Which optimization technique can be used in the Coin Change problem to reduce space complexity from O(amount * number of coins) to O(amount)?
- Using a 2D array instead of a 1D array.
- Reusing the same array in each iteration, overwriting previous results.
- Sorting the coins.
- Using memoization instead of tabulation.
Q6. Bottom-Up vs. Top-Down
In what scenario is a bottom-up dynamic programming approach generally preferred over a top-down approach?
- When the solution requires calculating only a small subset of possible states.
- When the problem has overlapping subproblems that are never revisited.
- When there is a clear topological order for solving the subproblems.
- When the recursion depth becomes a limiting factor.
Q7. Space Complexity Optimization
Which type of dynamic programming problems are most suitable for space complexity optimization by reducing the dimensionality of the DP table?
- Problems with complex dependencies between states.
- Problems where the current state only depends on the immediately previous row or column.
- Problems involving strings with large alphabets.
- Problems requiring high precision floating-point arithmetic.
Q8. Real-World DP Scenario
In which real-world application is dynamic programming frequently used for optimal decision-making?
- Database management systems.
- Compiler optimization.
- Network routing algorithms.
- All of the above.
Q9. Edit Distance - Understanding
What does the Edit Distance problem aim to find?
- The longest common subsequence between two strings.
- The shortest path between two nodes in a graph.
- The minimum number of operations required to transform one string into another.
- The maximum number of matching characters between two strings.
Q10. DP State Variables
What determines the number of state variables needed to define a dynamic programming solution?
- The number of input elements.
- The number of possible function calls.
- The number of dimensions of the DP table.
- The minimum number of parameters required to uniquely identify each subproblem.
Q11. Minimum Cost Path - Application
Dynamic programming is commonly used to solve the Minimum Cost Path problem in a grid. What does this path typically represent?
- The path with the fewest number of cells.
- The path with the largest sum of values in the cells.
- The path with the smallest sum of values in the cells.
- The path that avoids all obstacles.
Q12. Partition Problem
What is the core objective of the Partition Problem solvable with dynamic programming?
- To find the largest subset of a set.
- To divide a set into two subsets such that the difference of subset sums is minimized.
- To sort the elements of a set in ascending order.
- To find the median element of a set.
Q13. Optimal Binary Search Tree
What problem does Dynamic programming offer a solution for in case of Optimal Binary Search Tree?
- Optimizing the height of the BST
- Minimizing the average search cost in a BST
- Maximizing the number of nodes in a BST
- Balancing the BST structure
Q14. Matrix Chain Multiplication
Which problem does dynamic programming optimize when addressing Matrix Chain Multiplication?
- The order of matrix storage in memory.
- The number of matrices to be multiplied.
- The order in which matrices are multiplied to minimize the total number of scalar multiplications.
- The size of the resulting matrix.
Q15. Cutting a Rod
What is the goal when using dynamic programming to solve the 'Cutting a Rod' problem?
- To find the shortest way to cut the rod.
- To determine the maximum number of cuts possible.
- To find the optimal way to cut a rod into smaller pieces to maximize the total value.
- To minimize the amount of material wasted during cutting.