Dynamic Programming & Divide and Conquer | 180 min | No notes, no calculator
00:00:00
Part A: Multiple Choice / Short Answer (20 points)
Select the best answer. Some questions may have multiple correct answers.
Question 1 (2 pts)
What is the runtime of the Chain Matrix Multiplication DP algorithm for multiplying a chain of n matrices?
Question 2 (2 pts)
In the Knapsack without repetition problem, which of the following correctly describes the subproblem?
Question 3 (2 pts)
The Karatsuba algorithm for multiplying two n-bit integers makes how many recursive calls on inputs of size n/2?
Question 4 (2 pts)
Which of the following recurrences does the Median of Medians (FastSelect) algorithm satisfy?
Question 5 (2 pts)
Using the Master Theorem on T(n) = 4T(n/2) + O(n), what is the runtime?
Question 6 (2 pts)
Why does the Median of Medians algorithm use groups of 5 instead of groups of 3?
Question 7 (2 pts)
In the Chain Matrix Multiplication problem, what do the subproblems represent?
Question 8 (2 pts)
What is the runtime of the naive divide-and-conquer algorithm for integer multiplication (before the Karatsuba improvement)?
Question 9 (2 pts)
For the LCS (Longest Common Subsequence) problem on strings of length m and n, what is the size of the DP table?
Question 10 (2 pts)
Which of the following is TRUE about D&C solutions in this course? (Select all that apply)
Part B: Dynamic Programming (10 points)
Define subproblem, recurrence, base case, runtime, and how to extract the answer.
Problem B1 (10 pts)
You are given a sequence of n words with lengths ℓ₁, ℓ₂, ..., ℓₙ. You want to arrange them into lines, where each line can hold at most L characters (including exactly one space between adjacent words on the same line). The penalty for a line is (L − total characters used on that line)³ — i.e., the cube of the leftover space. The last line has zero penalty regardless of leftover space.
Design a DP algorithm to partition the words into lines minimizing the total penalty.
Required parts: (1) Define table entries in words. (2) Recurrence with base case. (3a) Number of subproblems. (3b) Runtime to fill table. (3c) How return is extracted. (3d) Runtime of extraction.
Part C: Divide and Conquer (20 points)
Describe your algorithm in plain English (no pseudocode). Justify correctness. Analyze runtime.
Problem C1 (20 pts)
You are given a sorted array A of n distinct integers. An element A[i] is called a fixed point if A[i] = i (using 1-based indexing). Design an O(log n) algorithm to find a fixed point if one exists, or report that none exists.
Faster (and correct) solutions are worth more credit.
⚠️ Remember: Describe in plain English. No pseudocode. Must include: (a) Algorithm, (b) Justification of Correctness, (c) Runtime Analysis.
Problem C2 (20 pts — BONUS PRACTICE)
You are given an unsorted array A of n distinct integers and a value T. Design a divide-and-conquer algorithm that determines whether there exist two elements in A that sum to T. Your algorithm must run in O(n log n) time.
Faster (and correct) solutions are worth more credit.
⚠️ Remember: Describe in plain English. No pseudocode. Must include: (a) Algorithm, (b) Justification of Correctness, (c) Runtime Analysis.
Copied to clipboard! Send to your AI assistant for feedback ✓