Dynamic Programming
- 57Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the central goal of the algorithmic-design approach introduced in the lecture?
What is the central goal of the algorithmic-design approach introduced in the lecture?
57 questions
- 1
What is the central goal of the algorithmic-design approach introduced in the lecture?
- A
Converting every input into a graph and applying a shortest-path algorithm
- B
Constructing an algorithm from scratch, often aiming for a polynomial-time solution
- C
Replacing recursive algorithms with longer, problem-specific code
- D
Selecting a data structure that has already been shown to solve the problem directly
Correct answer
AConverting every input into a graph and applying a shortest-path algorithm
Explanation
Algorithmic design focuses on constructing an algorithm from scratch, often seeking a polynomial-time solution, rather than only applying or adapting previously known algorithms.
- A
- 2
What makes an algorithm recursive in the broad sense described in the lecture?
- A
It solves a problem by expressing it in terms of smaller subproblems
- B
It stores every possible answer before examining the input
- C
It avoids reusing code by creating separate instructions for every input size
- D
It requires that every problem be represented as a graph
Correct answer
AIt solves a problem by expressing it in terms of smaller subproblems
Explanation
Recursive design breaks a problem into smaller subproblems and specifies how to solve one problem using solutions to others.
- A
- 3
Which list correctly expands the SRTBOT design framework?
- A
Subproblems, recursion, tables, boundaries, operations, and time
- B
Sorting, recursion, traversal, branching, optimization, and termination
- C
Subproblems, relations, topological order, base cases, original problem, and time
- D
Subarrays, recurrence, testing, binary search, output, and transfer
Correct answer
CSubproblems, relations, topological order, base cases, original problem, and time
Explanation
SRTBOT stands for subproblems, relations, topological order, base cases, original problem, and time analysis.
- A
- 4
Which step is often the hardest part of designing a recursive algorithm?
- A
Ensure that every possible subset of the input is a subproblem
- B
Choose the fastest programming language for implementing the recurrence
- C
Define a useful collection of subproblems, usually polynomial in number
- D
Find a closed-form solution before considering smaller problems
Correct answer
CDefine a useful collection of subproblems, usually polynomial in number
Explanation
Choosing the right subproblems is often the hardest part of recursive algorithm design. A useful design typically has only polynomially many subproblems.
- A
- 5
In SRTBOT, what does the relation specify?
- A
A rule for solving one subproblem using solutions to other subproblems
- B
An estimate of the memory required to store the final answer
- C
A list of all input values that should be ignored
- D
A proof that the original problem has a unique solution
Correct answer
AA rule for solving one subproblem using solutions to other subproblems
Explanation
The relation specifies how to compute one subproblem using solutions to other subproblems; those dependencies define the recursive structure.
- A
- 6
What purpose does a topological order serve in a recursive algorithm’s subproblem graph?
- A
An order in which every subproblem is computed after its dependencies
- B
An order that guarantees the largest subproblem is solved first
- C
An order based only on the amount of time each subproblem takes
- D
An order that groups subproblems by their input values
Correct answer
AAn order in which every subproblem is computed after its dependencies
Explanation
A topological order arranges subproblems so that each dependency is solved before the problem that relies on it.
- A
- 7
Why should the dependency graph of recursive subproblems be acyclic?
- A
It ensures that each subproblem has exactly two dependencies
- B
It prevents recursive calls from continuing indefinitely through cyclic dependencies
- C
It guarantees that every subproblem has the same running time
- D
It ensures that the recurrence uses only addition and subtraction
Correct answer
BIt prevents recursive calls from continuing indefinitely through cyclic dependencies
Explanation
If recursive dependencies contain a cycle, the algorithm can keep calling subproblems in that cycle without terminating. A directed acyclic graph avoids this issue.
- A
- 8
How can specifying a topological order help establish that a recursive algorithm is well-founded?
- A
It replaces the need to establish a recurrence relation
- B
It ensures that the original problem is always the first subproblem solved
- C
It allows the algorithm to skip defining base cases
- D
It gives an order in which dependencies are ready before they are used
Correct answer
DIt gives an order in which dependencies are ready before they are used
Explanation
A valid topological order provides a way to compute dependencies before the subproblems that need them. It may be specified explicitly, such as through a loop.
- A
- 9
How are merge sort’s subproblems and original problem defined in the lecture’s notation?
- A
A subproblem merges the full array; the original problem sorts each item separately
- B
A subproblem selects one item from the array; the original problem selects the median
- C
A subproblem sorts a prefix; the original problem sorts only the final item
- D
A subproblem sorts the range from i to j−1; the original problem is to sort the range from 0 to n−1
Correct answer
DA subproblem sorts the range from i to j−1; the original problem is to sort the range from 0 to n−1
Explanation
For merge sort, a subproblem sorts the range from index i up to but not including j. The original task is the range from 0 to n.
- A
- 10
How does the merge-sort recurrence solve the subproblem for range [i,j)?
- A
It sorts the whole range first and then recursively sorts individual elements
- B
It sorts both smaller ranges and merges their sorted outputs
- C
It merges the unsorted halves and then sorts the merged result
- D
It sorts one half and discards the other half before returning the result
Correct answer
BIt sorts both smaller ranges and merges their sorted outputs
Explanation
Merge sort divides a range at a midpoint, recursively sorts both halves, and merges the two sorted results to obtain the sorted range.
- A
- 11
Which topological order is suitable for merge sort’s range subproblems?
- A
Increasing starting index, because both halves begin at larger indices
- B
Decreasing range length, because the largest ranges are base cases
- C
Increasing ending index only, regardless of range length
- D
Increasing range length, so the smaller halves are solved first
Correct answer
DIncreasing range length, so the smaller halves are solved first
Explanation
For merge sort, subproblems can be ordered by increasing range length j−i. A non-base range’s two halves are strictly shorter, so they come earlier in that order.
- A
- 12
What is a valid merge-sort base case described in the lecture?
- A
Any range whose midpoint is its first element
- B
The empty range, which is already sorted
- C
A range with two elements, which must be merged recursively
- D
The full input range, which is assumed to be sorted
Correct answer
BThe empty range, which is already sorted
Explanation
The empty range is a base case for sorting: there are no elements that need to be ordered.
- A
- 13
What is memoization?
- A
Reordering recursive calls so that the largest one runs first
- B
Recording every path explored by the algorithm, whether needed or not
- C
Storing subproblem solutions so repeated calls can reuse them
- D
Replacing each recurrence with a closed-form equation
Correct answer
CStoring subproblem solutions so repeated calls can reuse them
Explanation
Memoization records computed subproblem answers and reuses them when the same subproblem is encountered again.
- A
- 14
What information does a memo table store?
- A
A data structure mapping solved subproblems to their solutions
- B
A stack containing every recursive call, including completed repeats
- C
A graph mapping each base case to all possible inputs
- D
A queue mapping input elements to the order they were read
Correct answer
AA data structure mapping solved subproblems to their solutions
Explanation
A memo can be implemented with a dictionary that maps subproblem specifications to their computed solutions. Arrays or hash tables can serve this role when appropriate.
- A
- 15
Why does the straightforward recursive Fibonacci algorithm take exponential time?
- A
It performs a linear number of recursive calls, each taking exponential time
- B
It uses too many distinct subproblems, even though each is solved once
- C
It spends exponential time sorting the Fibonacci values
- D
It recomputes the same Fibonacci subproblems many times
Correct answer
DIt recomputes the same Fibonacci subproblems many times
Explanation
Naive recursive Fibonacci repeatedly computes the same values, creating an exponentially large recursion tree even though there are only linearly many distinct indices.
- A
- 16
Which recurrence and base cases define the Fibonacci numbers in the lecture?
- A
fi=fi−1fi−2, with f1=f2=0
- B
fi=fi−1+fi−2, with f1=f2=1
- C
fi=2fi−1, with f1=1
- D
fi=fi−1−fi−2, with f1=f2=1
Correct answer
Bfi=fi−1+fi−2, with f1=f2=1
Explanation
The Fibonacci recurrence is fi=fi−1+fi−2, with the stated base cases f1=f2=1.
- A
- 17
Why does memoization reduce the number of Fibonacci computations to a linear number of subproblems?
- A
Each of the n distinct indexed subproblems is computed at most once
- B
Each Fibonacci number is calculated separately for every path in the call tree
- C
The algorithm stores only the final answer and recomputes all earlier values
- D
The recursive calls are eliminated by solving the recurrence algebraically
Correct answer
AEach of the n distinct indexed subproblems is computed at most once
Explanation
There are only n Fibonacci subproblems with indices from 1 to n. With memoization, each is computed at most once, and each computation uses constant-time arithmetic in the usual unit-cost model.
- A
- 18
What does a memoized function do when its requested subproblem is already in the memo?
- A
It discards stored values whenever a new call begins
- B
It recursively computes every dependency before checking storage
- C
It checks the memo only after recomputing the subproblem
- D
It checks the memo first and returns the stored answer if present
Correct answer
DIt checks the memo first and returns the stored answer if present
Explanation
A memoized recursive function first checks whether its subproblem is already stored. If so, it returns the saved answer without making recursive calls again.
- A
- 19
In the memoized Fibonacci recursion, why can many calls on the right side of the recursion tree finish immediately?
- A
The second request for fi−2 can return its already-computed value
- B
The recurrence no longer needs the value of fi−2
- C
The call for fi−2 is replaced by a call for fi+2
- D
The base case automatically determines every larger Fibonacci number
Correct answer
AThe second request for fi−2 can return its already-computed value
Explanation
When computing fi, the recursive call for fi−1 will compute fi−2 as part of its work. The later request for fi−2 can therefore use the saved result.
- A
- 20
Which statement best describes possible implementations of a memo table?
- A
The memo is an interface that can be implemented with an array or a hash table
- B
The memo must use a sorted tree because subproblems are computed in order
- C
A memo must always be a linked list of recursive calls
- D
A memo is a special-purpose graph that stores only base cases
Correct answer
AThe memo is an interface that can be implemented with an array or a hash table
Explanation
A dictionary can provide the memo interface, while a direct-access array is often suitable when subproblem identifiers are integer indices. A hash table is another option.
- A
- 21
How should the running time of a memoized dynamic program generally be analyzed?
- A
Sum the nonrecursive work over all distinct subproblems
- B
Count only the base cases and ignore all other subproblems
- C
Multiply the number of recursive calls by the depth of the recursion tree
- D
Count the number of lines in the recursive function
Correct answer
ASum the nonrecursive work over all distinct subproblems
Explanation
Once a subproblem is solved, memoization prevents solving it again. The running time can therefore be bounded by summing the nonrecursive work for each distinct subproblem.
- A
- 22
Why does memoization not improve merge sort in the way it improves naive recursive Fibonacci?
- A
Merge sort’s memo must store every possible permutation
- B
Merge sort has no repeated subproblems to reuse, so memoization offers no benefit
- C
Merge sort cannot be written recursively, so it cannot use a memo
- D
Merge sort’s base cases are exponential in number
Correct answer
BMerge sort has no repeated subproblems to reuse, so memoization offers no benefit
Explanation
Memoization does not create repeated subproblems where none existed. Merge sort’s recursive ranges are disjoint, so storing their answers does not provide the same benefit it provides for Fibonacci.
- A
- 23
What is the subproblem used for the DAG shortest-path dynamic program?
- A
The shortest path from each vertex to a different source
- B
The longest path between every pair of vertices in the graph
- C
The shortest path from every vertex to itself, for one selected vertex
- D
The shortest-path distance from the source s to a vertex v
Correct answer
DThe shortest-path distance from the source s to a vertex v
Explanation
The DAG shortest-path subproblem is the shortest-path distance from a fixed source s to a particular vertex v. Solving it for all vertices gives the single-source result.
- A
- 24
How does the recurrence compute the shortest-path distance from s to v?
- A
Take the minimum over incoming edges uv of the distance to u plus the weight of uv
- B
Add the weights of all incoming edges to the distance from s to v
- C
Choose the incoming edge with the smallest weight, regardless of the distance to its tail
- D
Take the maximum over outgoing edges vu of the distance to u minus the weight of vu
Correct answer
ATake the minimum over incoming edges uv of the distance to u plus the weight of uv
Explanation
Any path ending at v either begins at s when v=s, or reaches v through an incoming edge uv. Thus the best distance is the minimum distance to a predecessor plus the weight of its final edge.
- A
- 25
Which edges does the DAG shortest-path recurrence examine for a given vertex v?
- A
Incoming edges to v, because a path reaching v must enter from a predecessor
- B
Outgoing edges from v, because the path must continue after reaching v
- C
All edges in the graph, because every edge may be part of the final step
- D
Only edges incident to the source, because all paths start there
Correct answer
AIncoming edges to v, because a path reaching v must enter from a predecessor
Explanation
The recurrence examines incoming edges to v. For each predecessor u, it considers the best path to u followed by edge uv.
- A
- 26
How does the recurrence account for a vertex that is unreachable from the source?
- A
Repeat the recurrence until an unreachable vertex becomes reachable
- B
Include infinity among the candidates when no path reaches the vertex
- C
Assign a distance of zero to every unreachable vertex
- D
Use the largest edge weight as the distance to every unreachable vertex
Correct answer
BInclude infinity among the candidates when no path reaches the vertex
Explanation
If no path from s to v exists, the minimum should represent that no finite candidate distance is available; the recurrence includes infinity for this possibility.
- A
- 27
Why can DAG shortest-path subproblems be computed in a valid topological order?
- A
A topological order of the DAG makes the dependency computation acyclic
- B
The subproblems are ordered by increasing distance, which is known in advance
- C
A topological order is unnecessary because all distances are base cases
- D
The algorithm sorts vertices by their incoming-edge weights
Correct answer
AA topological order of the DAG makes the dependency computation acyclic
Explanation
A DAG has a topological order, and the graph’s acyclicity provides the order needed to compute predecessor subproblems before dependent ones.
- A
- 28
What is the base case for the DAG shortest-path recurrence?
- A
The distance from every vertex to s is 0
- B
The distance from s to itself is infinity
- C
The distance from s to every vertex is the weight of its first edge
- D
The distance from s to s is 0
Correct answer
DThe distance from s to s is 0
Explanation
The base case is the source’s distance to itself, which is 0.
- A
- 29
Why can the DAG shortest-path dynamic program run in O(V+E) time?
- A
The algorithm takes O(V2) time because every pair of vertices is compared
- B
The total work is O(V+E) because incoming-edge scans sum to the number of edges
- C
The algorithm takes O(VE) time because every edge is scanned for every vertex
- D
The algorithm takes O(E2) time because every edge is compared to every other edge
Correct answer
BThe total work is O(V+E) because incoming-edge scans sum to the number of edges
Explanation
For each vertex, the recurrence scans its incoming edges. Summed across all vertices, this examines each edge once, along with per-vertex work, yielding O(V+E) time.
- A
- 30
How is the recurrence-based DAG shortest-path algorithm related to DAG relaxation?
- A
It avoids examining edge weights by using only the number of vertices
- B
It computes the same minima as DAG relaxation, with the computation organized differently
- C
It performs memoized recursive calls but never processes a vertex twice
- D
It uses a different recurrence that maximizes over outgoing edges
Correct answer
BIt computes the same minima as DAG relaxation, with the computation organized differently
Explanation
DAG relaxation processes vertices in topological order and relaxes their edges. This is equivalent to computing the minimum over candidate predecessor paths, whether done all at once or through successive updates.
- A
- 31
What graph-search behavior is implicit in a generic memoized recursive dynamic program?
- A
It is a breadth-first search that ignores the dependency graph
- B
It performs a depth-first traversal of the subproblem dependencies, using the memo to avoid repeats
- C
It is a random traversal that depends on the order edges are stored
- D
It is a sorting algorithm that replaces shortest-path relaxation
Correct answer
BIt performs a depth-first traversal of the subproblem dependencies, using the memo to avoid repeats
Explanation
The memoized recursive version follows dependencies in a depth-first manner, and the memo records which subproblems have already been visited. The dependency order gives the needed computation order.
- A
- 32
Which are natural polynomial-size subproblem families for sequence inputs?
- A
Only single elements and arbitrary sets of elements
- B
All possible reorderings and all partitions of the sequence
- C
Subsequences, permutations, and all subsets
- D
Prefixes, suffixes, and substrings
Correct answer
DPrefixes, suffixes, and substrings
Explanation
For a sequence of length n, there are only linearly many prefixes and suffixes, and quadratically many substrings. These provide polynomial-size subproblem families.
- A
- 33
What distinguishes a substring from a subsequence?
- A
A substring and a subsequence both require consecutive items
- B
A subsequence is always shorter than two items, while a substring is not
- C
A substring uses consecutive items, while a subsequence may omit items in the middle
- D
A substring may omit middle items, while a subsequence must be consecutive
Correct answer
CA substring uses consecutive items, while a subsequence may omit items in the middle
Explanation
A substring consists of consecutive items between two endpoints. A subsequence may omit items in the middle, so there can be exponentially many subsequences.
- A
- 34
Why are arbitrary subsequences usually a poor choice of subproblems for a polynomial-time dynamic program?
- A
There are 2n subsequences because each item can be included or omitted
- B
There are n! subsequences because their items can be reordered
- C
There are n subsequences because each starts at a different index
- D
There are n2 subsequences because each has two endpoints
Correct answer
AThere are 2n subsequences because each item can be included or omitted
Explanation
Each of the n positions can independently be included or excluded in a subsequence, giving 2n possible subsequences. This is generally too many subproblems for an efficient dynamic program.
- A
- 35
How do the numbers of prefix, suffix, and substring subproblems compare for a length-n sequence?
- A
Prefixes and suffixes are linear in number, while substrings are quadratic
- B
Suffixes are always better because they require no recurrence
- C
Substrings are always better because they encode more information
- D
Prefixes are exponential, while suffixes are quadratic
Correct answer
APrefixes and suffixes are linear in number, while substrings are quadratic
Explanation
Prefixes and suffixes each give a linear number of subproblems, while substrings give a quadratic number. Prefixes or suffixes are often preferable when either works.
- A
- 36
What does the bowling subproblem b(i) represent?
- A
The score from hitting pin i alone, regardless of later pins
- B
The number of ways to pair pins in the suffix beginning at i
- C
The minimum score obtainable using pins 0 through i
- D
The maximum score obtainable using pins i through n−1
Correct answer
DThe maximum score obtainable using pins i through n−1
Explanation
For the bowling problem, b(i) is the maximum score obtainable from the suffix beginning at pin i and continuing through the last pin.
- A
- 37
Which bowling subproblem gives the answer for the entire input?
- A
b(n), because it contains every pin
- B
b(1), because the first pin is excluded
- C
The maximum of all individual values vi
- D
b(0), because it represents the full sequence of pins
Correct answer
Db(0), because it represents the full sequence of pins
Explanation
The suffix beginning at index 0 contains all pins, so its optimal score is the answer to the original bowling problem.
- A
- 38
What are the three choices considered for the first pin in the bowling recurrence?
- A
Hit pin i twice, skip pin i+1, or pair all remaining pins
- B
Skip pin i, pair it with any later pin, or hit every remaining pin together
- C
Hit pin i alone, pair it with pin i−1, or pair it with pin i+2
- D
Skip pin i, hit it alone, or pair it with pin i+1
Correct answer
DSkip pin i, hit it alone, or pair it with pin i+1
Explanation
The first pin can be skipped, hit alone for vi points, or paired with the next pin for vivi+1 points. Each choice leaves a smaller suffix to solve.
- A
- 39
What expression corresponds to skipping pin i in the bowling recurrence?
- A
b(i+2)+vi
- B
b(i+1)+vivi+1
- C
b(i+1)
- D
b(i−1)
Correct answer
Cb(i+1)
Explanation
Skipping pin i leaves the suffix starting at i+1, so the score for that choice is b(i+1).
- A
- 40
What expression corresponds to hitting pin i alone?
- A
b(i+1)+vivi+1
- B
b(i+2)+vi
- C
b(i)+vivi+1
- D
b(i+1)+vi
Correct answer
Db(i+1)+vi
Explanation
If pin i is hit alone, it contributes vi points and leaves the suffix beginning at i+1, giving b(i+1)+vi.
- A
- 41
What expression corresponds to pairing pins i and i+1?
- A
b(i)+vivi+1
- B
b(i+1)+vi+vi+1
- C
b(i+2)+vivi+1
- D
b(i+2)+vi
Correct answer
Cb(i+2)+vivi+1
Explanation
Pairing pins i and i+1 gives their product as points, after which the remaining suffix starts at i+2.
- A
- 42
How should the bowling recurrence combine its available choices?
- A
Add all three choices because each action can be performed together
- B
Take the minimum of the three choices, including a pair beyond the sequence
- C
Take the maximum of the valid choices and omit pairing when fewer than two pins remain
- D
Choose the pair option whenever either pin has a positive value
Correct answer
CTake the maximum of the valid choices and omit pairing when fewer than two pins remain
Explanation
The recurrence takes the maximum of the scores from skipping, hitting alone, or pairing the first two pins. The pairing option is available only when a next pin exists.
- A
- 43
What is the bowling dynamic program’s base case?
- A
b(n)=-, because no pins remain to score points
- B
b(n)=0, because the empty suffix yields no points
- C
b(n)=1, because the empty suffix has one possible action
- D
b(n)=vn, because the final pin is always hit
Correct answer
Bb(n)=0, because the empty suffix yields no points
Explanation
The base case is the empty suffix at index n. With no pins remaining, no points can be scored, so b(n)=0.
- A
- 44
Why does the bowling dynamic program run in linear time?
- A
There are O(2n) possible bowling strategies and each takes constant time
- B
There are O(n2) substring subproblems and O(n) work per subproblem
- C
There are O(n) subproblems and each requires scanning all remaining pins
- D
There are O(n) suffix subproblems and O(1) nonrecursive work per subproblem
Correct answer
DThere are O(n) suffix subproblems and O(1) nonrecursive work per subproblem
Explanation
Computing each bowling subproblem requires only a constant number of arithmetic operations and comparisons, and there are linearly many suffixes, so the total time is linear.
- A
- 45
What topological order is used to compute the bowling suffix subproblems?
- A
Increasing i, because the full sequence is the empty suffix
- B
Increasing suffix length, starting with the full sequence
- C
Decreasing i, so each suffix depends on already-computed shorter suffixes
- D
In arbitrary order, because every suffix is independent
Correct answer
CDecreasing i, so each suffix depends on already-computed shorter suffixes
Explanation
For suffix subproblems, the suffix beginning at n is solved first, followed by decreasing starting indices, ending with the full suffix at 0.
- A
- 46
How does bottom-up dynamic programming compute the bowling solution?
- A
It stores only b(0) and computes all other values whenever needed
- B
It initializes b(n), fills values from n−1 down to 0, and returns b(0)
- C
It starts with b(0) and repeatedly replaces it with smaller scores
- D
It recursively calls itself, then saves the answers after returning
Correct answer
BIt initializes b(n), fills values from n−1 down to 0, and returns b(0)
Explanation
The bottom-up version initializes the base case, fills the table in topological order, applies the recurrence at each index, and returns b(0).
- A
- 47
Which local viewpoint often helps derive recurrences for suffix and prefix subproblems?
- A
For suffixes, focus on the first item or items; for prefixes, focus on the last
- B
For suffixes, focus on the last item; for prefixes, focus on the first
- C
For both prefixes and suffixes, focus only on the middle item
- D
For suffixes, focus on every item at once; for prefixes, focus on no items
Correct answer
AFor suffixes, focus on the first item or items; for prefixes, focus on the last
Explanation
For a suffix, considering the first item or first few items creates choices that leave a smaller suffix. For a prefix, the analogous focus is usually its last item.
- A
- 48
What can happen when an item is removed from the middle of a substring subproblem?
- A
Removing an endpoint always creates an arbitrary subsequence
- B
Removing an interior item necessarily creates an exponential number of subproblems
- C
Removing any item makes the remaining substring nonconsecutive
- D
Removing an interior item can split it into two substrings
Correct answer
DRemoving an interior item can split it into two substrings
Explanation
Removing an item from the middle of a substring can leave two substrings, which may become smaller subproblems.
- A
- 49
What is the key reasoning step in deriving many dynamic-programming recurrences?
- A
Enumerate every complete solution and select the first one found
- B
Avoid defining subproblems until after the algorithm has been implemented
- C
Identify a useful feature or choice that reduces the problem to smaller subproblems
- D
Choose the largest subproblem and assume its answer determines all others
Correct answer
CIdentify a useful feature or choice that reduces the problem to smaller subproblems
Explanation
The design idea is to identify a feature or choice that, once fixed, reduces the task to a smaller subproblem. The recurrence considers the possible choices and combines their results.
- A
- 50
How are alternatives commonly combined in maximization and minimization dynamic programs?
- A
Use an average whenever the alternatives have different values
- B
Use a maximum for maximization problems and a minimum for minimization problems
- C
Use a minimum for both maximization and minimization problems
- D
Use a sum when maximizing and a product when minimizing
Correct answer
BUse a maximum for maximization problems and a minimum for minimization problems
Explanation
For optimization problems, if the alternatives represent competing valid choices, maximize when seeking the greatest value and minimize when seeking the least value.
- A
- 51
What does the lecture mean by using “local brute force” in dynamic programming?
- A
It avoids examining alternatives by predicting the optimal choice in advance
- B
It tries local alternatives while reusing shared subproblem solutions rather than recomputing them
- C
It uses memoization to make every possible subproblem constant-time, including setup
- D
It explores every complete strategy but removes recursion from the code
Correct answer
BIt tries local alternatives while reusing shared subproblem solutions rather than recomputing them
Explanation
Dynamic programming can explore several local choices at each step without enumerating every complete combination, because repeated smaller subproblems are solved once and reused.
- A
- 52
Under what conditions does the standard memoized subproblem analysis give a polynomial-time algorithm?
- A
Polynomially many subproblems with polynomial work per subproblem yield a polynomial-time bound
- B
Polynomially many recursive calls guarantee polynomial time even without reuse
- C
Any recurrence with a base case runs in polynomial time
- D
A polynomial-time algorithm must have exactly one subproblem per input item
Correct answer
APolynomially many subproblems with polynomial work per subproblem yield a polynomial-time bound
Explanation
If the number of subproblems is polynomial and the nonrecursive work for each one is polynomial, their total is polynomial, assuming memoization avoids repeated computation.
- A
- 53
Why does the lecture qualify the usual constant-time assumption for Fibonacci additions?
- A
Fibonacci values fit in one bit, so additions are constant-time for all n
- B
Fibonacci values grow exponentially and require Theta(n) bits, so large-number additions can cost more than constant time
- C
The number of Fibonacci subproblems is exponential, so bit length is irrelevant
- D
The word RAM model forbids addition on values larger than the input length
Correct answer
BFibonacci values grow exponentially and require Theta(n) bits, so large-number additions can cost more than constant time
Explanation
For a fixed-width word RAM, arithmetic on word-sized values is often treated as constant-time. Fibonacci values have Theta(n) bits, so their addition may require more than constant time when the values exceed the word size.
- A
- 54
What effect can accounting for the bit lengths of Fibonacci numbers have on the memoized running-time bound?
- A
The memoized algorithm remains exponential because the Fibonacci values grow
- B
The memoized algorithm is polynomial, with bit costs potentially adding a term on the order of n2/w
- C
The memoized algorithm takes O(n\,\log n) because it sorts the values
- D
The memoized algorithm is constant-time because the memo stores all answers
Correct answer
BThe memoized algorithm is polynomial, with bit costs potentially adding a term on the order of n2/w
Explanation
With n distinct Fibonacci subproblems and additions on values of Theta(n) bits, the bit-operation discussion gives a polynomial bound of n+Theta(n^2/w), rather than the exponential time of naive recursion.
- A
- 55
Why can applying the general memoized subproblem bound to merge sort produce a loose O(n3) estimate?
- A
The total is Theta(n\log n) because every range is merged once
- B
Memoization proves merge sort takes O(n) time
- C
A coarse sum gives an O(n3) bound, although the actual merge-sort time is Theta(n\log n)
- D
The range count is exponential, so the bound is exponential
Correct answer
CA coarse sum gives an O(n3) bound, although the actual merge-sort time is Theta(n\log n)
Explanation
The number of possible merge-sort ranges is O(n2), and merging a range can take time proportional to its length. Summing over all ranges gives an upper bound of O(n3), which is valid but weaker than merge sort’s actual Theta(n\log n) time.
- A
- 56
What does “nonrecursive work” mean when analyzing a memoized recurrence?
- A
It measures the time needed to write the recurrence on paper
- B
It excludes recursive-call work, which is counted through the other subproblems
- C
It includes the total running time of every recursive descendant
- D
It counts only the time spent in base cases
Correct answer
BIt excludes recursive-call work, which is counted through the other subproblems
Explanation
The recurrence’s nonrecursive work is the work performed for the current subproblem excluding the recursive computations. Those recursive subproblems are accounted for separately in the sum.
- A
- 57
How does bottom-up dynamic programming differ from the memoized recursive approach?
- A
Memoization stores only base cases, while bottom-up methods store all answers
- B
Memoization uses recursive calls and a memo, while bottom-up methods fill values in an explicit order
- C
Memoization requires iteration, while bottom-up methods require recursion
- D
Memoization and bottom-up dynamic programming cannot implement the same recurrence
Correct answer
BMemoization uses recursive calls and a memo, while bottom-up methods fill values in an explicit order
Explanation
Memoized recursion stores answers and returns them on later requests. Bottom-up dynamic programming instead fills a table explicitly in topological order, often using a loop and avoiding recursive-call overhead.
- A

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