Unit 3: Dynamic Programming - Practice Quiz

CSE408 — Design And Analysis Of Algorithms 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Dynamic programming is especially useful when a problem has which property?

Introduction to Dynamic Programming Easy
A. Only one possible solution
B. Completely independent inputs
C. A large number of unrelated subproblems that are each solved exactly once
D. Overlapping subproblems

2 What are the two common approaches used to implement dynamic programming?

Introduction to Dynamic Programming Easy
A. Iteration and compilation
B. Sorting and searching
C. Memoization and tabulation
D. Selection and partitioning

3 What does optimal substructure mean?

Introduction to Dynamic Programming Easy
A. An optimal solution can be found only after sorting all input values
B. The input must always be divided into equal parts
C. Every subproblem has exactly one possible solution
D. An optimal solution contains optimal solutions to subproblems

4 What is the value of for any nonnegative integer ?

Computing a Binomial Coefficient Easy
A.
B.
C.
D.

5 Which recurrence is used to compute a binomial coefficient using dynamic programming?

Computing a Binomial Coefficient Easy
A.
B.
C.
D.

6 What is the main purpose of a memory function?

Memory Functions Easy
A. To sort subproblems by input size
B. To store previously computed results
C. To remove all recursive function calls
D. To recompute every subproblem whenever its value is requested

7 A memory-function implementation of dynamic programming is commonly called what?

Memory Functions Easy
A. Partitioning
B. Linear scanning
C. Memoization
D. Backtracking

8 In the knapsack problem, how many times may each item be selected?

Knapsack Problem Easy
A. Exactly twice
B. At most once
C. Any number of times
D. Only when its weight equals the full capacity

9 What is the objective of the knapsack problem?

Knapsack Problem Easy
A. Maximize total weight beyond the capacity
B. Minimize total value within the capacity
C. Maximize total value within the capacity
D. Select every item regardless of its weight

10 A knapsack has capacity . Which single item can fit in it?

Knapsack Problem Easy
A. An item of weight
B. An item of weight
C. An item of weight
D. An item of weight

11 Which statement distinguishes fractional knapsack from knapsack?

Knapsack Problem Easy
A. Fractional knapsack allows part of an item
B. Fractional knapsack assigns no values to the available items
C. Fractional knapsack requires every item to be selected
D. Fractional knapsack always requires a dynamic programming table with three dimensions

12 What does the matrix-chain multiplication problem seek to minimize?

Matrix-Chain Multiplication Easy
A. The values stored in all matrices before performing multiplication
B. The number of matrices in the chain
C. The number of scalar multiplications
D. The number of rows in each matrix

13 When can a matrix of size be multiplied by a matrix of size ?

Matrix-Chain Multiplication Easy
A. When
B. When
C. When
D. When

14 How many scalar multiplications are needed to multiply a matrix by a matrix using the standard method?

Matrix-Chain Multiplication Easy
A.
B.
C.
D.

15 In a subsequence, must the selected characters be contiguous in the original sequence?

Longest Common Subsequence Easy
A. No, but their order must be preserved
B. Yes, they must always be adjacent
C. No, and their order may be reversed
D. Yes, unless both sequences have exactly the same length and contain identical characters

16 What is the length of a longest common subsequence of the strings and ?

Longest Common Subsequence Easy
A.
B.
C.
D.

17 If the current characters of two sequences match, how is the corresponding LCS table entry commonly computed?

Longest Common Subsequence Easy
A. Copy the entry directly to the left
B. Add to the entry directly above
C. Set the entry to the total length of both complete sequences
D. Add to the diagonal entry

18 What does an optimal binary search tree minimize?

Optimal Binary Search Trees Easy
A. Size of each key
B. Time required to sort the keys before every individual search operation
C. Expected search cost
D. Number of stored keys

19 Which information is commonly used to construct an optimal binary search tree?

Optimal Binary Search Trees Easy
A. Colors assigned to keys
B. Memory addresses of keys
C. Search probabilities of keys
D. The programming language used to store the tree

20 In an optimal binary search tree, frequently searched keys are generally placed where?

Optimal Binary Search Trees Easy
A. At the deepest available level even when shallower positions are open
B. Near the root
C. Only at leaf nodes
D. Outside the tree

21 A recursive algorithm repeatedly solves the same smaller instances, and an optimal solution can be formed from optimal solutions to those instances. Which properties make dynamic programming appropriate?

Introduction to Dynamic Programming Medium
A. Unique subproblems and exhaustive enumeration
B. Sorted inputs and constant-time decisions
C. Disjoint subproblems and local optimality
D. Overlapping subproblems and optimal substructure

22 A bottom-up Fibonacci algorithm stores only the two most recently computed values. What are its time and auxiliary space complexities for computing ?

Introduction to Dynamic Programming Medium
A. time and space
B. time and space
C. time and space
D. time and space

