1. Home
  2. Explore
  3. Computer Science
  4. Dynamic Programming

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Dynamic Programming

  • 60Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Recursive Design
The new section on algorithmic design focuses on how to develop
to solve a problem.

60 questions

  1. 1
    The 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.

  2. 2
    The 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.

  3. 3
    The 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.

  4. 4
    When 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.

  5. 5
    The 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.

  6. 6
    The 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.

  7. 7
    In 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.

  8. 8
    To 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.

  9. 9
    An 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.

  10. 10
    A 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.

  11. 11
    In 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.

  12. 12
    The 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.

  13. 13
    In 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.

  14. 14
    For 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.

  15. 15
    A 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.

  16. 16
    The 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.

  17. 17
    The 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.

  18. 18
    The 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.

  19. 19
    A 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.

  20. 20
    When 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.

  21. 21
    With 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.

  22. 22
    A 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.

  23. 23
    Under 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.

  24. 24
    Because 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.

  25. 25
    If 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.

  26. 26
    Even 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.

  27. 27
    Whether 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.

  28. 28
    The 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.

  29. 29
    For 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.

  30. 30
    The 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.

  31. 31
    If 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.

  32. 32
    The 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.

  33. 33
    A 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.

  34. 34
    The 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.

  35. 35
    When 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.

  36. 36
    When 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.

  37. 37
    A 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.

  38. 38
    The 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.

  39. 39
    The 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.

  40. 40
    The 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.

  41. 41
    The 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.

  42. 42
    The 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.

  43. 43
    To 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.

  44. 44
    After 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.

  45. 45
    The 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.

  46. 46
    A 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.

  47. 47
    Because 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.

  48. 48
    The 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.

  49. 49
    Trying 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.

  50. 50
    Three 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.

  51. 51
    A 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.

  52. 52
    The 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.

  53. 53
    The 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.

  54. 54
    For 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.

  55. 55
    When 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.

  56. 56
    When 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.

  57. 57
    The 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.

  58. 58
    For 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.

  59. 59
    When 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.

  60. 60
    When 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.

1 of 60
Question 1 of 60

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent