1Dynamic 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
Correct Answer: Overlapping subproblems
Explanation:
Dynamic programming avoids repeated work by solving overlapping subproblems once and reusing their results.
Incorrect! Try again.
2What 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
Correct Answer: Memoization and tabulation
Explanation:
Memoization is top-down, while tabulation is bottom-up.
Incorrect! Try again.
3What 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
Correct Answer: An optimal solution contains optimal solutions to subproblems
Explanation:
Optimal substructure means the best solution to a problem can be built from the best solutions to its subproblems.
Incorrect! Try again.
4What is the value of for any nonnegative integer ?
Computing a Binomial Coefficient
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
There is exactly one way to choose no elements from a set, so .
Incorrect! Try again.
5Which recurrence is used to compute a binomial coefficient using dynamic programming?
Computing a Binomial Coefficient
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Pascal's identity expresses each binomial coefficient as the sum of two smaller coefficients.
Incorrect! Try again.
6What 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
Correct Answer: To store previously computed results
Explanation:
A memory function stores results so that the same subproblem does not need to be solved repeatedly.
Incorrect! Try again.
7A memory-function implementation of dynamic programming is commonly called what?
Memory Functions
Easy
A.Partitioning
B.Linear scanning
C.Memoization
D.Backtracking
Correct Answer: Memoization
Explanation:
Memoization is a top-down technique that caches the results of solved subproblems.
Incorrect! Try again.
8In 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
Correct Answer: At most once
Explanation:
The term means an item is either excluded or included once.
Incorrect! Try again.
9What 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
Correct Answer: Maximize total value within the capacity
Explanation:
The goal is to select items with the greatest total value without exceeding the knapsack capacity.
Incorrect! Try again.
10A 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
Correct Answer: An item of weight
Explanation:
An item fits when its weight is no greater than the capacity. Since , the first item fits.
Incorrect! Try again.
11Which 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
Correct Answer: Fractional knapsack allows part of an item
Explanation:
In fractional knapsack, an item may be divided, whereas a knapsack item must be taken whole or left out.
Incorrect! Try again.
12What 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
Correct Answer: The number of scalar multiplications
Explanation:
Different parenthesizations can require different numbers of scalar multiplications, even though the final product is the same.
Incorrect! Try again.
13When can a matrix of size be multiplied by a matrix of size ?
Matrix-Chain Multiplication
Easy
A.When
B.When
C.When
D.When
Correct Answer: When
Explanation:
Matrix multiplication is defined when the number of columns in the first matrix equals the number of rows in the second.
Incorrect! Try again.
14How many scalar multiplications are needed to multiply a matrix by a matrix using the standard method?
Matrix-Chain Multiplication
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Multiplying a matrix by a matrix requires operations, so .
Incorrect! Try again.
15In 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
Correct Answer: No, but their order must be preserved
Explanation:
A subsequence may skip characters, but it must preserve the relative order of the selected characters.
Incorrect! Try again.
16What is the length of a longest common subsequence of the strings and ?
Longest Common Subsequence
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
The string is a subsequence of , so the LCS has length .
Incorrect! Try again.
17If 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
Correct Answer: Add to the diagonal entry
Explanation:
When the characters match, they extend a common subsequence represented by the diagonal subproblem.
Incorrect! Try again.
18What 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
Correct Answer: Expected search cost
Explanation:
An optimal binary search tree arranges keys to minimize the expected number of comparisons based on search probabilities.
Incorrect! Try again.
19Which 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
Correct Answer: Search probabilities of keys
Explanation:
Search probabilities help determine which keys should be placed closer to the root.
Incorrect! Try again.
20In 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
Correct Answer: Near the root
Explanation:
Placing frequently searched keys near the root reduces their average number of comparisons.
Incorrect! Try again.
21A 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
Correct Answer: Overlapping subproblems and optimal substructure
Explanation:
Dynamic programming is effective when subproblems overlap and optimal solutions can be constructed from optimal solutions to smaller subproblems.
Incorrect! Try again.
22A 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
Correct Answer: time and space
Explanation:
The algorithm performs one iteration per Fibonacci number and retains only two previous values.
Incorrect! Try again.
23In 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
Correct Answer: The selected edge may lead to an expensive remaining path
Explanation:
A locally cheapest edge need not produce the cheapest complete path because the cost of the remaining path also matters.
Incorrect! Try again.
24Using , what is the value of ?
Computing a Binomial Coefficient
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
, which is also obtained from .
Incorrect! Try again.
25A 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
Correct Answer: To preserve values from the previous row during updates
Explanation:
A descending update ensures that still contains its previous-row value when computing the new .
Incorrect! Try again.
26A 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
Correct Answer: When the recursive calls reach only part of the table
Explanation:
Memoization computes states on demand, so unreachable states need not be evaluated.
Incorrect! Try again.
27A 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
Correct Answer: Use a separate Boolean array for visited states
Explanation:
A separate visited flag distinguishes an uncomputed state from a computed state whose legitimate value is .
Incorrect! Try again.
28A knapsack has capacity . Items have pairs , , , and . What is the maximum obtainable value?
Knapsack Problem
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The weight- item gives value . The only useful two-item combination has weights and value .
Incorrect! Try again.
29Let 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.
Correct Answer:
Explanation:
The item is either excluded or included once, in which case the remaining capacity uses only the first items.
Incorrect! Try again.
30During 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
Correct Answer: Include item and set
Explanation:
The strict improvement shows that item was included, so its weight must be removed from the remaining capacity.
Incorrect! Try again.
31When 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
Correct Answer: Selecting the current item more than once
Explanation:
Descending capacities ensure that each update uses values from before the current item was processed, enforcing the restriction.
Incorrect! Try again.
32Matrices , , and have dimensions , , and . What is the minimum number of scalar multiplications?
Matrix-Chain Multiplication
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
For , the cost is , less than the alternative.
Incorrect! Try again.
33A 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.
Correct Answer:
Explanation:
The optimal form is , with cost .
Incorrect! Try again.
34For four matrices, the split table contains , , and . Which optimal parenthesization does this describe?
Matrix-Chain Multiplication
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The main split is between and , while each two-matrix subchain is multiplied as a pair.
Incorrect! Try again.
35What is the length of a longest common subsequence of and ?
Longest Common Subsequence
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
A common subsequence of length is . No common subsequence of length exists.
Incorrect! Try again.
36Let denote the LCS length of prefixes and . If , which recurrence should be used?
Longest Common Subsequence
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
When the final characters differ, an LCS must omit one of them, so the larger neighboring subproblem is selected.
Incorrect! Try again.
37The 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.
Correct Answer:
Explanation:
The minimum is operations.
Incorrect! Try again.
38Three 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
Correct Answer: The second key
Explanation:
Placing the second key at the root gives expected cost , which is lower than using an outer key.
Incorrect! Try again.
39In 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
Correct Answer: Every search in the interval moves one level deeper
Explanation:
Attaching the interval below a root increases the depth, and therefore the search cost, of every key and gap in that interval by one.
Incorrect! Try again.
40Why 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
Correct Answer: It minimizes expected search cost using access probabilities
Explanation:
Frequently accessed keys may be placed near the root, producing a lower expected cost even if the resulting tree is not height-balanced.
Incorrect! Try again.
41A 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
Correct Answer: Process increasingly, and for each , process increasingly
Explanation:
Increasing row-major order places the three dependencies earlier in the traversal. The other orders can request a state from the current or previous row before it has been computed.
Incorrect! Try again.
42A 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
Correct Answer: A higher-reward prefix may use more edges, so the state should include the edge budget
Explanation:
Prefixes ending at the same vertex are not interchangeable when they consume different numbers of edges. A sufficient state is typically , where records the number of edges used or remaining.
Incorrect! Try again.
43A 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.
Correct Answer:
Explanation:
The left-to-right updates produce because newly updated values are reused. Updating from right to left is required to obtain the correct value .
Incorrect! Try again.
44Consider 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.
Correct Answer:
Explanation:
For each , five non-base values of are reachable. Thus the number of non-base states is .
Incorrect! Try again.
45A 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.
Correct Answer:
Explanation:
Every legitimate LCS value is , so no state is recognized as cached. The recursion follows the binomial recurrence, giving calls.
Incorrect! Try again.
46A 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
Correct Answer: time and space
Explanation:
Each reachable state is evaluated once, and each reachable dependency edge is inspected once. The memo table stores one result per reachable state.
Incorrect! Try again.
47For 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
Correct Answer: Reported ; true optimum
Explanation:
Increasing scans allow the same item to be reused within its own iteration. The algorithm reports , corresponding to repeated use, whereas selecting both items once gives the true 0/1 optimum .
Incorrect! Try again.
48An 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
Correct Answer: The optimum for capacity at most
Explanation:
Zero initialization makes unreachable residual capacities appear feasible. The item of weight and value is therefore accepted, which is valid for an at-most-capacity problem but not for exact fill.
Incorrect! Try again.
49A 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
Correct Answer: Store a decision for each pair and backtrack through item rows
Explanation:
A two-dimensional decision table preserves which item row produced each choice. Backtracking from then moves to earlier rows, ensuring that no item is selected more than once.
Incorrect! Try again.
50When 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
Correct Answer: Store the minimum weight for each value in time
Explanation:
Define as the minimum weight needed to obtain value . After processing all items, choose the largest with , using time.
Incorrect! Try again.
51Four 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
Correct Answer: with cost
Explanation:
The two pair costs are and . Multiplying the resulting and matrices costs , for a total of .
Incorrect! Try again.
52The 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.
Correct Answer:
Explanation:
The total is candidate splits.
Incorrect! Try again.
53A 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.
Correct Answer:
Explanation:
Every parenthesization performs five multiplications of matrices and therefore has the same cost. The number of parenthesizations is the Catalan number .
Incorrect! Try again.
54For and , the LCS length is . Which sequence is not an LCS of the two strings?
Longest Common Subsequence
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
is not a subsequence of because no occurs after its . Each of the other sequences is a common subsequence of length .
Incorrect! Try again.
55For 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
Correct Answer: It uses time and auxiliary workspace
Explanation:
Hirschberg recursively divides one string and uses forward and backward linear-space DP rows. It preserves time while reducing auxiliary table space to linear in the shorter length.
Incorrect! Try again.
56A 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.
Correct Answer:
Explanation:
The calls follow . Thus only states are evaluated, illustrating that demand-driven memoization may avoid most of the full table.
Incorrect! Try again.
57Two 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.
Correct Answer:
Explanation:
Characters outside an LCS must be deleted from the first string or inserted into it. The distance is .
Incorrect! Try again.
58An 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
Correct Answer: Root with expected cost
Explanation:
Choosing gives cost , while choosing gives .
Incorrect! Try again.
59For 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
Correct Answer: , giving time
Explanation:
Knuth's optimization restricts the root search to the interval between the neighboring optimal roots. The total number of examined candidates over all subproblems becomes .
Incorrect! Try again.
60Four 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
Correct Answer: Key with expected cost
Explanation:
With key as root, the left interval has cost , the right singleton has cost , and the total probability is . Hence the cost is .
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →