Dynamic Programming
- 60Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
60 questions
- 1The new section on algorithmic design focuses on how to develop_____to solve a problem.
Hint
Think of the goal of the new section: creating an efficient solution for a problem.
Answer
a polynomial-time algorithm from scratch
Explanation
Algorithmic design focuses on how to construct an algorithm for a problem, rather than only applying algorithms already presented.
- 2The recursive design paradigm that reuses solutions to subproblems is called_____.
Hint
This design paradigm is the central subject of the lecture.
Answer
dynamic programming
Explanation
Dynamic programming is a powerful, general recursive design paradigm that combines recursive solutions with reuse of previously computed work.
- 3The steps summarized by SRTBOT are_____, in order.
Hint
Expand each letter in the acronym, including the final step for analyzing efficiency.
Answer
subproblems, relations, topological order, base case, original problem, and time
Explanation
SRTBOT names the six steps used to specify a recursive algorithm.
- 4When defining subproblems for an efficient recursive algorithm, we generally want_____.
Hint
The desired number should grow no faster than a polynomial in the input size.
Answer
a polynomial number of subproblems
Explanation
A useful recursive design usually defines only polynomially many subproblems so that solving them can lead to a polynomial-time algorithm.
- 5The part of recursive algorithm design that is usually hardest is deciding what_____should be.
Hint
This is the first step of SRTBOT and determines what smaller tasks the algorithm will solve.
Answer
the subproblems
Explanation
Choosing the right subproblems is often the hardest part of designing a recursive algorithm.
- 6The recursive rule that defines how to solve one problem using smaller subproblems is called_____.
Hint
It expresses a recursive structure among the subproblem solutions.
Answer
a recurrence relation
Explanation
A recurrence relation specifies how to solve a subproblem using solutions to smaller subproblems.
- 7In a subproblem graph, the vertices represent_____and the edges represent their dependencies.
Hint
They are the tasks represented by the vertices of the dependency graph.
Answer
subproblems
Explanation
In a subproblem graph, vertices represent subproblems and edges represent dependencies between them.
- 8To avoid infinite recursive calls, the dependencies among subproblems should form_____.
Hint
The desired graph has directed dependencies and no cycles.
Answer
a directed acyclic graph
Explanation
The recursive calls must form a DAG; a cycle could cause the algorithm to keep making recursive calls without terminating.
- 9An order that schedules dependent subproblems only after their prerequisites is called_____.
Hint
This is an ordering of vertices in a DAG that respects its directed edges.
Answer
a topological order
Explanation
A topological order schedules each subproblem after the subproblems it depends on, and can establish an acyclic computation order.
- 10A recursive algorithm needs_____to stop its recursive calls and provide initial solutions.
Hint
These are the simplest cases of a recursive algorithm.
Answer
base cases
Explanation
Base cases provide solutions that do not require further recursive calls and anchor the recursive computation.
- 11In SRTBOT, the algorithm must explain how the subproblem solutions yield_____.
Hint
This is the problem the algorithm was intended to solve in the first place.
Answer
the original problem
Explanation
The original problem is the goal of the algorithm; it may itself be one of the subproblems, or it may need to be assembled from several subproblem solutions.
- 12The final step in SRTBOT is to analyze the algorithm's_____.
Hint
This step measures how the algorithm's resource use grows with input size.
Answer
running time
Explanation
The final SRTBOT step analyzes the algorithm's efficiency after its subproblems, recurrence, order, base cases, and output are specified.
- 13In the SRTBOT description of merge sort, the subproblems involve_____.
Hint
Each recursive task concerns a range of array elements.
Answer
sorting different subarrays of the input array
Explanation
Merge sort solves subproblems that sort portions of the original array.
- 14For an array of length n, merge sort's original problem is_____.
Hint
It is the range from the first array position through the end.
Answer
the subproblem that sorts the entire array
Explanation
The original merge sort problem is the subproblem whose range contains all array elements.
- 15A valid topological order for merge sort's subproblems is to process them in_____.
Hint
The order starts with the smallest ranges and proceeds toward larger ones.
Answer
increasing subarray length
Explanation
The subarrays used by merge sort's recurrence are shorter than the current subarray, so computing subproblems in increasing length gives a valid topological order. The empty array is the base case, and the resulting algorithm has running time n log n.
- 16The Fibonacci sequence is defined using_____and the base values one and one.
Hint
Each value after the initial pair is formed from its two immediate predecessors.
Answer
the recurrence for Fibonacci numbers
Explanation
The Fibonacci sequence is defined by adding the two preceding values, with the first two values equal to one.
- 17The naive recursive algorithm for computing a Fibonacci number takes_____because it repeats subproblems.
Hint
The running time grows exponentially with the input index.
Answer
exponential time
Explanation
The direct recursive Fibonacci algorithm recomputes many of the same values, giving an exponential number of recursive calls.
- 18The technique of storing subproblem solutions and reusing them is called_____.
Hint
It is the key dynamic programming idea of remembering and reusing previous work.
Answer
memoization
Explanation
Memoization means recording solutions to subproblems so later calls can reuse them instead of solving them again.
- 19A common abstract data type for mapping solved subproblems to their solutions is_____.
Hint
It is an abstract data type that associates keys with stored values.
Answer
a dictionary
Explanation
A dictionary can map each solved subproblem to its solution; a direct-access array or a hash table can also implement this role.
- 20When a recursive function is called on a subproblem, it should first_____.
Hint
The stored result should be used before recomputing a subproblem.
Answer
check the memo table and return the stored solution if present
Explanation
The algorithm first checks whether the requested subproblem has already been solved; if so, it returns the saved result without making recursive calls.
- 21With memoization, the algorithm solves_____.
Hint
This is the main reason memoization reduces repeated work.
Answer
each subproblem at most once
Explanation
Once a subproblem's solution is stored in the memo table, future requests reuse it rather than solving it again.
- 22A useful upper bound for memoized running time is_____.
Hint
Count the distinct tasks and the local work required for each one.
Answer
the number of subproblems times the non-recursive work per subproblem
Explanation
Memoized running time can be bounded by counting each distinct subproblem once and adding the work done to evaluate its recurrence, excluding recursive work counted elsewhere.
- 23Under the usual constant-time arithmetic assumption, memoized Fibonacci computation takes_____.
Hint
The number of Fibonacci subproblems grows proportionally to the index.
Answer
linear time
Explanation
Computing the nth Fibonacci number with memoization requires only a linear number of distinct subproblems and a constant number of additions per subproblem under the usual unit-cost assumption.
- 24Because Fibonacci numbers grow exponentially, representing the nth value requires_____.
Hint
The number of bits grows linearly even though the numeric values grow exponentially.
Answer
theta n bits
Explanation
Fibonacci values grow exponentially in the index, so writing down a value requires a number of bits proportional to that index.
- 25If an addition involves n-bit Fibonacci values and the machine word size is w, its time is proportional to_____.
Hint
Divide the bit length by the machine word size and round up.
Answer
ceiling of n over w
Explanation
In the word RAM model, an addition on n-bit values takes a number of word operations proportional to the number of machine words needed to hold the values.
- 26Even when the growing bit lengths of Fibonacci values are considered, the memoized running time is_____.
Hint
This growth rate is efficient in contrast with exponential time.
Answer
polynomial
Explanation
Accounting for the bit lengths makes the memoized algorithm's running time include terms proportional to n and n squared over w, which is still polynomial, unlike the naive exponential algorithm.
- 27Whether memoization substantially improves a recursive algorithm depends on repeated computation of_____.
Hint
Look for overlap among the recursive calls.
Answer
the number of distinct subproblems
Explanation
Memoization helps only when different recursive calls request the same subproblem; merge sort's recursive ranges do not repeat, so it gains no useful reuse.
- 28The DAG shortest-path problem asks for distances from one source to every vertex in_____.
Hint
It is a shortest-path problem with one starting vertex and an acyclic directed graph.
Answer
single-source shortest paths in a directed acyclic graph
Explanation
The DAG shortest-path problem takes a DAG and a source, then computes the shortest-path weight from that source to every vertex.
- 29For DAG shortest paths, a useful family of subproblems computes_____.
Hint
There is one such subproblem for each destination vertex.
Answer
the shortest-path distance from the source to each vertex
Explanation
A natural subproblem is to compute the distance from the fixed source to an individual vertex.
- 30The distance to a vertex is computed by taking_____.
Hint
Consider the final edge of a path and compare all possible previous vertices.
Answer
the minimum over incoming edges of the distance to the predecessor plus the edge weight
Explanation
Any path reaching a vertex must use an incoming edge; considering each possible predecessor and choosing the least total weight gives the recurrence.
- 31If no path reaches a vertex, its shortest-path recurrence can return_____.
Hint
Use a value larger than every finite path weight to represent an unreachable vertex.
Answer
infinity
Explanation
Including infinity among the candidates allows the minimum to represent the case where there is no path from the source to the vertex.
- 32The base-case shortest-path distance from the source to itself is_____.
Hint
A path from a vertex to itself need not use any edges.
Answer
zero
Explanation
The distance from the source to itself is zero, providing the base case for the shortest-path recurrence.
- 33A valid order for computing the DAG shortest-path subproblems is_____.
Hint
This order respects every directed edge in the DAG.
Answer
a topological order of the graph
Explanation
Because the graph is acyclic, its vertices can be processed in topological order so the predecessor distances needed by a vertex are available.
- 34The running time of the DAG shortest-path dynamic program is proportional to_____.
Hint
Count one contribution per vertex and one per edge.
Answer
the number of vertices plus the number of edges
Explanation
The non-recursive work for each vertex scans its incoming edges; summing those scans over all vertices accounts for all edges, giving a total linear in vertices plus edges. This is equivalent in effect to DAG relaxation.
- 35When a ball knocks down two adjacent pins, the score is_____.
Hint
The two-pin score is obtained by multiplying rather than adding.
Answer
the product of the two pin values
Explanation
In the bowling game, knocking down two adjacent pins awards the product of their values.
- 36When a ball knocks down one pin, the score is_____.
Hint
For a single pin, the score is not combined with a neighboring value.
Answer
the value of the pin
Explanation
Knocking down a single pin awards that pin's value.
- 37A two-pin hit in the linear bowling game can knock down only_____.
Hint
The two pins must be next to each other in the sequence.
Answer
adjacent pins
Explanation
Because the pins lie on a line and the ball can hit one pin or two neighboring pins, a two-pin hit must involve adjacent pins.
- 38The objective of the bowling problem is to_____.
Hint
The player is looking for the best possible outcome, not necessarily to hit every pin.
Answer
maximize the total score
Explanation
The objective is to choose which pins to hit, singly or in pairs, to obtain the greatest possible score.
- 39The bowling dynamic program defines each subproblem on_____.
Hint
It consists of all sequence items from a chosen position through the end.
Answer
a suffix of the pin sequence
Explanation
The subproblem beginning at position i considers the pins from i onward, which form a suffix.
- 40The value of the bowling subproblem beginning at position i is_____.
Hint
This is the score goal for the remaining pins in the suffix.
Answer
the maximum score obtainable from the pins starting at position i
Explanation
Defining the goal of each subproblem precisely makes it clear what its recurrence must compute.
- 41The original bowling problem is represented by_____.
Hint
Choose the suffix that starts at the beginning of the input.
Answer
the subproblem for the entire pin sequence
Explanation
The suffix starting at the first position contains every pin, so solving that subproblem solves the original bowling problem.
- 42The recurrence considers whether to_____.
Hint
List the choices that determine what happens to the first item.
Answer
skip the first pin, hit it alone, or pair it with the next pin
Explanation
These are the three possibilities for the first pin in a suffix: leave it untouched, score it alone, or knock it down with its adjacent neighbor.
- 43To combine the bowling choices in the recurrence, take_____.
Hint
Since this is an optimization problem seeking the greatest score, compare the candidates using the appropriate operation.
Answer
the maximum of the scores from the three choices
Explanation
Each choice gives a candidate score, and taking their maximum selects the best strategy for the suffix.
- 44After pairing the first two pins, the remaining bowling subproblem is_____.
Hint
A pair hit removes two pins from the start of the current suffix.
Answer
the suffix starting two positions later
Explanation
If the first two pins are knocked down together, the remaining pins begin after those two, leaving a smaller suffix subproblem.
- 45The bowling base case is that the maximum score for_____is zero.
Hint
This is the suffix with no remaining items.
Answer
the empty suffix
Explanation
There are no pins to score in the empty suffix, so its maximum score is zero and it serves as the base case.
- 46A valid topological order for the bowling suffix subproblems is_____.
Hint
The computation proceeds from the end of the sequence toward its beginning.
Answer
decreasing index order
Explanation
Each suffix recurrence uses subproblems starting at later positions, so computing larger indices first ensures those solutions are ready.
- 47Because the bowling recurrence has a linear number of constant-work suffix subproblems, it runs in_____.
Hint
The number of subproblems grows proportionally to the number of pins.
Answer
linear time
Explanation
There are linearly many suffix subproblems and each requires constant non-recursive work, resulting in a linear-time algorithm.
- 48The non-recursive implementation that fills subproblem values in topological order is called_____.
Hint
This implementation uses a loop to fill solutions rather than recursive calls.
Answer
bottom-up dynamic programming
Explanation
Instead of recursive calls, bottom-up dynamic programming initializes base cases and fills the table in topological order using the recurrence.
- 49Trying all local options for the first pin and reusing subproblem answers is an example of_____.
Hint
The method exhaustively considers the limited choices at one step rather than all complete strategies independently.
Answer
local brute force
Explanation
The recurrence tries each possible local choice and combines the results, while memoization prevents the full exploration from becoming exponentially repetitive.
- 50Three common polynomial-size subproblem families for sequence inputs are_____.
Hint
They are contiguous portions anchored at the beginning, end, or both positions.
Answer
prefixes, suffixes, and substrings
Explanation
For a sequence input, these are three standard families of candidate subproblems that remain polynomial in number.
- 51A family of subproblems to avoid when polynomially many are needed is all possible_____.
Hint
Unlike a substring, this kind of selection may omit elements in the middle.
Answer
subsequences
Explanation
Each sequence element can independently be included or omitted, so there can be exponentially many subsequences.
- 52The number of prefixes or suffixes of a sequence is_____.
Hint
The count grows proportionally to the sequence length rather than its square.
Answer
a linear number
Explanation
A sequence of length n has a number of prefixes proportional to n, and likewise a linear number of suffixes.
- 53The number of substrings of a sequence is_____.
Hint
There are roughly n choices for each of two endpoints.
Answer
a quadratic number
Explanation
A substring is determined by its start and end positions, giving a number of possibilities proportional to the square of the sequence length.
- 54For many sequence problems, the two equally useful linear-size choices are_____.
Hint
Both describe contiguous portions anchored at one end of the sequence.
Answer
prefixes and suffixes
Explanation
These two subproblem families have the same linear size, and either is often a convenient choice for a dynamic program.
- 55When designing a recurrence on suffixes, it is often useful to focus on_____.
Hint
A suffix is naturally processed from its beginning.
Answer
the first item
Explanation
When a subproblem is a suffix, considering what happens to its first item can reduce the remaining task to a smaller suffix.
- 56When designing a recurrence on prefixes, it is often useful to focus on_____.
Hint
A prefix is naturally processed from its ending boundary.
Answer
the last item
Explanation
For prefix-based subproblems, considering the last item can reduce the problem to a smaller prefix.
- 57The key to designing a recurrence is to identify_____.
Hint
Ask what information about the solution would let you finish by solving a reduced instance.
Answer
a feature of the solution that reduces the task to a smaller subproblem
Explanation
A useful recurrence identifies a decision or feature that, once known, leaves a smaller problem that can be solved recursively.
- 58For local choices to support a polynomial-time dynamic program, their number should be_____.
Hint
The number of options must not grow exponentially with input size.
Answer
a polynomial number of choices
Explanation
If the recurrence has only polynomially many choices and stays within a polynomial family of subproblems, dynamic programming can yield a polynomial-time algorithm.
- 59When a dynamic program seeks the smallest possible cost, it typically combines choices using_____.
Hint
This operation selects the least-cost candidate.
Answer
the minimum
Explanation
Optimization recurrences use a minimum when the objective is to minimize a quantity, as in shortest paths.
- 60When a dynamic program seeks the greatest possible value, it typically combines choices using_____.
Hint
This operation selects the greatest-value candidate.
Answer
the maximum
Explanation
Optimization recurrences use a maximum when the objective is to maximize a quantity, as in the bowling score problem.

Ask anything
We've read this whole study set, so questions about it get the best answers.