Week 3 - Divide and Conquer
Assignment - Due 10/13/2018
Credit: source code of questions are from walkccc.
4.1-1
What does \text{FIND-MAXIMUM-SUBARRAY} return when all elements of A are negative?
4.1-2
Write pseudocode for the brute-force method of solving the maximum-subarray problem. Your procedure should run in \Theta(n^2) time.
4.1-3
Implement both the brute-force and recursive algorithms for the maximum-subarray problem on your own computer. What problem size n_0 gives the crossover point at which the recursive algorithm beats the brute-force algorithm? Then, change the base case of the recursive algorithm to use the brute-force algorithm whenever the problem size is less than n_0. Does that change the crossover point?
4.2-1
Use Strassen's algorithm to compute the matrix product
\begin{pmatrix} 1 & 2 \\\\ 7 & 5 \end{pmatrix} \begin{pmatrix} 6 & 8 \\\\ 4 & 2 \end{pmatrix} .Show your work.
4.2-2
Write pseudocode for Strassen's algorithm.
4.2-3
How would you modify Strassen's algorithm to multiply n \times n matrices in which n is not an exact power of 2? Show that the resulting algorithm runs in time \Theta(n^{\lg7}).
4.3-1
Show that the solution of T(n) = T(n - 1) + n is O(n^2).
Assume T(n) = O(n^2), then \exists{c > 0} letting T(n) \leq cn^2:
So, when c \geq 1, n_0 = 1, for all n \geq n_0 the inequality holds, which is
4.3-2
Show that the solution of T(n) = T(\lceil n / 2 \rceil) + 1 is O(\lg n).
Assume T(n) = O(\lg n), then \exists{c > 0}, letting T(n) \leq c\lg(n-2):
So, when c \geq 1, n_0 = 1, for all n \geq n_0 the inequality holds, which is
4.3-3
We saw that the solution of T(n) = 2T(\lfloor n / 2 \rfloor) + n is O(n\lg n). Show that the solution of this recurrence is also \Omega(n\lg n). Conclude that the solution is \Theta(n\lg n).
Assume T(n) = \Theta(n\lg{n}), then \exists{c > 0, d > 0}, letting c(n+2)\lg{(n+2)} \leq T(n) \leq dn\lg{n}:
So, when 0 < c \leq 1, d \geq 1, n_0 = \dfrac{2c}{1-c}, for all n \geq n_0 the inequality holds, which is
4.3-5
Show that \Theta(n\lg n) is the solution to the "exact" recurrence \text{(4.3)} for merge sort.
The exact recurrence of Merge-Sort is
So assume T(n) = \Theta(n\lg{n}), \exists c > 0, \exists d > 0, \exists e > 0, \exists f > 0 letting
such that:
So, when 0 < c < d, 0 < f < e, n_0 = \max(\dfrac{2c}{d-c}, \dfrac{2e}{e-f}), for all n \geq n_0 the inequality holds, which is