You are on page 1of 2

CS513 Spring 2020 Design and Analysis of Data Structures and

Algorithms
Jie Gao∗

February 23, 2020

Due February 9th 9pm. Each problem, unless specified otherwise, has a maximum of 10 points.
Avoid too many details. A succinct and clean proof is the best. You may use the algorithms we
covered in class without referring to the details.
The assignment has two parts. The practice problems are meant for you to practice on your own
and there is no need to submit your solution. The assignment problems need to be submitted to
canvas.

Homework 1
Practice Problems
1. Prove or disprove the following claims.

(a) 2blg nc = Θ(2dlg ne ).


blg lg nc dlg lg ne
(b) 22 = Θ(22 ).

2. List the following functions in increasing asymptotic order. Between each adjacent functions
in your list, indicate whether they are asymptotically equivalent (f (n) ∈ Θ(g(n)), you may use
the notation that f (n) ≡ g(n)) or if one is strictly less than the other (f (n) ∈ o(g(n)) and use
the notation that f (n) ≺ g(n)).

5n3 + log n 2

n 3 n/2 2 n/3 lg n
lg n 2
Pn 77
ln n 2 min{n , 1045n} i nln 4
2 2 2 √
i=1
bn /45c dn /45e n /45 lg n lg lg√n
Pn Pn 2
Pn 2 4
i=1 1/i i=1 1/i i=1 (i + 5i)/(6i + 7) ln(n!) (lg n) lg n

3. Solving recurrences. Find the asymptotic order of the following recurrence, represented in
big-Θ notation.

(a) A(n) = 4A(bn/2c + 5) + n2


(b) B(n) = B(n − 4) + 1/n + 5/(n2 + 6) + 7n2 /(3n3 + 8)
√ √
(c) C(n) = n + 2 nC( n) Hint: take H(n) = C(n) + n.

Department of Computer Science, Rutgers University, jg1555@cs.rutgers.edu.

1
Assignment Problems
1. Previous large element. Given a sequence of n numbers, {a1 , a2 , · · · , an }, for each element
ai , 1 ≤ i ≤ n, find the index of the rightmost element inside {a1 , a2 , · · · , ai−1 } whose value is
strictly larger than ai . If no element is larger than ai then output 0. In other words, find for
each i
pi = max{j|0 ≤ j < i, aj > ai },
in which assume a0 = ∞.
Find an O(n) algorithm. Remember that you need to prove the correctness of the algorithm.
2. Merge k sorted lists. Give an O(n log k) time algorithm to merge k sorted lists into one
sorted list, where n is the total number of elements in all the lists.
3. Insertion sort is a sorting algorithm in which we sequentially examine the elements in the input
and place each new element into the right position among the elements already examined. In
particular, the ith element u is compared with each element in front of it and if u is smaller,
swap the two elements and continue. Insertion sort has worst case running time of Θ(n2 ). For
more details, see CLRS Chapter 2.
In the following algorithm, we combine selection sort with quicksort. When quicksort is called
on a subarray with fewer than k elements, let’s simply return without sorting the subarray.
After the top-level call to quicksort is done, we run insertion sort on the entire array. Show that
this algorithm has running time O(nk + n log(n/k)) expected time. How should k be picked to
minimize the running time?
4. Square of a matrix. The square of a matrix A is its product with itself, AA.
(a) Show that 5 multiplications are sufficient to compute the square of a 2 × 2 matrix. (5pts)
aa, bc, dd, (a + d)b, (a + d)c.
(b) What is wrong with the following algorithm for computing the square of an n × n matrix?
(5pts)
Use a divide-and-conquer approach as in Strassen’s algorithm, except that instead
of getting 7 subproblems of size n = 2, we now get 5 subproblems of size n = 2
thanks to part (a). Using the same analysis as in Strassen’s algorithm, we can
conclude that the algorithm runs in time O(nlog2 5 ).
The problem is that the subproblem may not be square of a matrix.
(c) In fact, squaring matrices is no easier than matrix multiplication. In this part, you will
show that if n × n matrices can be squared in time S(n) = O(nc ), c ≥ 2, then any two
n × n matrices can be multiplied in time O(nc ). (5pts)
i. Given two n × n matrices A and B, show that the matrix AB + BA can be computed
in time 3S(n) + O(n2 ).
ii. Given two n × n matrices X and Y , define the 2n × 2n matrices A and B as follows:
   
X 0 0 Y
A= ;B=
0 0 0 0
What is AB + BA, in terms of X and Y ?
iii. Using (i) and (ii), argue that the product XY can be computed in time 3S(2n)+O(n2 ).
Conclude that matrix multiplication takes time O(nc ).

You might also like