0% found this document useful (0 votes)
17 views

homework4w24

The document outlines the homework assignment for CSE 202, focusing on divide and conquer algorithms, with various ungraded and graded problems. It includes recurrence relations, binary tree algorithms, Fibonacci number identities, multi-select problems, and polynomial multiplication algorithms. The assignment is due on March 1, 2024, and consists of both theoretical and practical components requiring proofs, algorithm design, and time analysis.

Uploaded by

jsliang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

homework4w24

The document outlines the homework assignment for CSE 202, focusing on divide and conquer algorithms, with various ungraded and graded problems. It includes recurrence relations, binary tree algorithms, Fibonacci number identities, multi-select problems, and polynomial multiplication algorithms. The assignment is due on March 1, 2024, and consists of both theoretical and practical components requiring proofs, algorithm design, and time analysis.

Uploaded by

jsliang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSE 202 Homework 4

Winter, 2024
Divide and conquer
Due Friday, March 1 , 11:59 PM

Ungraded problems

1. For each of the following recurrence relations ( 6 points each),


1 point Say whether the Master Theorem applies
3 points If the Master Theorem applies, say what the relevant a, b and
d values are.
1 point If the Master Theorem applies, show which case we are in.
1 point If the Master Theorem applies, use it to solve the recurrence up
to order.
5 points If the Master Theorem does not apply, use unravelling to solve
the recurrence up to order.

(a) (a) T (n) = 8T (n/2) + cn, T (1) = c


(b) (b) T (n) = 4T (n − 2) + 1, T (1) = 1
(c) (c) T (n) = 3T (n/3) + cn1/2 , T (1) = c
(d) (d) T (n) = T (n − 1) + c, T (1) = c.
(e) (e) T (n) = 4T (n/8) + n2 , T (1) = c

2. Consider the following problem: You are given a pointer to the root r of
a complete, balanced binary tree, (meaning the sizes of left and right sub-
trees are equal) and where each vertex v has pointers v.lc and v.rc to the
left and right child, and a value V al(v) If v.lc or v.rc have the value NIL
it indicates that v has no child of that type. You wish to find a connected
sub-tree containing the root, that maximizes the total sum of values of
vertices in the sub-tree. (Since some vertices might have negative values,
it might not be optimal to include all of them) Your algorithm can return
just the maximum possible sum, not the sub-tree.

3 points Give an example of an instance of the problem for a depth 3 tree


where the optimal sum does not include the left child of the root.
3 points Give an example of an instance of the problem for a depth 3 tree
where the optimal sum includes the left child of the root, even though
its value is negative.
6 points Give a general rule for when we should include a child of the root,
based on the best solution for that root.
8 points Give a recursive algorithm based on the rule in the previous part.

1
5 points Give a recurrence for the time your algorithm takes.
5 points Use the Master theorem to give a time analysis for your algorithm.
5 points Extend your time analysis to the case when the tree is an arbitrary
binary tree, not necessarily balanced.

3. Give an efficient algorithm to convert decimal integers into binary integers.


You can use algorithms from class and the textbook as sub-routines. Give
a proof of correctness and time analysis for your algorithm.
4. Remember that the Fibonnaci numbers are defined by F ib(0) = 1, F ib(1) =
1 and F ib(n) = F ib(n − 1) + F ib(n − 2) for n ≥ 2.
Here are two identities about the Fibonacci numbers that we discovered
a few years ago in CSE 21.
(a) F ib(2n) = (F ib(n))2 + F ib(n − 1)2 .
(b) F ib(2n + 1) = F ib(n)F ib(n + 1) + F ib(n − 1) ∗ F ib(n) = F ib(n)2 +
2F ib(n)F ib(n − 1)

5 points Prove these identities .