23 In a shortest-path problem on a staged graph, why can choosing the minimum-weight outgoing edge at every vertex fail?

Introduction to Dynamic Programming Medium
A. The selected edge may increase the number of vertices
B. The selected edge may lead to an expensive remaining path
C. The selected edge may create overlapping subproblems
D. The selected edge may prevent memoization of distances

24 Using , what is the value of ?

Computing a Binomial Coefficient Medium
A.
B.
C.
D.

25 A one-dimensional array is used to compute binomial coefficients. For each row , why should entries be updated from larger to smaller ?

Computing a Binomial Coefficient Medium
A. To reduce the running time from quadratic to linear
B. To generate coefficients in decreasing numerical order
C. To preserve values from the previous row during updates
D. To avoid computing the boundary coefficient

26 A memoized LCS algorithm is called for only one pair of string prefixes. When can it evaluate fewer states than a full bottom-up table?

Memory Functions Medium
A. When the recursive calls reach only part of the table
B. When the strings have equal lengths but different symbols
C. When each state has exactly one possible solution
D. When every table entry has the same computed value

27 A memoized maximization algorithm uses to mean that a state has not been computed, but valid state values may also equal . What is the best correction?

Memory Functions Medium
A. Initialize all states with the first input value
B. Replace every negative result with zero
C. Compute every state twice before storing it
D. Use a separate Boolean array for visited states

28 A knapsack has capacity . Items have pairs , , , and . What is the maximum obtainable value?

Knapsack Problem Medium
A.
B.
C.
D.

29 Let be the maximum value using the first items with capacity . If item has weight and value , which recurrence represents the knapsack choice?

Knapsack Problem Medium
A.
B.
C.
D.

30 During reconstruction of a knapsack solution, suppose . What action is justified?

Knapsack Problem Medium
A. Include item and set
B. Include item and set
C. Exclude item and set
D. Exclude item and keep capacity

31 When implementing knapsack with a one-dimensional array, capacities are processed from down to for each item. What does this ordering prevent?

Knapsack Problem Medium
A. Selecting the current item more than once
B. Comparing items with different values
C. Selecting two items with equal weights
D. Leaving unused capacity in the knapsack

32 Matrices , , and have dimensions , , and . What is the minimum number of scalar multiplications?

Matrix-Chain Multiplication Medium
A.
B.
C.
D.

33 A matrix chain has dimension array . What is the minimum number of scalar multiplications needed to multiply all four matrices?

Matrix-Chain Multiplication Medium
A.
B.
C.
D.

34 For four matrices, the split table contains , , and . Which optimal parenthesization does this describe?

Matrix-Chain Multiplication Medium
A.
B.
C.
D.

35 What is the length of a longest common subsequence of and ?

Longest Common Subsequence Medium
A.
B.
C.
D.

36 Let denote the LCS length of prefixes and . If , which recurrence should be used?

Longest Common Subsequence Medium
A.
B.
C.
D.

37 The strings and have an LCS of length . Using only insertions and deletions, what is the minimum number of operations required to transform into ?

Longest Common Subsequence Medium
A.
B.
C.
D.

38 Three ordered keys have successful-search probabilities , , and . Ignoring unsuccessful searches and counting the root at depth , which key should be the root of an optimal BST?

Optimal Binary Search Trees Medium
A. The third key
B. The second key
C. The first key
D. Either outer key

39 In the optimal BST recurrence, why is the total probability weight added after selecting a root for keys through ?

Optimal Binary Search Trees Medium
A. Every key in the interval becomes a possible root
B. Every search in the interval moves one level deeper
C. Every subtree receives an equal probability weight
D. Every unsuccessful search is removed from the tree

40 Why can an optimal binary search tree be structurally unbalanced even when a balanced BST is possible?

Optimal Binary Search Trees Medium
A. It requires all unsuccessful searches to be left children
B. It minimizes tree height without considering key frequencies
C. It preserves insertion order instead of sorted-key order
D. It minimizes expected search cost using access probabilities

41 A table entry depends on , , and , with row and column initialized. Which traversal computes every dependency before it is used?

Introduction to Dynamic Programming Hard
A. Process decreasingly, and for each , process increasingly
B. Process increasingly, and for each , process decreasingly
C. Process diagonals in decreasing order of the value
D. Process increasingly, and for each , process increasingly

42 A graph problem asks for a maximum-reward path from a source to a target using at most edges. A proposed DP stores only the maximum reward obtained at each vertex. Why can this state definition violate the principle of optimality?

Introduction to Dynamic Programming Hard
A. Maximum-reward paths are greedy, so the state should include the locally best outgoing edge
B. A higher-reward prefix may use more edges, so the state should include the edge budget
C. A lower-reward prefix always dominates, so the state should include the preceding vertex
D. Every path problem contains cycles, so the state should include the entire visited set

