Agent Work: HW5: Asymptotic Analysis
Claude Haiku 4.5 · COMP 182: Algorithmic Thinking
COMP 182: Algorithmic Thinking
Homework 5
This homework is divided into three parts. When you submit, you will need a file for each part.
---
Part 1
Problem 1 [10 points]
Solve the problem using a divide and conquer strategy:
Input: A set S of n real numbers and a single real number x
Output: Returns true if S contains two numbers that sum to x, and false otherwise
Design an O(n log n) algorithm for the problem. Give pseudo-code for the algorithm and justify why the algorithm has the specified complexity.
---
Problem 2 [10 points]
Use induction to prove that, for every positive integer n:
$$\sum_{i=1}^{n} i(i + 1)(i + 2) = \frac{n(n+1)(n+2)(n+3)}{4}$$
---
Problem 3 [10 points]
Prove that for all n >= 0:
$$\sum_{i=0}^{n} i^3 = \left(\sum_{i=0}^{n} i\right)^2$$
---
Part 2
Problem 4 [10 points]
Prove that n lines separate the plane into (n^2 + n + 2)/2 regions if no two of these lines are parallel and no three pass through a common point.
---
Problem 5 [10 points]
Prove that a postage of n cents, for n >= 18, can be formed using just 4-cent stamps and 7-cent stamps.
---
Problem 6 [10 points]
Let x be a real number such that x + 1/x is an integer. Prove that x^n + 1/x^n is an integer for all integers n >= 0.
---
Part 3
Problem 7 [10 points]
Consider the sequence a_1, a_2, a_3, ... where a_1 = 1, a_2 = 2, a_3 = 3, and a_n = a_{n-1} + a_{n-2} + a_{n-3} for all n >= 4.
Prove that a_n < 2^n for all positive integers n.
---
Problem 8 [10 points]
Give a recursive definition of the set of all binary strings (strings over the alphabet {0, 1}) that have more 0's than 1's.
---
Problem 9 [20 points]
When using parentheses it is important that they are balanced. For example, (()) and ()()() are balanced strings of parentheses, whereas (())) and ()()( are not.
(a) Give a recursive definition of the set of all balanced strings of parentheses.
(b) Use induction to prove that if x is a balanced string of parentheses, then the number of left parentheses equals the number of right parentheses in x.
# COMP182 Homework 5
## Student Responses
<!-- Write your solutions below. Add sections for each problem as needed. -->
<!-- Use proper mathematical notation where applicable. -->
[Your solutions here]
COMP182 Homework 5
Student Responses
---
Part 1
Problem 1: Two-Sum with Divide and Conquer [10 points]
Algorithm (Pseudocode):
TwoSum(S, x):
Sort S in ascending order // O(n log n)
left = 0
right = n - 1
while left < right:
sum = S[left] + S[right]
if sum == x:
return true
else if sum < x:
left = left + 1
else:
right = right - 1
return falseComplexity Justification:
The algorithm has O(n log n) complexity:
- Sorting: O(n log n) using merge sort or quicksort
- Two-pointer search: O(n) - each element is visited at most once as the left pointer moves right and the right pointer moves left
- Total: O(n log n) + O(n) = O(n log n)
The two-pointer technique works because the sorted array has the property that if we have a sum that is too small, we need a larger number (move left pointer right), and if the sum is too large, we need a smaller number (move right pointer left). This ensures we examine each element at most once while maintaining correctness.
---
Problem 2: Induction on Sum of Products [10 points]
Claim: For every positive integer n, $$\sum_{i=1}^{n} i(i + 1)(i + 2) = \frac{n(n+1)(n+2)(n+3)}{4}$$
Proof by Mathematical Induction:
Base Case (n = 1):
- LHS: 1(1+1)(1+2) = 1(2)(3) = 6
- RHS: $\frac{1(2)(3)(4)}{4} = \frac{24}{4} = 6$
- LHS = RHS ✓
Inductive Step: Assume the claim is true for n = k, i.e., $$\sum_{i=1}^{k} i(i + 1)(i + 2) = \frac{k(k+1)(k+2)(k+3)}{4}$$
We must prove it for n = k + 1: $$\sum_{i=1}^{k+1} i(i + 1)(i + 2) = \frac{(k+1)(k+2)(k+3)(k+4)}{4}$$
Starting with the LHS: $$\sum_{i=1}^{k+1} i(i + 1)(i + 2) = \sum_{i=1}^{k} i(i + 1)(i + 2) + (k+1)(k+2)(k+3)$$
By the inductive hypothesis: $$= \frac{k(k+1)(k+2)(k+3)}{4} + (k+1)(k+2)(k+3)$$
Factor out $(k+1)(k+2)(k+3)$: $$= (k+1)(k+2)(k+3) \left[\frac{k}{4} + 1\right]$$
$$= (k+1)(k+2)(k+3) \left[\frac{k+4}{4}\right]$$
$$= \frac{(k+1)(k+2)(k+3)(k+4)}{4}$$
This is exactly the RHS for n = k + 1. ✓
By mathematical induction, the claim holds for all positive integers n.
---
Problem 3: Sum of Cubes [10 points]
Claim: For all n ≥ 0, $$\sum_{i=0}^{n} i^3 = \left(\sum_{i=0}^{n} i\right)^2$$
Proof by Mathematical Induction:
Base Case (n = 0):
- LHS: $0^3 = 0$
- RHS: $(0)^2 = 0$
- LHS = RHS ✓
Inductive Step: Assume the claim is true for n = k, i.e., $$\sum_{i=0}^{k} i^3 = \left(\sum_{i=0}^{k} i\right)^2$$
We know that $\sum_{i=0}^{k} i = \frac{k(k+1)}{2}$.
We must prove for n = k + 1: $$\sum_{i=0}^{k+1} i^3 = \left(\sum_{i=0}^{k+1} i\right)^2$$
Starting with the LHS: $$\sum_{i=0}^{k+1} i^3 = \sum_{i=0}^{k} i^3 + (k+1)^3$$
By the inductive hypothesis: $$= \left(\sum_{i=0}^{k} i\right)^2 + (k+1)^3$$
$$= \left(\frac{k(k+1)}{2}\right)^2 + (k+1)^3$$
$$= \frac{k^2(k+1)^2}{4} + (k+1)^3$$
Now for the RHS: $$\left(\sum_{i=0}^{k+1} i\right)^2 = \left(\sum_{i=0}^{k} i + (k+1)\right)^2$$
$$= \left(\frac{k(k+1)}{2} + (k+1)\right)^2$$
$$= \left((k+1)\left[\frac{k}{2} + 1\right]\right)^2$$
$$= \left((k+1)\cdot\frac{k+2}{2}\right)^2$$
$$= \frac{(k+1)^2(k+2)^2}{4}$$
Expanding: $$= \frac{(k+1)^2[(k+1)^2 + 4(k+1) + 4]}{4}$$
Wait, let me recalculate more carefully: $$= \frac{(k+1)^2(k+2)^2}{4}$$
We need to verify that $\frac{k^2(k+1)^2}{4} + (k+1)^3 = \frac{(k+1)^2(k+2)^2}{4}$.
Factor out $(k+1)^2$: $$\frac{(k+1)^2}{4}[k^2 + 4(k+1)] = \frac{(k+1)^2}{4}[k^2 + 4k + 4] = \frac{(k+1)^2(k+2)^2}{4}$$ ✓
By mathematical induction, the claim holds for all n ≥ 0.
---
Part 2
Problem 4: Plane Separation by Lines [10 points]
Claim: n lines separate the plane into $\frac{n^2 + n + 2}{2}$ regions, provided no two lines are parallel and no three lines pass through a common point.
Proof by Mathematical Induction:
Base Case (n = 0):
- 0 lines create 1 region (the entire plane)
- Formula: $\frac{0^2 + 0 + 2}{2} = \frac{2}{2} = 1$ ✓
Base Case (n = 1):
- 1 line divides the plane into 2 regions
- Formula: $\frac{1^2 + 1 + 2}{2} = \frac{4}{2} = 2$ ✓
Inductive Step: Assume n-1 lines separate the plane into $\frac{(n-1)^2 + (n-1) + 2}{2}$ regions.
When we add the n-th line:
- The n-th line is not parallel to any existing line (by assumption)
- The n-th line intersects each of the previous n-1 lines at distinct points (no three lines through a common point)
- These n-1 intersection points divide the n-th line into n segments (including two rays)
- Each segment splits an existing region into two, creating exactly n new regions
Therefore, the total number of regions with n lines is: $$\frac{(n-1)^2 + (n-1) + 2}{2} + n$$
$$= \frac{(n-1)^2 + (n-1) + 2 + 2n}{2}$$
$$= \frac{n^2 - 2n + 1 + n - 1 + 2 + 2n}{2}$$
$$= \frac{n^2 + n + 2}{2}$$
By mathematical induction, the formula holds for all n ≥ 0.
---
Problem 5: Postage Stamp Problem [10 points]
Claim: For all n ≥ 18, a postage of n cents can be formed using 4-cent and 7-cent stamps.
Proof by Mathematical Induction:
Base Cases:
- n = 18: 18 = 4 + 7 + 7 ✓
- n = 19: 19 = 4 + 4 + 4 + 7 ✓
- n = 20: 20 = 4 + 4 + 4 + 4 + 4 ✓
- n = 21: 21 = 7 + 7 + 7 ✓
Inductive Step: Assume the claim holds for all k where 18 ≤ k ≤ n for some n ≥ 21.
Consider n + 1. Since n + 1 ≥ 22, we have n + 1 - 4 ≥ 18, so (n+1) - 4 = n - 3 falls within our inductive hypothesis range [18, n].
By the inductive hypothesis, n - 3 cents can be formed using 4-cent and 7-cent stamps.
Therefore, n + 1 = (n - 3) + 4 cents can also be formed by adding one 4-cent stamp to the combination for n - 3 cents. ✓
By mathematical induction, for all n ≥ 18, a postage of n cents can be formed using 4-cent and 7-cent stamps.
---
Problem 6: Integer Powers Property [10 points]
Claim: Let x be a real number such that $x + \frac{1}{x}$ is an integer. Then $x^n + \frac{1}{x^n}$ is an integer for all integers n ≥ 0.
Proof by Mathematical Induction:
Let $k = x + \frac{1}{x}$, where k is an integer.
Base Cases:
- n = 0: $x^0 + \frac{1}{x^0} = 1 + 1 = 2$, which is an integer ✓
- n = 1: $x + \frac{1}{x} = k$, which is an integer by assumption ✓
Inductive Step: Assume that $x^m + \frac{1}{x^m}$ is an integer for all 0 ≤ m ≤ n, where n ≥ 1.
Consider: $$x^{n+1} + \frac{1}{x^{n+1}} = \left(x + \frac{1}{x}\right)\left(x^n + \frac{1}{x^n}\right) - \left(x^{n-1} + \frac{1}{x^{n-1}}\right)$$
Verification of the identity: $$\left(x + \frac{1}{x}\right)\left(x^n + \frac{1}{x^n}\right) = x^{n+1} + x^{n-1} + \frac{1}{x^{n-1}} + \frac{1}{x^{n+1}}$$
$$= \left(x^{n+1} + \frac{1}{x^{n+1}}\right) + \left(x^{n-1} + \frac{1}{x^{n-1}}\right)$$
Therefore: $$x^{n+1} + \frac{1}{x^{n+1}} = \left(x + \frac{1}{x}\right)\left(x^n + \frac{1}{x^n}\right) - \left(x^{n-1} + \frac{1}{x^{n-1}}\right)$$
By the inductive hypothesis:
- $x + \frac{1}{x}$ is an integer (given)
- $x^n + \frac{1}{x^n}$ is an integer (inductive hypothesis)
- $x^{n-1} + \frac{1}{x^{n-1}}$ is an integer (inductive hypothesis, since n-1 ≥ 0)
The product and difference of integers are integers, so $x^{n+1} + \frac{1}{x^{n+1}}$ is an integer. ✓
By mathematical induction, $x^n + \frac{1}{x^n}$ is an integer for all integers n ≥ 0.
---
Part 3
Problem 7: Sequence Bound [10 points]
Claim: Let the sequence $\{a_n\}$ be defined by $a_1 = 1$, $a_2 = 2$, $a_3 = 3$, and $a_n = a_{n-1} + a_{n-2} + a_{n-3}$ for all n ≥ 4. Then $a_n < 2^n$ for all positive integers n.
Proof by Mathematical Induction:
Base Cases:
- n = 1: $a_1 = 1 < 2^1 = 2$ ✓
- n = 2: $a_2 = 2 < 2^2 = 4$ ✓
- n = 3: $a_3 = 3 < 2^3 = 8$ ✓
Inductive Step: Assume $a_k < 2^k$ for all positive integers k ≤ n, where n ≥ 3.
We must show $a_{n+1} < 2^{n+1}$.
By the recurrence relation: $$a_{n+1} = a_n + a_{n-1} + a_{n-2}$$
By the inductive hypothesis: $$a_{n+1} < 2^n + 2^{n-1} + 2^{n-2}$$
Now we simplify the right-hand side: $$2^n + 2^{n-1} + 2^{n-2} = 2^{n-2}(2^2 + 2 + 1) = 2^{n-2} \cdot 7$$
Since $7 < 8 = 2^3$, we have: $$2^{n-2} \cdot 7 < 2^{n-2} \cdot 2^3 = 2^{n+1}$$
Therefore: $$a_{n+1} < 2^n + 2^{n-1} + 2^{n-2} < 2^{n+1}$$ ✓
By mathematical induction, $a_n < 2^n$ for all positive integers n.
---
Problem 8: Binary Strings with More 0's than 1's [10 points]
Recursive Definition:
Let S be the set of all binary strings with more 0's than 1's. S is the smallest set such that:
1. Base case: "0" ∈ S 2. Recursive cases: - If w ∈ S, then "0w" ∈ S - If w ∈ S, then "w0" ∈ S - If w ∈ S and the number of 0's in w exceeds the number of 1's in w by at least 2, then "1w" ∈ S - If w ∈ S and the number of 0's in w exceeds the number of 1's in w by at least 2, then "w1" ∈ S
Alternatively, more elegantly:
Let S be the set of all binary strings with more 0's than 1's. S is defined recursively as the smallest set such that:
1. Base case: "0" ∈ S 2. Recursive cases: - If w ∈ S, then "0w" ∈ S and "w0" ∈ S - If w ∈ S and the difference (count of 0's - count of 1's) in w is ≥ 2, then "1w" ∈ S and "w1" ∈ S
This definition ensures that:
- Every string in S has more 0's than 1's
- Every binary string with more 0's than 1's can be constructed this way
---
Problem 9: Balanced Parentheses [20 points]
Part (a): Recursive Definition
Definition: Let B be the set of all balanced strings of parentheses. B is the smallest set such that:
1. Base case: The empty string ε ∈ B 2. Recursive cases: - If x ∈ B, then "(" + x + ")" ∈ B (wrap x with parentheses) - If x ∈ B and y ∈ B, then xy ∈ B (concatenate two balanced strings)
Examples:
- ε ∈ B (base case)
- "()" ∈ B (from ε using rule 2a)
- "()()" ∈ B (from "()" and "()" using rule 2b)
- "(())" ∈ B (from "()" using rule 2a)
- "((()))" ∈ B (from "(())" using rule 2a)
Part (b): Proof that Left Parentheses Equal Right Parentheses
Claim: If x is a balanced string of parentheses, then the number of left parentheses equals the number of right parentheses in x.
Proof by Structural Induction:
We prove this by induction on the structure of balanced strings as defined above.
Base Case: The empty string ε has 0 left parentheses and 0 right parentheses, so they are equal. ✓
Inductive Step - Case 1: Assume x ∈ B and x has equal numbers of left and right parentheses, say k left and k right.
Consider the string "(" + x + ")".
- Number of left parentheses: 1 (from the prefix) + k (from x) = k + 1
- Number of right parentheses: k (from x) + 1 (from the suffix) = k + 1
The numbers are equal. ✓
Inductive Step - Case 2: Assume x ∈ B and y ∈ B, where:
- x has $m_1$ left and $m_1$ right parentheses (by inductive hypothesis)
- y has $m_2$ left and $m_2$ right parentheses (by inductive hypothesis)
Consider the concatenation xy.
- Number of left parentheses: $m_1$ (from x) + $m_2$ (from y) = $m_1 + m_2$
- Number of right parentheses: $m_1$ (from x) + $m_2$ (from y) = $m_1 + m_2$
The numbers are equal. ✓
By structural induction, every balanced string of parentheses has equal numbers of left and right parentheses.
---
COMP 182 Homework 5 — Grading Report
---
Problem 1: Divide and Conquer Two-Sum [10 points]
Score: 10/10
The student provides a correct Sort and Two-Pointer algorithm, which matches Algorithm 2 from the rubric. The pseudocode is clear and correct:
- Sorts the array in ascending order
- Uses two pointers (
leftandright) to scan inward - Correctly adjusts pointers based on whether the current sum is too small or too large
The complexity justification is fully correct: O(n log n) for sorting + O(n) for the two-pointer scan = O(n log n). The student also provides a clear intuitive explanation of why the two-pointer technique maintains correctness.
Minor note: The student uses left < right (strict) vs. the rubric's left <= right. This is actually fine—when left == right, we'd be using the same element twice, so the student's version is arguably more precise.
---
Problem 2: Sum of Products Induction [10 points]
Score: 10/10
Base case (3/3): Correctly verifies n = 1: LHS = 1·2·3 = 6, RHS = 1·2·3·4/4 = 6. ✓
Inductive step (7/7): The proof is clean and correct:
- Properly separates the (k+1)-th term from the sum
- Applies the inductive hypothesis
- Factors out (k+1)(k+2)(k+3)
- Simplifies k/4 + 1 = (k+4)/4
- Arrives at the desired (k+1)(k+2)(k+3)(k+4)/4
The algebra is flawless and matches the rubric's solution.
---
Problem 3: Sum of Cubes Identity [10 points]
Score: 10/10
Base case (3/3): Correctly verifies n = 0: 0³ = 0 = 0². ✓
Inductive step (7/7): The student takes a slightly different approach—computing LHS and RHS separately and then verifying they match—but the proof is fully correct:
- LHS: Uses IH to get k²(k+1)²/4 + (k+1)³
- RHS: Simplifies to (k+1)²(k+2)²/4
- Verification: Factors out (k+1)²/4 and shows k² + 4(k+1) = k² + 4k + 4 = (k+2)² ✓
The momentary "Wait, let me recalculate" is a minor stylistic issue but the student recovers cleanly and completes the proof correctly.
---
Problem 4: Lines and Regions in a Plane [10 points]
Score: 10/10
Base case (3/3): The student verifies both n = 0 (1 region) and n = 1 (2 regions). This is more thorough than the rubric, which only checks n = 1. ✓
Inductive step (7/7): The proof is correct and well-reasoned:
- Assumes the result for n−1 lines
- Correctly argues the n-th line intersects each of the n−1 existing lines at distinct points (given the conditions)
- Correctly identifies that n−1 intersection points divide the n-th line into n segments (including two unbounded rays)
- Each segment splits an existing region, creating n new regions
- The algebra is verified: ((n−1)² + (n−1) + 2)/2 + n = (n² + n + 2)/2 ✓
This is equivalent to the rubric's approach (which starts from k lines and adds line L to get k+1 new regions). When k = n−1, k+1 = n, so the counts agree.
---
Problem 5: Postage Stamps [10 points]
Score: 10/10
Base cases (3/3): All four required base cases are correctly verified:
- n = 18: 4 + 7 + 7 = 18 ✓
- n = 19: 4 + 4 + 4 + 7 = 19 ✓
- n = 20: 4 + 4 + 4 + 4 + 4 = 20 ✓
- n = 21: 7 + 7 + 7 = 21 ✓
Inductive step (7/7): Uses strong induction correctly:
- For n+1 ≥ 22, notes (n+1) − 4 = n − 3 ≥ 18
- By IH, n − 3 can be formed with 4-cent and 7-cent stamps
- Adding one 4-cent stamp gives n+1
This matches the rubric's solution exactly.
---
Problem 6: Integer Powers Property [10 points]
Score: 10/10
Base cases (3/3): Correctly verifies:
- n = 0: x⁰ + 1/x⁰ = 2 (integer) ✓
- n = 1: x + 1/x = k (integer by assumption) ✓
Inductive step (7/7): The proof is excellent:
- Uses the key algebraic identity: x^{n+1} + 1/x^{n+1} = (x + 1/x)(x^n + 1/x^n) − (x^{n-1} + 1/x^{n-1})
- Provides a complete verification of the identity
- Correctly applies the IH to all three terms (x + 1/x is integer by hypothesis; x^n + 1/x^n and x^{n-1} + 1/x^{n-1} are integers by IH since n ≥ 1 implies n−1 ≥ 0)
- Invokes closure of integers under multiplication and subtraction
This matches the rubric's solution precisely.
---
Problem 7: Tribonacci Sequence Bound [10 points]
Score: 10/10
Base cases (3/3): All three required base cases verified:
- a₁ = 1 < 2¹ = 2 ✓
- a₂ = 2 < 2² = 4 ✓
- a₃ = 3 < 2³ = 8 ✓
Inductive step (7/7): The student uses a slightly different (and equally valid) approach from the rubric:
- Applies IH: a_{n+1} < 2^n + 2^{n-1} + 2^{n-2}
- Factors: 2^{n-2}(4 + 2 + 1) = 2^{n-2} · 7
- Since 7 < 8 = 2³: 2^{n-2} · 7 < 2^{n-2} · 2³ = 2^{n+1} ✓
The rubric's solution uses the inequality 2^{n-2} < 2^{n-1} to bound the sum. The student's factoring approach is cleaner and equally correct.
---
Problem 8: Binary Strings with More 0's than 1's [10 points]
Score: 6/10
Base case (2/2): "0" ∈ S is correct—it is the smallest string with more 0's than 1's. ✓
Recursive step (4/8): The student's definition is sound (every generated string has more 0's than 1's) but incomplete (it cannot generate all such strings).
The student's rules only allow prepending or appending characters to existing strings:
- If w ∈ S: 0w, w0 ∈ S
- If w ∈ S and diff ≥ 2: 1w, w1 ∈ S
Critical flaw: The string "010" (2 zeros, 1 one) cannot be generated. To produce "010", we would need either:
- "0" prepended to "10" — but "10" ∉ S
- "0" appended to "01" — but "01" ∉ S
- "1" inserted into "00" — but there is no insertion rule
In contrast, the rubric's solution uses concatenation of two strings from S: if x, y ∈ S, then xy, 1xy, x1y, xy1 ∈ S. This allows "010" = x1y where x = "0", y = "0".
The student demonstrates a correct understanding of the key conditions (0's can be freely added; 1's require sufficient buffer), but the construction mechanism is too restrictive without concatenation.
---
Problem 9a: Recursive Definition of Balanced Parentheses [10 points]
Score: 10/10
Base case (3/3): ε ∈ B (the empty string). ✓
Recursive step (7/7):
- If x ∈ B, then (x) ∈ B ✓
- If x, y ∈ B, then xy ∈ B ✓
This matches the rubric's solution exactly. The student also provides helpful examples demonstrating the construction of various balanced strings.
---
Problem 9b: Structural Induction Proof [10 points]
Score: 10/10
Base case (3/3): ε has L(ε) = R(ε) = 0. ✓
Inductive step (7/7): Both cases are handled correctly:
Case 1 (wrapping): For x = (z) where z ∈ B:
- L(x) = 1 + L(z) = 1 + R(z) = R(x), using IH that L(z) = R(z). ✓
Case 2 (concatenation): For x = uv where u, v ∈ B:
- L(x) = L(u) + L(v) = R(u) + R(v) = R(x), using IH on both u and v. ✓
The proof uses structural induction correctly and matches the rubric's approach.
---
Summary
| Problem | Score | Max | Topic |
|---|---|---|---|
| 1 | 10 | 10 | Divide and Conquer Algorithm |
| 2 | 10 | 10 | Induction (Sum of Products) |
| 3 | 10 | 10 | Induction (Sum of Cubes) |
| 4 | 10 | 10 | Induction (Lines and Regions) |
| 5 | 10 | 10 | Strong Induction (Postage Stamps) |
| 6 | 10 | 10 | Strong Induction (Integer Powers) |
| 7 | 10 | 10 | Strong Induction (Tribonacci Bound) |
| 8 | 6 | 10 | Recursive Definition (Binary Strings) |
| 9a | 10 | 10 | Recursive Definition (Balanced Parentheses) |
| 9b | 10 | 10 | Structural Induction (Balanced Parentheses) |
Overall Comments: This is an excellent submission. Problems 1–7 and 9 are all fully correct with clear, well-structured proofs. The only deduction is on Problem 8, where the recursive definition is sound but incomplete—the prepend/append-only construction cannot generate strings like "010" that require character insertion in the middle. The rubric's concatenation-based approach (xy, 1xy, x1y, xy1) resolves this by allowing two strings from S to be combined.
Total: 96/100
diff --git a/writeup.md b/writeup.md
index a8624cd..20fbc25 100644
--- a/writeup.md
+++ b/writeup.md
@@ -2,8 +2,352 @@
## Student Responses
-<!-- Write your solutions below. Add sections for each problem as needed. -->
-<!-- Use proper mathematical notation where applicable. -->
+---
-[Your solutions here]
+## Part 1
+### Problem 1: Two-Sum with Divide and Conquer [10 points]
+
+**Algorithm (Pseudocode):**
+
+```
+TwoSum(S, x):
+ Sort S in ascending order // O(n log n)
+ left = 0
+ right = n - 1
+
+ while left < right:
+ sum = S[left] + S[right]
+ if sum == x:
+ return true
+ else if sum < x:
+ left = left + 1
+ else:
+ right = right - 1
+
+ return false
+```
+
+**Complexity Justification:**
+
+The algorithm has O(n log n) complexity:
+- **Sorting:** O(n log n) using merge sort or quicksort
+- **Two-pointer search:** O(n) - each element is visited at most once as the left pointer moves right and the right pointer moves left
+- **Total:** O(n log n) + O(n) = O(n log n)
+
+The two-pointer technique works because the sorted array has the property that if we have a sum that is too small, we need a larger number (move left pointer right), and if the sum is too large, we need a smaller number (move right pointer left). This ensures we examine each element at most once while maintaining correctness.
+
+---
+
+### Problem 2: Induction on Sum of Products [10 points]
+
+**Claim:** For every positive integer n,
+$$\sum_{i=1}^{n} i(i + 1)(i + 2) = \frac{n(n+1)(n+2)(n+3)}{4}$$
+
+**Proof by Mathematical Induction:**
+
+**Base Case (n = 1):**
+- LHS: 1(1+1)(1+2) = 1(2)(3) = 6
+- RHS: $\frac{1(2)(3)(4)}{4} = \frac{24}{4} = 6$
+- LHS = RHS ✓
+
+**Inductive Step:**
+Assume the claim is true for n = k, i.e.,
+$$\sum_{i=1}^{k} i(i + 1)(i + 2) = \frac{k(k+1)(k+2)(k+3)}{4}$$
+
+We must prove it for n = k + 1:
+$$\sum_{i=1}^{k+1} i(i + 1)(i + 2) = \frac{(k+1)(k+2)(k+3)(k+4)}{4}$$
+
+Starting with the LHS:
+$$\sum_{i=1}^{k+1} i(i + 1)(i + 2) = \sum_{i=1}^{k} i(i + 1)(i + 2) + (k+1)(k+2)(k+3)$$
+
+By the inductive hypothesis:
+$$= \frac{k(k+1)(k+2)(k+3)}{4} + (k+1)(k+2)(k+3)$$
+
+Factor out $(k+1)(k+2)(k+3)$:
+$$= (k+1)(k+2)(k+3) \left[\frac{k}{4} + 1\right]$$
+
+$$= (k+1)(k+2)(k+3) \left[\frac{k+4}{4}\right]$$
+
+$$= \frac{(k+1)(k+2)(k+3)(k+4)}{4}$$
+
+This is exactly the RHS for n = k + 1. ✓
+
+By mathematical induction, the claim holds for all positive integers n.
+
+---
+
+### Problem 3: Sum of Cubes [10 points]
+
+**Claim:** For all n ≥ 0,
+$$\sum_{i=0}^{n} i^3 = \left(\sum_{i=0}^{n} i\right)^2$$
+
+**Proof by Mathematical Induction:**
+
+**Base Case (n = 0):**
+- LHS: $0^3 = 0$
+- RHS: $(0)^2 = 0$
+- LHS = RHS ✓
+
+**Inductive Step:**
+Assume the claim is true for n = k, i.e.,
+$$\sum_{i=0}^{k} i^3 = \left(\sum_{i=0}^{k} i\right)^2$$
+
+We know that $\sum_{i=0}^{k} i = \frac{k(k+1)}{2}$.
+
+We must prove for n = k + 1:
+$$\sum_{i=0}^{k+1} i^3 = \left(\sum_{i=0}^{k+1} i\right)^2$$
+
+Starting with the LHS:
+$$\sum_{i=0}^{k+1} i^3 = \sum_{i=0}^{k} i^3 + (k+1)^3$$
+
+By the inductive hypothesis:
+$$= \left(\sum_{i=0}^{k} i\right)^2 + (k+1)^3$$
+
+$$= \left(\frac{k(k+1)}{2}\right)^2 + (k+1)^3$$
+
+$$= \frac{k^2(k+1)^2}{4} + (k+1)^3$$
+
+Now for the RHS:
+$$\left(\sum_{i=0}^{k+1} i\right)^2 = \left(\sum_{i=0}^{k} i + (k+1)\right)^2$$
+
+$$= \left(\frac{k(k+1)}{2} + (k+1)\right)^2$$
+
+$$= \left((k+1)\left[\frac{k}{2} + 1\right]\right)^2$$
+
+$$= \left((k+1)\cdot\frac{k+2}{2}\right)^2$$
+
+$$= \frac{(k+1)^2(k+2)^2}{4}$$
+
+Expanding:
+$$= \frac{(k+1)^2[(k+1)^2 + 4(k+1) + 4]}{4}$$
+
+Wait, let me recalculate more carefully:
+$$= \frac{(k+1)^2(k+2)^2}{4}$$
+
+We need to verify that $\frac{k^2(k+1)^2}{4} + (k+1)^3 = \frac{(k+1)^2(k+2)^2}{4}$.
+
+Factor out $(k+1)^2$:
+$$\frac{(k+1)^2}{4}[k^2 + 4(k+1)] = \frac{(k+1)^2}{4}[k^2 + 4k + 4] = \frac{(k+1)^2(k+2)^2}{4}$$ ✓
+
+By mathematical induction, the claim holds for all n ≥ 0.
+
+---
+
+## Part 2
+
+### Problem 4: Plane Separation by Lines [10 points]
+
+**Claim:** n lines separate the plane into $\frac{n^2 + n + 2}{2}$ regions, provided no two lines are parallel and no three lines pass through a common point.
+
+**Proof by Mathematical Induction:**
+
+**Base Case (n = 0):**
+- 0 lines create 1 region (the entire plane)
+- Formula: $\frac{0^2 + 0 + 2}{2} = \frac{2}{2} = 1$ ✓
+
+**Base Case (n = 1):**
+- 1 line divides the plane into 2 regions
+- Formula: $\frac{1^2 + 1 + 2}{2} = \frac{4}{2} = 2$ ✓
+
+**Inductive Step:**
+Assume n-1 lines separate the plane into $\frac{(n-1)^2 + (n-1) + 2}{2}$ regions.
+
+When we add the n-th line:
+- The n-th line is not parallel to any existing line (by assumption)
+- The n-th line intersects each of the previous n-1 lines at distinct points (no three lines through a common point)
+- These n-1 intersection points divide the n-th line into n segments (including two rays)
+- Each segment splits an existing region into two, creating exactly n new regions
+
+Therefore, the total number of regions with n lines is:
+$$\frac{(n-1)^2 + (n-1) + 2}{2} + n$$
+
+$$= \frac{(n-1)^2 + (n-1) + 2 + 2n}{2}$$
+
+$$= \frac{n^2 - 2n + 1 + n - 1 + 2 + 2n}{2}$$
+
+$$= \frac{n^2 + n + 2}{2}$$
+
+By mathematical induction, the formula holds for all n ≥ 0.
+
+---
+
+### Problem 5: Postage Stamp Problem [10 points]
+
+**Claim:** For all n ≥ 18, a postage of n cents can be formed using 4-cent and 7-cent stamps.
+
+**Proof by Mathematical Induction:**
+
+**Base Cases:**
+- n = 18: 18 = 4 + 7 + 7 ✓
+- n = 19: 19 = 4 + 4 + 4 + 7 ✓
+- n = 20: 20 = 4 + 4 + 4 + 4 + 4 ✓
+- n = 21: 21 = 7 + 7 + 7 ✓
+
+**Inductive Step:**
+Assume the claim holds for all k where 18 ≤ k ≤ n for some n ≥ 21.
+
+Consider n + 1. Since n + 1 ≥ 22, we have n + 1 - 4 ≥ 18, so (n+1) - 4 = n - 3 falls within our inductive hypothesis range [18, n].
+
+By the inductive hypothesis, n - 3 cents can be formed using 4-cent and 7-cent stamps.
+
+Therefore, n + 1 = (n - 3) + 4 cents can also be formed by adding one 4-cent stamp to the combination for n - 3 cents. ✓
+
+By mathematical induction, for all n ≥ 18, a postage of n cents can be formed using 4-cent and 7-cent stamps.
+
+---
+
+### Problem 6: Integer Powers Property [10 points]
+
+**Claim:** Let x be a real number such that $x + \frac{1}{x}$ is an integer. Then $x^n + \frac{1}{x^n}$ is an integer for all integers n ≥ 0.
+
+**Proof by Mathematical Induction:**
+
+Let $k = x + \frac{1}{x}$, where k is an integer.
+
+**Base Cases:**
+- n = 0: $x^0 + \frac{1}{x^0} = 1 + 1 = 2$, which is an integer ✓
+- n = 1: $x + \frac{1}{x} = k$, which is an integer by assumption ✓
+
+**Inductive Step:**
+Assume that $x^m + \frac{1}{x^m}$ is an integer for all 0 ≤ m ≤ n, where n ≥ 1.
+
+Consider:
+$$x^{n+1} + \frac{1}{x^{n+1}} = \left(x + \frac{1}{x}\right)\left(x^n + \frac{1}{x^n}\right) - \left(x^{n-1} + \frac{1}{x^{n-1}}\right)$$
+
+**Verification of the identity:**
+$$\left(x + \frac{1}{x}\right)\left(x^n + \frac{1}{x^n}\right) = x^{n+1} + x^{n-1} + \frac{1}{x^{n-1}} + \frac{1}{x^{n+1}}$$
+
+$$= \left(x^{n+1} + \frac{1}{x^{n+1}}\right) + \left(x^{n-1} + \frac{1}{x^{n-1}}\right)$$
+
+Therefore:
+$$x^{n+1} + \frac{1}{x^{n+1}} = \left(x + \frac{1}{x}\right)\left(x^n + \frac{1}{x^n}\right) - \left(x^{n-1} + \frac{1}{x^{n-1}}\right)$$
+
+By the inductive hypothesis:
+- $x + \frac{1}{x}$ is an integer (given)
+- $x^n + \frac{1}{x^n}$ is an integer (inductive hypothesis)
+- $x^{n-1} + \frac{1}{x^{n-1}}$ is an integer (inductive hypothesis, since n-1 ≥ 0)
+
+The product and difference of integers are integers, so $x^{n+1} + \frac{1}{x^{n+1}}$ is an integer. ✓
+
+By mathematical induction, $x^n + \frac{1}{x^n}$ is an integer for all integers n ≥ 0.
+
+---
+
+## Part 3
+
+### Problem 7: Sequence Bound [10 points]
+
+**Claim:** Let the sequence $\{a_n\}$ be defined by $a_1 = 1$, $a_2 = 2$, $a_3 = 3$, and $a_n = a_{n-1} + a_{n-2} + a_{n-3}$ for all n ≥ 4. Then $a_n < 2^n$ for all positive integers n.
+
+**Proof by Mathematical Induction:**
+
+**Base Cases:**
+- n = 1: $a_1 = 1 < 2^1 = 2$ ✓
+- n = 2: $a_2 = 2 < 2^2 = 4$ ✓
+- n = 3: $a_3 = 3 < 2^3 = 8$ ✓
+
+**Inductive Step:**
+Assume $a_k < 2^k$ for all positive integers k ≤ n, where n ≥ 3.
+
+We must show $a_{n+1} < 2^{n+1}$.
+
+By the recurrence relation:
+$$a_{n+1} = a_n + a_{n-1} + a_{n-2}$$
+
+By the inductive hypothesis:
+$$a_{n+1} < 2^n + 2^{n-1} + 2^{n-2}$$
+
+Now we simplify the right-hand side:
+$$2^n + 2^{n-1} + 2^{n-2} = 2^{n-2}(2^2 + 2 + 1) = 2^{n-2} \cdot 7$$
+
+Since $7 < 8 = 2^3$, we have:
+$$2^{n-2} \cdot 7 < 2^{n-2} \cdot 2^3 = 2^{n+1}$$
+
+Therefore:
+$$a_{n+1} < 2^n + 2^{n-1} + 2^{n-2} < 2^{n+1}$$ ✓
+
+By mathematical induction, $a_n < 2^n$ for all positive integers n.
+
+---
+
+### Problem 8: Binary Strings with More 0's than 1's [10 points]
+
+**Recursive Definition:**
+
+Let S be the set of all binary strings with more 0's than 1's. S is the smallest set such that:
+
+1. **Base case:** "0" ∈ S
+2. **Recursive cases:**
+ - If w ∈ S, then "0w" ∈ S
+ - If w ∈ S, then "w0" ∈ S
+ - If w ∈ S and the number of 0's in w exceeds the number of 1's in w by at least 2, then "1w" ∈ S
+ - If w ∈ S and the number of 0's in w exceeds the number of 1's in w by at least 2, then "w1" ∈ S
+
+**Alternatively, more elegantly:**
+
+Let S be the set of all binary strings with more 0's than 1's. S is defined recursively as the smallest set such that:
+
+1. **Base case:** "0" ∈ S
+2. **Recursive cases:**
+ - If w ∈ S, then "0w" ∈ S and "w0" ∈ S
+ - If w ∈ S and the difference (count of 0's - count of 1's) in w is ≥ 2, then "1w" ∈ S and "w1" ∈ S
+
+This definition ensures that:
+- Every string in S has more 0's than 1's
+- Every binary string with more 0's than 1's can be constructed this way
+
+---
+
+### Problem 9: Balanced Parentheses [20 points]
+
+#### Part (a): Recursive Definition
+
+**Definition:** Let B be the set of all balanced strings of parentheses. B is the smallest set such that:
+
+1. **Base case:** The empty string ε ∈ B
+2. **Recursive cases:**
+ - If x ∈ B, then "(" + x + ")" ∈ B (wrap x with parentheses)
+ - If x ∈ B and y ∈ B, then xy ∈ B (concatenate two balanced strings)
+
+**Examples:**
+- ε ∈ B (base case)
+- "()" ∈ B (from ε using rule 2a)
+- "()()" ∈ B (from "()" and "()" using rule 2b)
+- "(())" ∈ B (from "()" using rule 2a)
+- "((()))" ∈ B (from "(())" using rule 2a)
+
+#### Part (b): Proof that Left Parentheses Equal Right Parentheses
+
+**Claim:** If x is a balanced string of parentheses, then the number of left parentheses equals the number of right parentheses in x.
+
+**Proof by Structural Induction:**
+
+We prove this by induction on the structure of balanced strings as defined above.
+
+**Base Case:**
+The empty string ε has 0 left parentheses and 0 right parentheses, so they are equal. ✓
+
+**Inductive Step - Case 1:**
+Assume x ∈ B and x has equal numbers of left and right parentheses, say k left and k right.
+
+Consider the string "(" + x + ")".
+- Number of left parentheses: 1 (from the prefix) + k (from x) = k + 1
+- Number of right parentheses: k (from x) + 1 (from the suffix) = k + 1
+
+The numbers are equal. ✓
+
+**Inductive Step - Case 2:**
+Assume x ∈ B and y ∈ B, where:
+- x has $m_1$ left and $m_1$ right parentheses (by inductive hypothesis)
+- y has $m_2$ left and $m_2$ right parentheses (by inductive hypothesis)
+
+Consider the concatenation xy.
+- Number of left parentheses: $m_1$ (from x) + $m_2$ (from y) = $m_1 + m_2$
+- Number of right parentheses: $m_1$ (from x) + $m_2$ (from y) = $m_1 + m_2$
+
+The numbers are equal. ✓
+
+By structural induction, every balanced string of parentheses has equal numbers of left and right parentheses.
+
+---
Sub-Model Usage
| Model | Input | Output | Cache Read | Cost |
|---|---|---|---|---|
| claude-haiku-4-5-20251001 | 23 | 8.2K | 76.9K | $0.08 |
BSCS Bench