20 points Use these identities above to give an efficient algorithm for
computing F ib(n). You can use any algorithm from class as a sub-
routine. Note that you cannot assume arithmetic operations are con-
stant time, since F ib(n) is Θ(n) bits in binary. However, you can use
algorithms for arithmetic from class and their time analyses without
needing to reprove them or give pseudo-code. (10 points correct al-
gorithm and brief correctness argument using the identity; 10 points
time analysis,including a recurrence for the time and its solution.)

5. The multi-select problem generalizes the Select problem by asking to, given
an unsorted array A[1..n] of distinct integers, and k ranks 1 ≤ r1 < r2 <
.. < rk ≤ n , ouput the r1 ’st largest, r2 ’nd largest,...and rk ’th largest
elements in the array. Show how, using linear-time select as a subroutine,
we can solve multi-select in O(n log k) time.
6. Give matching (up to constant factors) upper and lower bounds in terms
of the array size n and the number of processors P on the parallel time
complexity in the Valiant model of deciding whether an element x is in a
sorted array y1 ≤ y2 ≤ y3 ≤ ... ≤ yn .

Graded Problems

1. Define a sequence of numbers T ri(n) by T ri(0) = 0, T ri(1) = 1, T ri(2) =


2 and T ri(n) = T ri(n − 1) + T ri(n − 2) + T ri(n − 3) for n ≥ 3. Consider a
3 × 3 matrix M whose first row is (0, 1, 0) second row (0, 0, 1) and bottom
row is (1, 1, 1).

2
(a) Show that M (T ri(n−2), T ri(n−1), T ri(n))+ = (T ri(n−1), T ri(n), T ri(n+
1))+ where v + is the transpose (to make the dimensions work) and
n ≥ 2. (2 points)
(b) From this, prove that M n (0, 1, 2)+ = (T rin , T rin+1 , T rin+2 )+ (3
points).
(c) Use the above formula to design a divide-and-conquer based algo-
rithm that given n , computes T rin . (10 points)
(d) Give a time analysis of your algorithm if we view arithmetic opera-
tions as constant time. (5 points)
(e) Give a time analysis of your algorithm in terms of bit-operations if
we use grade-school arithmetic. (5 points)
(f) Give a time analysis of your algorithm in terms of bit operations if
we use an O(nlog 2 n) F F T based method to perform integer multi-
plication. (5 points)
2. One vector (x1 , ..xd ) dominates another vector (y1 ., , , yd ) if xi ≥ yi for
all 1 ≤ i ≤ d. In the dominating vector problem, you are given two sets
of d dimensional vectors, X and Y and want to determine whether there
is any x ∈ X and any y ∈ Y so that x dominates y. Give as efficient
an algorithm as you can for the dominating vector problem for any fixed
constant dimension d. (Hint: First try d = 2. Use the result for dimension
d − 1 as a sub-routine in your algorithm for dimension d.)
15 points correctness, 5 points short proof of correctness (only requires a
paragraph or so), 20 points for time analysis and efficiency. There will be
no points for efficiency for O(n2 ) algorithms, where n = |X| + |Y | is the
total number of vectors.
3. Implement two algorithms for multiplying polynomials of degree n − 1,
given as the arrays a[0..n − 1] and b[0..n − 1] of co-efficients. The first
should be a naive FOIL based O(n2 ) algorithm. The second should be a
O(nlog 3 ) divide-and-conquer algorithm based on Karatsuba’s algorithm,
e.g. from the first problem above. Then consider mixes that use the
divide-and-conquer recursion when the input size is at least a threshold
n0 , and uses the brute force algorithm if the input is smaller than n0 .
(Note that this will also apply to recursive calls, so it could change the
time even for sizes n > n0 .)
Try this with a variety of thresholds n0 , and plot the performance of each
version (on a log-log scale). From this data, say whether it is a good idea
to use such a threshold in an implementation and give a good value for
the threshold if so.
(10 points, clear description of experiment performed; 10 points, clear
presentation of data obtained; 10 points, conclusions drawn from the ex-
periment.)

You might also like