Unit 4: Basic Dynamic Programming - Practice Quiz

CSE330 — Competitive Coding Approaches-Techniques 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the main purpose of dynamic programming?

Introduction to Dynamic Programming Easy
A. To sort data without comparisons
B. To solve problems by storing results of subproblems
C. To search only through graphs
D. To solve problems using random choices

2 Which two properties are commonly associated with dynamic programming problems?

Introduction to Dynamic Programming Easy
A. Optimal substructure and overlapping subproblems
B. Binary search and partitioning
C. Hashing and recursion limits
D. Greedy choice and sorting

3 In the Fibonacci sequence, what is the value of when and ?

Fibonacci Sequence Easy
A.
B.
C.
D.

4 What recurrence relation represents the Fibonacci sequence?

Fibonacci Sequence Easy
A.
B.
C.
D.

5 How many ways can a board usually be tiled using dominoes?

Tiling problem Easy
A.
B.
C.
D.

6 For a tiling problem, what can be placed at the left end of the board?

Tiling problem Easy
A. Only two vertical dominoes
B. Any number of diagonal tiles
C. One vertical domino or two horizontal dominoes
D. Only one square

7 If a person can climb either 1 or 2 stairs at a time, how many ways are there to climb 3 stairs?

Climbing Stairs Easy
A. 4
B. 2
C. 3
D. 5

8 What recurrence is commonly used for the climbing stairs problem when 1-step and 2-step moves are allowed?

Climbing Stairs Easy
A.
B.
C.
D.

9 What is memoization in dynamic programming?

Tabulation vs Memoizatation Easy
A. A sorting method for tables
B. A top-down method that stores computed results
C. A method that removes all recursion
D. A bottom-up table method

10 What is tabulation in dynamic programming?

Tabulation vs Memoizatation Easy
A. A bottom-up method using a table
B. A graph traversal method
C. A method based only on random values
D. A top-down recursive method

11 Which approach generally avoids recursive function calls?

Tabulation vs Memoizatation Easy
A. Memoization
B. Tabulation
C. Backtracking
D. Depth-first search

12 In dynamic programming, what does a state usually represent?

State Definition and State Transition Easy
A. A subproblem and its relevant information
B. A random input value
C. A complete program
D. A compiler instruction

13 What is a state transition in dynamic programming?

State Definition and State Transition Easy
A. A process for renaming variables
B. A command for printing output
C. A rule connecting related states
D. A method for deleting states

14 For climbing stairs, if stores the number of ways to reach stair , which transition is correct?

State Definition and State Transition Easy
A.
B.
C.
D.

15 What does the optimal substructure property mean?

Optimal Substructure Property Easy
A. Only the largest input matters
B. Every solution must use recursion
C. A problem has no smaller parts
D. An optimal solution contains optimal subproblem solutions

16 Which 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

17 What 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

18 Why 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

19 Which 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

20 What 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

21 Which 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

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

23 Using , , and , what is the minimum auxiliary space needed to compute only iteratively?

Fibonacci Sequence Medium
A.
B.
C.
D.

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

25 A board is tiled using dominoes placed vertically or horizontally. Which recurrence correctly counts the tilings?

Tiling problem Medium
A.
B.
C.
D.

26 For the domino tiling problem with and , how many tilings exist for a board?

Tiling problem Medium
A.
B.
C.
D.

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

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

29 A 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

30 Which 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

31 For 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

32 Let 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

33 Why 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

34 An 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

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

36 A 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

37 After 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

38 A 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

39 To 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

40 A 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

41 A 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

42 Suppose and . A fast-doubling algorithm recursively computes . Which identities correctly produce ?

Fibonacci Sequence Hard
A. and
B. and
C. and
D. and

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

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

45 A 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

46 Count 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

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

48 A 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

49 The naive recursion for uses . For all , how many distinct valid states can be reached from ?

Overlapping Subproblems Property Hard
A.
B.
C.
D.

50 A 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

51 For 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

52 An 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

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

54 A 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

55 A 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

56 For 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

57 Let 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

58 Consider 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

59 A 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

60 You 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