Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Question 1 of 60 · Introduction to Dynamic Programming · Easy
Dynamic programming is especially useful when a problem has which property?
Not quite. Try another option.
Answer: Overlapping subproblems
Dynamic programming avoids repeated work by solving overlapping subproblems once and reusing their results.
Question 2 of 60 · Introduction to Dynamic Programming · Easy
What are the two common approaches used to implement dynamic programming?
Not quite. Try another option.
Answer: Memoization and tabulation
Memoization is top-down, while tabulation is bottom-up.
Question 3 of 60 · Introduction to Dynamic Programming · Easy
What does optimal substructure mean?
Not quite. Try another option.
Answer: An optimal solution contains optimal solutions to subproblems
Optimal substructure means the best solution to a problem can be built from the best solutions to its subproblems.
Question 4 of 60 · Computing a Binomial Coefficient · Easy
What is the value of for any nonnegative integer ?
Not quite. Try another option.
Answer:
There is exactly one way to choose no elements from a set, so .
Question 5 of 60 · Computing a Binomial Coefficient · Easy
Which recurrence is used to compute a binomial coefficient using dynamic programming?
Not quite. Try another option.
Answer:
Pascal's identity expresses each binomial coefficient as the sum of two smaller coefficients.
Question 6 of 60 · Memory Functions · Easy
What is the main purpose of a memory function?
Not quite. Try another option.
Answer: To store previously computed results
A memory function stores results so that the same subproblem does not need to be solved repeatedly.
Question 7 of 60 · Memory Functions · Easy
A memory-function implementation of dynamic programming is commonly called what?
Not quite. Try another option.
Answer: Memoization
Memoization is a top-down technique that caches the results of solved subproblems.
Question 8 of 60 · Knapsack Problem · Easy
In the knapsack problem, how many times may each item be selected?
Not quite. Try another option.
Answer: At most once
The term means an item is either excluded or included once.
Question 9 of 60 · Knapsack Problem · Easy
What is the objective of the knapsack problem?
Not quite. Try another option.
Answer: Maximize total value within the capacity
The goal is to select items with the greatest total value without exceeding the knapsack capacity.
Question 10 of 60 · Knapsack Problem · Easy
A knapsack has capacity . Which single item can fit in it?
Not quite. Try another option.
Answer: An item of weight
An item fits when its weight is no greater than the capacity. Since , the first item fits.
Question 11 of 60 · Knapsack Problem · Easy
Which statement distinguishes fractional knapsack from knapsack?
Not quite. Try another option.
Answer: Fractional knapsack allows part of an item
In fractional knapsack, an item may be divided, whereas a knapsack item must be taken whole or left out.
Question 12 of 60 · Matrix-Chain Multiplication · Easy
What does the matrix-chain multiplication problem seek to minimize?
Not quite. Try another option.
Answer: The number of scalar multiplications
Different parenthesizations can require different numbers of scalar multiplications, even though the final product is the same.
Question 13 of 60 · Matrix-Chain Multiplication · Easy
When can a matrix of size be multiplied by a matrix of size ?
Not quite. Try another option.
Answer: When
Matrix multiplication is defined when the number of columns in the first matrix equals the number of rows in the second.
Question 14 of 60 · Matrix-Chain Multiplication · Easy
How many scalar multiplications are needed to multiply a matrix by a matrix using the standard method?
Not quite. Try another option.
Answer:
Multiplying a matrix by a matrix requires operations, so .
Question 15 of 60 · Longest Common Subsequence · Easy
In a subsequence, must the selected characters be contiguous in the original sequence?
Not quite. Try another option.
Answer: No, but their order must be preserved
A subsequence may skip characters, but it must preserve the relative order of the selected characters.
Question 16 of 60 · Longest Common Subsequence · Easy
What is the length of a longest common subsequence of the strings and ?
Not quite. Try another option.
Answer:
The string is a subsequence of , so the LCS has length .
Question 17 of 60 · Longest Common Subsequence · Easy
If the current characters of two sequences match, how is the corresponding LCS table entry commonly computed?
Not quite. Try another option.
Answer: Add to the diagonal entry
When the characters match, they extend a common subsequence represented by the diagonal subproblem.
Question 18 of 60 · Optimal Binary Search Trees · Easy
What does an optimal binary search tree minimize?
Not quite. Try another option.
Answer: Expected search cost
An optimal binary search tree arranges keys to minimize the expected number of comparisons based on search probabilities.
Question 19 of 60 · Optimal Binary Search Trees · Easy
Which information is commonly used to construct an optimal binary search tree?
Not quite. Try another option.
Answer: Search probabilities of keys
Search probabilities help determine which keys should be placed closer to the root.
Question 20 of 60 · Optimal Binary Search Trees · Easy
In an optimal binary search tree, frequently searched keys are generally placed where?
Not quite. Try another option.
Answer: Near the root
Placing frequently searched keys near the root reduces their average number of comparisons.
Question 21 of 60 · Introduction to Dynamic Programming · Medium
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?
Not quite. Try another option.
Answer: Overlapping subproblems and optimal substructure
Dynamic programming is effective when subproblems overlap and optimal solutions can be constructed from optimal solutions to smaller subproblems.
Question 22 of 60 · Introduction to Dynamic Programming · Medium
A bottom-up Fibonacci algorithm stores only the two most recently computed values. What are its time and auxiliary space complexities for computing ?
Not quite. Try another option.
Answer: time and space
The algorithm performs one iteration per Fibonacci number and retains only two previous values.
Question 23 of 60 · Introduction to Dynamic Programming · Medium
In a shortest-path problem on a staged graph, why can choosing the minimum-weight outgoing edge at every vertex fail?
Not quite. Try another option.
Answer: The selected edge may lead to an expensive remaining path
A locally cheapest edge need not produce the cheapest complete path because the cost of the remaining path also matters.
Question 24 of 60 · Computing a Binomial Coefficient · Medium
Using , what is the value of ?
Not quite. Try another option.
Answer:
, which is also obtained from .
Question 25 of 60 · Computing a Binomial Coefficient · Medium
A one-dimensional array is used to compute binomial coefficients. For each row , why should entries be updated from larger to smaller ?
Not quite. Try another option.
Answer: To preserve values from the previous row during updates
A descending update ensures that still contains its previous-row value when computing the new .
Question 26 of 60 · Memory Functions · Medium
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?
Not quite. Try another option.
Answer: When the recursive calls reach only part of the table
Memoization computes states on demand, so unreachable states need not be evaluated.
Question 27 of 60 · Memory Functions · Medium
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?
Not quite. Try another option.
Answer: Use a separate Boolean array for visited states
A separate visited flag distinguishes an uncomputed state from a computed state whose legitimate value is .
Question 28 of 60 · Knapsack Problem · Medium
A knapsack has capacity . Items have pairs , , , and . What is the maximum obtainable value?
Not quite. Try another option.
Answer:
The weight- item gives value . The only useful two-item combination has weights and value .
Question 29 of 60 · Knapsack Problem · Medium
Let be the maximum value using the first items with capacity . If item has weight and value , which recurrence represents the knapsack choice?
Not quite. Try another option.
Answer:
The item is either excluded or included once, in which case the remaining capacity uses only the first items.
Question 30 of 60 · Knapsack Problem · Medium
During reconstruction of a knapsack solution, suppose . What action is justified?
Not quite. Try another option.
Answer: Include item and set
The strict improvement shows that item was included, so its weight must be removed from the remaining capacity.
Question 31 of 60 · Knapsack Problem · Medium
When implementing knapsack with a one-dimensional array, capacities are processed from down to for each item. What does this ordering prevent?
Not quite. Try another option.
Answer: Selecting the current item more than once
Descending capacities ensure that each update uses values from before the current item was processed, enforcing the restriction.
Question 32 of 60 · Matrix-Chain Multiplication · Medium
Matrices , , and have dimensions , , and . What is the minimum number of scalar multiplications?
Not quite. Try another option.
Answer:
For , the cost is , less than the alternative.
Question 33 of 60 · Matrix-Chain Multiplication · Medium
A matrix chain has dimension array . What is the minimum number of scalar multiplications needed to multiply all four matrices?
Not quite. Try another option.
Answer:
The optimal form is , with cost .
Question 34 of 60 · Matrix-Chain Multiplication · Medium
For four matrices, the split table contains , , and . Which optimal parenthesization does this describe?
Not quite. Try another option.
Answer:
The main split is between and , while each two-matrix subchain is multiplied as a pair.
Question 35 of 60 · Longest Common Subsequence · Medium
What is the length of a longest common subsequence of and ?
Not quite. Try another option.
Answer:
A common subsequence of length is . No common subsequence of length exists.
Question 36 of 60 · Longest Common Subsequence · Medium
Let denote the LCS length of prefixes and . If , which recurrence should be used?
Not quite. Try another option.
Answer:
When the final characters differ, an LCS must omit one of them, so the larger neighboring subproblem is selected.
Question 37 of 60 · Longest Common Subsequence · Medium
The strings and have an LCS of length . Using only insertions and deletions, what is the minimum number of operations required to transform into ?
Not quite. Try another option.
Answer:
The minimum is operations.
Question 38 of 60 · Optimal Binary Search Trees · Medium
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?
Not quite. Try another option.
Answer: The second key
Placing the second key at the root gives expected cost , which is lower than using an outer key.
Question 39 of 60 · Optimal Binary Search Trees · Medium
In the optimal BST recurrence, why is the total probability weight added after selecting a root for keys through ?
Not quite. Try another option.
Answer: Every search in the interval moves one level deeper
Attaching the interval below a root increases the depth, and therefore the search cost, of every key and gap in that interval by one.
Question 40 of 60 · Optimal Binary Search Trees · Medium
Why can an optimal binary search tree be structurally unbalanced even when a balanced BST is possible?
Not quite. Try another option.
Answer: It minimizes expected search cost using access probabilities
Frequently accessed keys may be placed near the root, producing a lower expected cost even if the resulting tree is not height-balanced.
Question 41 of 60 · Introduction to Dynamic Programming · Hard
A table entry depends on , , and , with row and column initialized. Which traversal computes every dependency before it is used?
Not quite. Try another option.
Answer: Process increasingly, and for each , process increasingly
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.
Question 42 of 60 · Introduction to Dynamic Programming · Hard
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?
Not quite. Try another option.
Answer: A higher-reward prefix may use more edges, so the state should include the edge budget
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.
Question 43 of 60 · Computing a Binomial Coefficient · Hard
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 ?
Not quite. Try another option.
Answer:
The left-to-right updates produce because newly updated values are reused. Updating from right to left is required to obtain the correct value .
Question 44 of 60 · Computing a Binomial Coefficient · Hard
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 ?
Not quite. Try another option.
Answer:
For each , five non-base values of are reachable. Thus the number of non-base states is .
Question 45 of 60 · Memory Functions · Hard
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?
Not quite. Try another option.
Answer:
Every legitimate LCS value is , so no state is recognized as cached. The recursion follows the binomial recurrence, giving calls.
Question 46 of 60 · Memory Functions · Hard
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?
Not quite. Try another option.
Answer: time and space
Each reachable state is evaluated once, and each reachable dependency edge is inspected once. The memo table stores one result per reachable state.
Question 47 of 60 · Knapsack Problem · Hard
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?
Not quite. Try another option.
Answer: Reported ; true optimum
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 .
Question 48 of 60 · Knapsack Problem · Hard
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?
Not quite. Try another option.
Answer: The optimum for capacity at most
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.
Question 49 of 60 · Knapsack Problem · Hard
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?
Not quite. Try another option.
Answer: Store a decision for each pair and backtrack through item rows
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.
Question 50 of 60 · Knapsack Problem · Hard
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 ?
Not quite. Try another option.
Answer: Store the minimum weight for each value in time
Define as the minimum weight needed to obtain value . After processing all items, choose the largest with , using time.
Question 51 of 60 · Matrix-Chain Multiplication · Hard
Four matrices have dimensions , , , and . Which parenthesization minimizes scalar multiplications, and what is its cost?
Not quite. Try another option.
Answer: with cost
The two pair costs are and . Multiplying the resulting and matrices costs , for a total of .
Question 52 of 60 · Matrix-Chain Multiplication · Hard
The standard bottom-up matrix-chain algorithm tests every split for every interval . How many candidate splits are examined for a chain of matrices?
Not quite. Try another option.
Answer:
The total is candidate splits.
Question 53 of 60 · Matrix-Chain Multiplication · Hard
A chain contains six matrices, each of dimension . Assuming only scalar multiplication count matters, how many distinct parenthesizations are optimal?
Not quite. Try another option.
Answer:
Every parenthesization performs five multiplications of matrices and therefore has the same cost. The number of parenthesizations is the Catalan number .
Question 54 of 60 · Longest Common Subsequence · Hard
For and , the LCS length is . Which sequence is not an LCS of the two strings?
Not quite. Try another option.
Answer:
is not a subsequence of because no occurs after its . Each of the other sequences is a common subsequence of length .
Question 55 of 60 · Longest Common Subsequence · Hard
For strings of lengths and , which statement correctly characterizes Hirschberg's algorithm for reconstructing an LCS?
Not quite. Try another option.
Answer: It uses time and auxiliary workspace
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.
Question 56 of 60 · Longest Common Subsequence · Hard
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 ?
Not quite. Try another option.
Answer:
The calls follow . Thus only states are evaluated, illustrating that demand-driven memoization may avoid most of the full table.
Question 57 of 60 · Longest Common Subsequence · Hard
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?
Not quite. Try another option.
Answer:
Characters outside an LCS must be deleted from the first string or inserted into it. The distance is .
Question 58 of 60 · Optimal Binary Search Trees · Hard
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?
Not quite. Try another option.
Answer: Root with expected cost
Choosing gives cost , while choosing gives .
Question 59 of 60 · Optimal Binary Search Trees · Hard
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?
Not quite. Try another option.
Answer: , giving time
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 .
Question 60 of 60 · Optimal Binary Search Trees · Hard
Four ordered keys have successful-search probabilities , with unsuccessful-search probabilities omitted. Under the recurrence , what are the optimal root and cost?
Not quite. Try another option.
Answer: Key with expected cost
With key as root, the left interval has cost , the right singleton has cost , and the total probability is . Hence the cost is .
That's unit 3
Answer a few questions and your score shows up here.
Nearly through. Did unit 3 of CSE408 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 3 of CSE408 save you a night before the exam?
Then you can help keep it free for the next batch. 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.