Test Your Knowledge - Based on Quiz 5 (Reductions) & Quiz 2 (Divide & Conquer)
Time Limit: 90 minutes (suggested)
Total Points: 200 points
Note: This is a CLOSED book, closed-notes exam. Work through each problem independently. Write your answers in the provided answer spaces. Click "Show Answer Key" at the bottom to reveal detailed solutions.
Consider the following flow network G. Edges are labeled with flow/capacity notation.
Create the residual graph GR based on the current flow state shown above. Fill in the table below with the edge weights (flow values only, not capacity). The second row is for reverse edges.
| sa | sb | ab | ac | bc | bd | cd | ct | dt |
|---|---|---|---|---|---|---|---|---|
| saR | sbR | abR | acR | bcR | bdR | cdR | ctR | dtR |
Find an augmenting path that the Edmonds-Karp algorithm would provide (uses BFS - shortest path first). Write the path in the form "ABCD" where each letter is a vertex.
Find an augmenting path that the Ford-Fulkerson algorithm could find but Edmonds-Karp would NOT find (any valid path, not necessarily shortest).
What is the maximum flow of this graph? Show the augmenting paths you used.
Word Limit: Questions 2.1-2.5 must be answered in 20 words or fewer. Question 2.6 can be up to 30 words.
What does it mean if a problem X is in the complexity class P?
What does it mean if a problem X is in the complexity class NP?
Why is P ⊆ NP (why is P a subset of NP)?
Explain, in plain English, what NP-complete means. This should be understandable to someone with no computing or mathematical background.
What steps must you complete to show that a problem is NP-complete? (Maximum 30 words)
For a problem reduction to be useful when analyzing complexity, what must be true about the time complexity of the reduction step?
Palindrome Finding Problem: Design a divide-and-conquer algorithm to find the longest palindrome in an array A[] of n characters in Θ(n log n) time. Answer the following:
a) Base case: [6 points]
b) Divide step: [6 points]
c) Conquer (recursive) step: [6 points]
d) Combine step: [6 points]
e) Recurrence relation: [6 points]
Median-of-Medians: Consider a 3×3 blocks version of median-of-medians (three blocks of three elements each) on a list of 9 elements. Using a brief English explanation and/or a diagram, show that the median-of-medians is greater than at least 33% of the values.
Master Theorem: For the recurrence T(n) = 4T(n/2) + n², determine:
Proof by Induction: Using the guess-and-check method, prove that binary search is O(n) using induction.
a) Base case(s): What are your base case(s)? Show that they work. [8 points]
b) Inductive hypothesis: [6 points]
c) Inductive step: Prove your inductive step. [11 points]
Master Theorem Applications: For each recurrence relation, state which case of the Master Theorem applies and give the asymptotic bound.
a) T(n) = 2T(n/2) + n log n [5 points]
b) T(n) = 3T(n/3) + n² [5 points]
c) T(n) = 8T(n/2) + n² [5 points]
All answers are provided with complete explanations to ensure no ambiguity.
Forward Edges (remaining capacity):
| sa | sb | ab | ac | bc | bd | cd | ct | dt |
|---|---|---|---|---|---|---|---|---|
| 5 | 5 | 4 | 2 | 3 | 5 | 2 | 4 | 5 |
Reverse Edges (current flow that can be pushed back):
| saR | sbR | abR | acR | bcR | bdR | cdR | ctR | dtR |
|---|---|---|---|---|---|---|---|---|
| 5 | 3 | 0 | 5 | 3 | 0 | 2 | 6 | 2 |
Explanation:
ANSWER: s → a → c → t
Explanation:
ANSWER: s → b → c → d → t
Explanation:
ANSWER: Maximum flow = 13
Augmenting paths used:
Verification:
ANSWER: Problem X can be solved in polynomial time.
Alternative acceptable answers:
ANSWER: Problem X can be verified in polynomial time.
Alternative acceptable answers:
Note: NP stands for "Nondeterministic Polynomial time," NOT "Non-Polynomial"
ANSWER: If a problem can be solved in polynomial time, it can also be verified in polynomial time.
Alternative acceptable answers:
Detailed explanation: If we have an algorithm that solves problem X in polynomial time, we can use that same algorithm to verify a proposed solution (just solve the problem ourselves and compare the result). Since solving takes polynomial time, verification also takes polynomial time, so X ∈ NP.
ANSWER: NP-complete problems are the hardest problems to solve, but easy to check if someone gives you an answer.
Alternative acceptable answers:
Real-world analogy: Like a jigsaw puzzle - very hard to solve, but easy to check if it's completed correctly by just looking at it.
ANSWER: (1) Show the problem is in NP (verifiable in polynomial time), AND (2) Reduce a known NP-complete problem to it in polynomial time.
Breakdown of the two steps:
Common mistakes to avoid:
ANSWER: d) Polynomial time
Explanation: For a reduction to be useful in complexity analysis, the reduction itself must take polynomial time (or faster). This is critical because:
Why other answers are wrong:
a) Base case [6 points]:
ANSWER: If the array has 1 or 2 elements, check directly. A single character is a palindrome of length 1. Two characters are a palindrome if they match, otherwise the longest palindrome is length 1.
b) Divide step [6 points]:
ANSWER: Divide the array A[1...n] into two halves: left = A[1...n/2] and right = A[n/2+1...n]
c) Conquer step [6 points]:
ANSWER: Recursively find the longest palindrome in the left half and in the right half. Let these be Lleft and Lright.
d) Combine step [6 points]:
ANSWER: Find the longest palindrome that crosses the midpoint by expanding from the center outward (similar to merge in mergesort). Compare Lleft, Lright, and Lcross, and return the longest one. The crossing palindrome check takes O(n) time.
e) Recurrence relation [6 points]:
ANSWER: T(n) = 2T(n/2) + O(n)
This solves to Θ(n log n) by Master Theorem Case 2 (a=2, b=2, logba = 1, f(n) = n = n1)
ANSWER:
Arrange 9 elements into 3 groups of 3:
Group 1: [a, b, c] → median = b
Group 2: [d, e, f] → median = e
Group 3: [g, h, i] → median = h
Medians: [b, e, h] → median-of-medians = e
After sorting each group:
a ≤ b ≤ c
d ≤ e ≤ f
g ≤ h ≤ i
And sorting the medians: b ≤ e ≤ h
Elements definitely ≤ e: {a, b, d, e} = 4 elements
Elements definitely ≥ e: {e, f, h, i} = 4 elements
Conclusion: e is greater than or equal to at least 4 out of 9 elements = 44.4% > 33% ✓
Note: We're unsure about c and g, but we don't need them to prove the 33% guarantee.
Recurrence: T(n) = 4T(n/2) + n²
Identify parameters:
Compare f(n) with nlogba:
Which case applies: Case 2
Since f(n) = Θ(nlogba logk n) where k = 0
Solution: T(n) = Θ(n² log n)
Intuition: The work at each level is n², and there are log n levels, so total work is n² × log n.
a) Base case(s) [8 points]:
ANSWER: Base case: n = 1
Alternative base case: n = 0
b) Inductive hypothesis [6 points]:
ANSWER: Assume that for all k < n, T(k) ≤ c·k for some constant c ≥ 1
c) Inductive step [11 points]:
ANSWER: Need to prove: T(n) ≤ c·n
Binary search recurrence: T(n) = T(n/2) + O(1)
Let d be the constant for the O(1) work, so T(n) = T(n/2) + d
By inductive hypothesis: T(n/2) ≤ c·(n/2)
Therefore:
T(n) = T(n/2) + d
≤ c·(n/2) + d (by inductive hypothesis)
= cn/2 + d
≤ cn (if we choose c ≥ 2d)
Conclusion: By choosing c ≥ max(1, 2d), we have T(n) ≤ cn for all n ≥ 0, proving binary search is O(n) ✓
Note: This is a weak bound - binary search is actually O(log n), but O(n) is technically correct since O(log n) ⊆ O(n).
a) T(n) = 2T(n/2) + n log n [5 points]
b) T(n) = 3T(n/3) + n² [5 points]
c) T(n) = 8T(n/2) + n² [5 points]
Total: 200 points