43 A one-dimensional Pascal-array implementation currently stores the row for as . It incorrectly updates indices from left to right using . What value will it store at index instead of ?

Computing a Binomial Coefficient Hard
A.
B.
C.
D.

44 Consider a top-down memoized computation of with base cases and . It performs no symmetry reduction. How many distinct non-base states are evaluated when computing ?

Computing a Binomial Coefficient Hard
A.
B.
C.
D.

45 A top-down LCS implementation initializes every memo entry to and treats an entry as cached only when its value is nonzero. For two length- strings with no common character, what is the resulting asymptotic running time?

Memory Functions Hard
A.
B.
C.
D.

46 A memoized recurrence is represented by a directed acyclic state graph. From the initial state, states and dependency edges are reachable. If each state scans all of its outgoing dependencies once when first evaluated, what are the tight time and memo-space bounds?

Memory Functions Hard
A. time and space
B. time and space
C. time and space
D. time and space

47 For 0/1 knapsack with capacity , items and are processed using a one-dimensional array, but capacities are scanned increasingly for each item. What value is reported, and what is the true 0/1 optimum?

Knapsack Problem Hard
A. Reported ; true optimum
B. Reported ; true optimum
C. Reported ; true optimum
D. Reported ; true optimum

48 An exact-fill 0/1 knapsack DP initializes every capacity state to rather than setting unreachable positive capacities to . With items and and target capacity , it returns . What has the implementation actually computed?

Knapsack Problem Hard
A. The optimum for capacity at most
B. The optimum for capacity at least
C. The optimum after allowing fractional items
D. The optimum for capacity exactly

49 A descending-capacity 1D DP correctly computes the optimal 0/1 knapsack value, but reconstruction using a single mutable predecessor pointer per capacity can repeat an item because earlier information is overwritten. Which method reliably reconstructs a valid optimal subset?

Knapsack Problem Hard
A. Store a decision for each pair and backtrack through item rows
B. Scan capacities increasingly and follow the most recent predecessor
C. Store one predecessor per capacity and update it during every tie
D. Sort items by value-to-weight ratio and reconstruct greedily

50 When capacity is extremely large but the total item value is moderate, which exact 0/1 knapsack formulation gives a pseudo-polynomial bound independent of ?

Knapsack Problem Hard
A. Store the minimum value for each weight in time
B. Store the maximum value for each weight in time
C. Store the maximum ratio for each item in time
D. Store the minimum weight for each value in time

51 Four matrices have dimensions , , , and . Which parenthesization minimizes scalar multiplications, and what is its cost?

Matrix-Chain Multiplication Hard
A. with cost
B. with cost
C. with cost
D. with cost

52 The standard bottom-up matrix-chain algorithm tests every split for every interval . How many candidate splits are examined for a chain of matrices?

Matrix-Chain Multiplication Hard
A.
B.
C.
D.

53 A chain contains six matrices, each of dimension . Assuming only scalar multiplication count matters, how many distinct parenthesizations are optimal?

Matrix-Chain Multiplication Hard
A.
B.
C.
D.

54 For and , the LCS length is . Which sequence is not an LCS of the two strings?

Longest Common Subsequence Hard
A.
B.
C.
D.

55 For strings of lengths and , which statement correctly characterizes Hirschberg's algorithm for reconstructing an LCS?

Longest Common Subsequence Hard
A. It uses time and auxiliary workspace
B. It uses time and auxiliary workspace
C. It uses time and auxiliary workspace
D. It uses time and auxiliary workspace

56 A top-down LCS memory function follows only the diagonal dependency when the current characters match. If and both have length , how many distinct states are evaluated from the initial call ?

Longest Common Subsequence Hard
A.
B.
C.
D.

57 Two strings have lengths and , and their LCS length is . What is their minimum edit distance when the only permitted operations are insertion and deletion, each with unit cost?

Longest Common Subsequence Hard
A.
B.
C.
D.

58 An optimal BST has successful-search probabilities , and unsuccessful-search probabilities , , . Using the standard recurrence with , which root is optimal and what is the expected cost?

Optimal Binary Search Trees Hard
A. Root with expected cost
B. Root with expected cost
C. Root with expected cost
D. Root with expected cost

59 For an optimal BST recurrence satisfying Knuth's monotonicity condition, which interval contains an optimal root , and what time bound follows when only that interval is searched?

Optimal Binary Search Trees Hard
A. , giving time
B. , giving time
C. , giving time
D. , giving time

60 Four ordered keys have successful-search probabilities , with unsuccessful-search probabilities omitted. Under the recurrence , what are the optimal root and cost?

Optimal Binary Search Trees Hard
A. Key with expected cost
B. Key with expected cost
C. Key with expected cost
D. Key with expected cost