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 solve problems by storing results of subproblems
B. To solve problems using random choices
C. To search only through graphs
D. To sort data without comparisons

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. One vertical domino or two horizontal dominoes
C. Any number of diagonal tiles
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. 5
B. 3
C. 4
D. 2

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 top-down method that stores computed results
B. A bottom-up table method
C. A sorting method for tables
D. A method that removes all recursion

10 What is tabulation in dynamic programming?

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

11 Which approach generally avoids recursive function calls?

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

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

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

13 What is a state transition in dynamic programming?

State Definition and State Transition Easy
A. A command for printing output
B. A rule connecting related states
C. A process for renaming variables
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. Every solution must use recursion
B. A problem has no smaller parts
C. Only the largest input matters
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 problem with unrelated calculations
B. A shortest path problem
C. A problem with no valid solutions
D. A problem requiring random output

17 What are overlapping subproblems?

Overlapping Subproblems Property Easy
A. Subproblems that appear repeatedly
B. Subproblems that cannot be solved
C. Subproblems solved only once
D. Subproblems with different input types

18 Why does dynamic programming store results of subproblems?

Overlapping Subproblems Property Easy
A. To repeat calculations
B. To avoid solving the same subproblem again
C. To increase the input size
D. To remove all base cases

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. Define the states
D. Choose random base cases

20 What is a base case in dynamic programming?

Dynamic Programming Process and Techniques Easy
A. A state that is always ignored
B. A directly known small subproblem
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. Every input element must be processed exactly once
C. Each recursive call produces entirely new subproblems
D. The solution requires sorting before any computation

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. Replace every loop with a recursive call
B. Sort the arguments before each call
C. Store each computed result and reuse it
D. Process the largest argument before the others

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. Bottom-up tabulation
B. Level-order traversal
C. Top-down memoization
D. Full-state enumeration

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. Stack overflow
B. Invalid input
C. Integer overflow
D. Duplicate output

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. : minimum index of an item with value
B. : best value using exactly item
C. : number of items having weight
D. : best value using the first items with capacity

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 edge on a shortest path has the smallest graph weight
B. Every prefix of a shortest path is itself a shortest path
C. Every shortest path visits all vertices in the graph
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. Memoization will always be slower than direct recursion
B. The base cases cannot contain constant values
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. is larger than both of its preceding values
B. is reached through multiple recursive branches
C. and are specified as base cases
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 input cannot be represented as an array
B. The subproblems do not significantly overlap
C. The recursive tree must have constant depth
D. The subproblems have no valid base cases

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. A sorted input and a binary search rule
B. A recursive tree and a greedy selection rule
C. Base cases and a valid evaluation order
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. Store only two rows and alternate between them
B. Store only the first row for every iteration
C. Discard each row before computing its successor
D. Replace the table with an unordered set

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. Set
B. Copy
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. The graph is a DAG and states are processed in topological order
B. All edge weights are positive and vertices are processed by index
C. The graph is connected and states are processed depth-first
D. Every vertex has equal indegree and states are processed breadth-first

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 always runs in time, while tabulation can run in time
B. Both methods necessarily run in time because the state space is rectangular
C. Memoization can run in time, while rectangular tabulation runs in time
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. The longest suffix that is also a prefix of either forbidden pattern
B. The complete prefix generated up to the current position
C. Only the number of occurrences of character
D. Only the most recently appended character

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 longest path objective cannot be decomposed across any pair of vertices
B. The best continuation from depends on which vertices were already visited
C. The transition fails only when the graph contains negative edge weights
D. Cycles make every longest simple path have infinitely many edges

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. Every state has constant indegree
C. The dependency graph is acyclic
D. Every transition has a nonnegative cost

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. In increasing order after sorting by weight
D. From capacity down to

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 recurrence has order two, so one residue does not determine the next residue
C. A single residue determines the next residue only when is prime
D. The pair is required only to avoid overflow during modular addition

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 stores the parity of the current step
B. , where stores the number of remaining steps
C. , where records whether the last jump had size
D. , where the state stores only the number of ways to reach

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. Tabulation avoids deep recursion and can use auxiliary space
B. Memoization avoids deep recursion and can use auxiliary space
C. Tabulation reduces the asymptotic running time from exponential to logarithmic
D. Memoization reduces the number of evaluated states below the reachable count

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 changes string lengths, so the state must include the current operation count
B. A transposition destroys optimal substructure, so no polynomial DP can represent it
C. A transposition may require a transition from after checking two character pairs
D. A transposition may require a transition from without checking characters

57 Let be the length of the longest increasing subsequence ending exactly at index . Which statement justifies the transition ?

Optimal Substructure Property Hard
A. Removing leaves a globally longest subsequence of the entire prefix ending at
B. Every globally longest subsequence of the prefix must include the element at index
C. Removing from such an optimal subsequence leaves an optimal subsequence ending at some valid
D. Every increasing subsequence ending at must contain the largest earlier array value

58 Consider the recursion with base case . Which observation most directly supports memoization?

Overlapping Subproblems Property Hard
A. Different recursion branches can request the same integer argument
B. Every recursive call receives a strictly smaller integer argument
C. The recursion tree has a finite maximum depth bounded by
D. The recurrence has exactly two recursive terms at each non-base state

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. Discarded rows remove predecessor information needed for direct reconstruction
B. Rolling rows change the recurrence from minimization to maximization
C. Compressed storage makes the computed optimum numerically approximate
D. Two-row storage is valid only when every transition cost is identical

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 current task index, the total occupied duration, and the first category
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 latest finish time, the number of skipped tasks, and the largest value