Correct Answer: An optimal solution contains optimal subproblem solutions
Explanation:
A problem has optimal substructure when its best overall solution can be built from best solutions to smaller subproblems.
Incorrect! Try again.
16Which type of problem is most likely to have optimal substructure?
Optimal Substructure Property
Easy
A.A shortest path problem
B.A problem with no valid solutions
C.A problem requiring random output
D.A problem with unrelated calculations
Correct Answer: A shortest path problem
Explanation:
A shortest path often contains shortest paths between intermediate points, which is an example of optimal substructure.
Incorrect! Try again.
17What are overlapping subproblems?
Overlapping Subproblems Property
Easy
A.Subproblems with different input types
B.Subproblems that appear repeatedly
C.Subproblems that cannot be solved
D.Subproblems solved only once
Correct Answer: Subproblems that appear repeatedly
Explanation:
Overlapping subproblems occur when the same smaller problem is needed multiple times.
Incorrect! Try again.
18Why does dynamic programming store results of subproblems?
Overlapping Subproblems Property
Easy
A.To avoid solving the same subproblem again
B.To repeat calculations
C.To remove all base cases
D.To increase the input size
Correct Answer: To avoid solving the same subproblem again
Explanation:
Storing results allows later computations to reuse them instead of recalculating the same values.
Incorrect! Try again.
19Which step should usually be performed first when solving a dynamic programming problem?
Dynamic Programming Process and Techniques
Easy
A.Delete the input
B.Print the final answer
C.Choose random base cases
D.Define the states
Correct Answer: Define the states
Explanation:
Defining the state clarifies what each stored value represents and supports the transition design.
Incorrect! Try again.
20What is a base case in dynamic programming?
Dynamic Programming Process and Techniques
Easy
A.A directly known small subproblem
B.A state that is always ignored
C.The largest possible input
D.A value selected after the program ends
Correct Answer: A directly known small subproblem
Explanation:
Base cases provide known starting values from which other DP states can be calculated.
Incorrect! Try again.
21Which situation most strongly suggests that dynamic programming should be used?
Introduction to Dynamic Programming
Medium
A.Subproblems repeat and their solutions can be combined
B.Each recursive call produces entirely new subproblems
C.The solution requires sorting before any computation
D.Every input element must be processed exactly once
Correct Answer: Subproblems repeat and their solutions can be combined
Explanation:
Dynamic programming is most useful when a problem has overlapping subproblems and optimal substructure.
Incorrect! Try again.
22A recursive algorithm makes many repeated calls with the same arguments. What change most directly converts it into a dynamic programming solution?
Introduction to Dynamic Programming
Medium
A.Sort the arguments before each call
B.Process the largest argument before the others
C.Store each computed result and reuse it
D.Replace every loop with a recursive call
Correct Answer: Store each computed result and reuse it
Explanation:
Caching results prevents the algorithm from recomputing identical subproblems.
Incorrect! Try again.
23Using , , and , what is the minimum auxiliary space needed to compute only iteratively?
Fibonacci Sequence
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Only the two previous Fibonacci values are needed, so a constant number of variables is sufficient.
Incorrect! Try again.
24A memoized recursive implementation computes . If each state for is evaluated at most once, what is its time complexity?
Fibonacci Sequence
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Memoization evaluates each of the Fibonacci states once, with constant work per state.
Incorrect! Try again.
25A board is tiled using dominoes placed vertically or horizontally. Which recurrence correctly counts the tilings?
Tiling problem
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The final placement is either one vertical domino, leaving width , or two horizontal dominoes, leaving width .
Incorrect! Try again.
26For the domino tiling problem with and , how many tilings exist for a board?
Tiling problem
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Using gives , , , and .
Incorrect! Try again.
27A person may climb , , or stairs at a time. If is the number of ways to reach stair , which transition is correct for ?
Climbing Stairs
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The final move reaches stair from stair , , or .
Incorrect! Try again.
28In a minimum-cost climbing problem, stepping on stair costs , and one may move one or two stairs. If is the minimum cost to reach stair , which transition is appropriate?
Climbing Stairs
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Stair can be reached from either previous valid stair, so the cheaper previous cost is selected before adding .
Incorrect! Try again.
29A problem has possible states, but a particular input reaches only states, where . Which approach may avoid evaluating the unreachable states?
Tabulation vs Memoizatation
Medium
A.Full-state enumeration
B.Bottom-up tabulation
C.Top-down memoization
D.Level-order traversal
Correct Answer: Top-down memoization
Explanation:
Memoization computes states on demand, so states not reached by the recursion may remain unevaluated.
Incorrect! Try again.
30Which implementation issue is generally avoided by replacing a deep top-down memoized solution with an equivalent bottom-up tabulation?
Tabulation vs Memoizatation
Medium
A.Duplicate output
B.Integer overflow
C.Stack overflow
D.Invalid input
Correct Answer: Stack overflow
Explanation:
Bottom-up tabulation uses iteration and therefore avoids a potentially deep recursive call stack.
Incorrect! Try again.
31For the knapsack problem, which state definition contains enough information to decide whether item may be included?
State Definition and State Transition
Medium
A.: best value using exactly item
B.: best value using the first items with capacity
C.: number of items having weight
D.: minimum index of an item with value
Correct Answer: : best value using the first items with capacity
Explanation:
The decision depends on both how many items are available and the remaining capacity.
Incorrect! Try again.
32Let be the length of the longest increasing subsequence ending at index . Which transition correctly computes ?
State Definition and State Transition
Medium
A. over all with
B. over all with
C. over all with
D. whenever
Correct Answer: over all with
Explanation:
An increasing subsequence ending at extends the longest valid subsequence ending at an earlier smaller element.
Incorrect! Try again.
33Why does the shortest-path problem exhibit optimal substructure when all considered path costs are well-defined?
Optimal Substructure Property
Medium
A.Every shortest path visits all vertices in the graph
B.Every prefix of a shortest path is itself a shortest path
C.Every edge on a shortest path has the smallest graph weight
D.Every pair of vertices has exactly one shortest path
Correct Answer: Every prefix of a shortest path is itself a shortest path
Explanation:
If a prefix were not shortest, replacing it with a shorter prefix would produce a shorter complete path.
Incorrect! Try again.
34An optimization problem lacks optimal substructure. What is the main consequence for a proposed dynamic programming recurrence?
Optimal Substructure Property
Medium
A.The base cases cannot contain constant values
B.Memoization will always be slower than direct recursion
C.The recurrence must always require exponential storage
D.Locally optimal subproblem solutions may not form a global optimum
Correct Answer: Locally optimal subproblem solutions may not form a global optimum
Explanation:
Dynamic programming relies on constructing an optimal full solution from optimal solutions to suitable subproblems.
Incorrect! Try again.
35In the naive recursive computation of , which observation demonstrates overlapping subproblems?
Overlapping Subproblems Property
Medium
A. and are specified as base cases
B. is larger than both of its preceding values
C. is reached through multiple recursive branches
D. can be computed with integer addition
Correct Answer: is reached through multiple recursive branches
Explanation:
The same Fibonacci states are repeatedly recomputed in different branches of the recursion tree.
Incorrect! Try again.
36A divide-and-conquer algorithm splits an input into disjoint subarrays that are never processed again. Why might memoization provide little benefit?
Overlapping Subproblems Property
Medium
A.The subproblems have no valid base cases
B.The subproblems do not significantly overlap
C.The input cannot be represented as an array
D.The recursive tree must have constant depth
Correct Answer: The subproblems do not significantly overlap
Explanation:
Memoization saves work only when identical subproblems would otherwise be solved more than once.
Incorrect! Try again.
37After defining states and deriving a transition, what should be established before filling a bottom-up DP table?
Dynamic Programming Process and Techniques
Medium
A.Base cases and a valid evaluation order
B.A sorted input and a binary search rule
C.A recursive tree and a greedy selection rule
D.A random order and a stopping probability
Correct Answer: Base cases and a valid evaluation order
Explanation:
Each table entry must be computed only after the states on which it depends are available.
Incorrect! Try again.
38A two-dimensional DP transition uses only the current row and the immediately preceding row. Which optimization is generally valid?
Dynamic Programming Process and Techniques
Medium
A.Discard each row before computing its successor
B.Store only the first row for every iteration
C.Replace the table with an unordered set
D.Store only two rows and alternate between them
Correct Answer: Store only two rows and alternate between them
Explanation:
Rows older than the previous row are no longer needed, so rolling arrays reduce space while preserving required dependencies.
Incorrect! Try again.
39To find the minimum number of coins needed to form amount with unlimited coin reuse, which recurrence is appropriate?
Formulating Dynamic Programming Problems
Medium
A. over coins
B. over coins
C. over coins
D. over coins
Correct Answer: over coins
Explanation:
Choosing coin leaves amount ; adding one coin to the best solution for that remainder gives a candidate minimum.
Incorrect! Try again.
40A robot moves from the top-left to the bottom-right of a grid using only right or down moves. Some cells are blocked. If counts valid paths to cell , how should a blocked cell be handled?
Formulating Dynamic Programming Problems
Medium
A.Copy
B.Set
C.Set
D.Take
Correct Answer: Set
Explanation:
No valid path can end at a blocked cell, so it contributes zero paths to later states.
Incorrect! Try again.
41A recurrence is defined by with . Under which condition can all states be evaluated once in a fixed order without repeated relaxation?
Introduction to Dynamic Programming
Hard
A.All edge weights are positive and vertices are processed by index
B.Every vertex has equal indegree and states are processed breadth-first
C.The graph is connected and states are processed depth-first
D.The graph is a DAG and states are processed in topological order
Correct Answer: The graph is a DAG and states are processed in topological order
Explanation:
A topological order guarantees that every predecessor is finalized before is evaluated. General cyclic graphs may require repeated relaxation or another shortest-path algorithm.
Incorrect! Try again.
42Suppose and . A fast-doubling algorithm recursively computes . Which identities correctly produce ?
Fibonacci Sequence
Hard
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
These doubling identities reduce the index by half at each recursive call, allowing Fibonacci numbers to be computed in time.
Incorrect! Try again.
43Let be the number of tilings of a board using dominoes. Exactly one specified cell in the top row of column , where , is blocked. Which expression gives the number of valid tilings?
Tiling problem
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The blocked cell forces a horizontal domino across the bottom cells adjacent to the boundary and separates the remaining board into independent and regions. Their counts are and .
Incorrect! Try again.
44A climber may take , , or steps at a time. Landing on step is forbidden, but jumping over it is allowed. If counts sequences that land exactly on step , what is ?
Climbing Stairs
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Use with , negative states equal to , and . This gives , , and .
Incorrect! Try again.
45A DP has states for and , but from the initial state only states are reachable. Each state has outgoing transitions. Ignoring recursion-stack limits, which comparison is most accurate?
Tabulation vs Memoizatation
Hard
A.Memoization can run in time, while rectangular tabulation runs in time
B.Memoization always runs in time, while tabulation can run in time
C.Both methods necessarily run in time because the state space is rectangular
D.Both methods necessarily run in time because states require lookup
Correct Answer: Memoization can run in time, while rectangular tabulation runs in time
Explanation:
Top-down memoization evaluates only reachable states. A conventional rectangular table still iterates over all state positions, including unreachable ones.
Incorrect! Try again.
46Count length- strings over that contain neither nor as a substring. What is the smallest generally sufficient suffix-based state for a left-to-right DP?
State Definition and State Transition
Hard
A.Only the most recently appended character
B.Only the number of occurrences of character
C.The complete prefix generated up to the current position
D.The longest suffix that is also a prefix of either forbidden pattern
Correct Answer: The longest suffix that is also a prefix of either forbidden pattern
Explanation:
The state must retain exactly the suffix information that may grow into or . Tracking automaton-prefix states is sufficient, while only the last character cannot distinguish all relevant prefixes.
Incorrect! Try again.
47In weighted interval scheduling, jobs are sorted by nondecreasing finish time. Let be the largest index whose job finishes no later than job starts, and let be the maximum weight using jobs through . Which transition is correct?
State Definition and State Transition
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
An optimal solution either excludes job , giving , or includes it and combines with the best solution ending before it starts, namely .
Incorrect! Try again.
48A proposed DP for the longest simple path uses , the longest simple path from vertex to a target, and transitions to for each neighbor . Why is this state invalid on a general cyclic graph?
Optimal Substructure Property
Hard
A.The transition fails only when the graph contains negative edge weights
B.The best continuation from depends on which vertices were already visited
C.Cycles make every longest simple path have infinitely many edges
D.The longest path objective cannot be decomposed across any pair of vertices
Correct Answer: The best continuation from depends on which vertices were already visited
Explanation:
Simplicity couples a subproblem to the path history. The state omits the visited set, so its stored continuation may reuse a vertex already on the prefix.
Incorrect! Try again.
49The naive recursion for uses . For all , how many distinct valid states can be reached from ?
Overlapping Subproblems Property
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Although the recursion tree has exponentially many calls, many calls share the same pair. A quadratic number of valid pairs is reachable around the middle of Pascal's triangle.
Incorrect! Try again.
50A DP transition for state reads only states connected to by incoming dependency edges. What condition is necessary and sufficient for evaluating every state exactly once using a static linear order?
Dynamic Programming Process and Techniques
Hard
A.The dependency graph is weakly connected
B.The dependency graph is acyclic
C.Every transition has a nonnegative cost
D.Every state has constant indegree
Correct Answer: The dependency graph is acyclic
Explanation:
A static order in which every dependency precedes its consumer exists exactly when the dependency graph has a topological ordering, which is equivalent to acyclicity.
Incorrect! Try again.
51For 0/1 knapsack, a one-dimensional table uses for each item . In which order must capacities be processed to prevent using item multiple times?
Formulating Dynamic Programming Problems
Hard
A.In arbitrary order after sorting by value
B.From capacity up to
C.From capacity down to
D.In increasing order after sorting by weight
Correct Answer: From capacity down to
Explanation:
Descending capacity ensures still refers to the previous item's stage. Ascending order could reuse a value updated for the same item, turning the recurrence into unbounded knapsack.
Incorrect! Try again.
52An implementation computes with the recurrence . Why must the pair , rather than a single residue , be used to detect that the sequence has restarted?
Fibonacci Sequence
Hard
A.Consecutive Fibonacci residues are equal exactly once in every period
B.The pair is required only to avoid overflow during modular addition
C.A single residue determines the next residue only when is prime
D.The recurrence has order two, so one residue does not determine the next residue
Correct Answer: The recurrence has order two, so one residue does not determine the next residue
Explanation:
The future sequence is determined by two consecutive residues. The same value can occur with different successors, so it cannot uniquely identify a cycle boundary.
Incorrect! Try again.
53Let count tilings of a board with dominoes and L-trominoes, where rotations are allowed. Using , , and , which recurrence is valid for ?
Tiling problem
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Accounting for complete and one-cell-gap profiles yields the standard recurrence . The gap states are necessary before they are algebraically eliminated.
Incorrect! Try again.
54A climber must reach step using jumps of size or , but two jumps of size may not be consecutive. Which state formulation gives a correct DP?
Climbing Stairs
Hard
A., where the state stores only the number of ways to reach
B., where stores the parity of the current step
C., where stores the number of remaining steps
D., where records whether the last jump had size
Correct Answer: , where records whether the last jump had size
Explanation:
Whether a size- jump is currently legal depends on the previous jump. A one-bit history state captures that constraint without retaining the full jump sequence.
Incorrect! Try again.
55A top-down DP recursively follows a dependency chain of length , and every state is reachable. A bottom-up order is known, and only the previous two values are needed. Which implementation tradeoff is most decisive?
Tabulation vs Memoizatation
Hard
A.Memoization reduces the number of evaluated states below the reachable count
B.Tabulation reduces the asymptotic running time from exponential to logarithmic
C.Memoization avoids deep recursion and can use auxiliary space
D.Tabulation avoids deep recursion and can use auxiliary space
Correct Answer: Tabulation avoids deep recursion and can use auxiliary space
Explanation:
Both approaches evaluate all reachable states, but top-down recursion risks stack overflow and stores a large call stack. Bottom-up evaluation can retain only the two required prior values.
Incorrect! Try again.
56For edit distance with insertion, deletion, substitution, and adjacent transposition, why is the usual transition based only on , , and insufficient?
State Definition and State Transition
Hard
A.A transposition may require a transition from without checking characters
B.A transposition changes string lengths, so the state must include the current operation count
C.A transposition may require a transition from after checking two character pairs
D.A transposition destroys optimal substructure, so no polynomial DP can represent it
Correct Answer: A transposition may require a transition from after checking two character pairs
Explanation:
Swapping two adjacent characters consumes two characters from each prefix. The transition is valid when the two source characters match the two target characters in reversed order.
Incorrect! Try again.
57Let be the length of the longest increasing subsequence ending exactly at index . Which statement justifies the transition ?
Optimal Substructure Property
Hard
A.Every increasing subsequence ending at must contain the largest earlier array value
B.Every globally longest subsequence of the prefix must include the element at index
C.Removing leaves a globally longest subsequence of the entire prefix ending at
D.Removing from such an optimal subsequence leaves an optimal subsequence ending at some valid
Correct Answer: Removing from such an optimal subsequence leaves an optimal subsequence ending at some valid
Explanation:
If the remaining subsequence were not optimal among those ending at its final index , replacing it with a longer one would improve the subsequence ending at .
Incorrect! Try again.
58Consider the recursion with base case . Which observation most directly supports memoization?
Overlapping Subproblems Property
Hard
A.Every recursive call receives a strictly smaller integer argument
B.The recurrence has exactly two recursive terms at each non-base state
C.Different recursion branches can request the same integer argument
D.The recursion tree has a finite maximum depth bounded by
Correct Answer: Different recursion branches can request the same integer argument
Explanation:
Memoization is useful because repeated arguments represent identical subproblems. Decreasing arguments guarantee termination but do not by themselves establish overlap.
Incorrect! Try again.
59A minimum-cost DP is compressed from a full table to two rolling rows. Later, the program must output one optimal sequence of decisions. What is the central issue with the compressed representation?
Dynamic Programming Process and Techniques
Hard
A.Rolling rows change the recurrence from minimization to maximization
B.Discarded rows remove predecessor information needed for direct reconstruction
C.Two-row storage is valid only when every transition cost is identical
D.Compressed storage makes the computed optimum numerically approximate
Correct Answer: Discarded rows remove predecessor information needed for direct reconstruction
Explanation:
Rolling arrays preserve the optimal value when dependencies are local, but they usually discard the history needed to trace decisions. Reconstruction needs stored choices, recomputation, or a divide-and-conquer technique.
Incorrect! Try again.
60You must choose a maximum-value subset of tasks. Each task has a start time, finish time, value, and category; chosen tasks may not overlap, and at most category changes are allowed in chronological order. Which DP state is sufficient after sorting tasks by finish time?
Formulating Dynamic Programming Problems
Hard
A.The latest finish time, the number of skipped tasks, and the largest value
B.The number of chosen tasks, their total value, and the latest finish time
C.The last chosen task, the number of category changes used, and its category
D.The current task index, the total occupied duration, and the first category
Correct Answer: The last chosen task, the number of category changes used, and its category
Explanation:
Compatibility with the next task depends on the last finish time, while the category-change constraint depends on the last category and changes already used. The last task supplies both its finish time and category.
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 →