COMP 3250 B – Design and Analysis of Algorithms (Advanced Class)
Assignment 1
                                                              Due: 9:30 AM, Feb 20 (Monday), 2017
Warm-up (for your own practice; seek help from the tutor if necessary)
  1. Solve the recurrence T (n) = T (n/9) + T (2n/3) + 76n.
                                                      √     √
  2. Show that the solution to the recurrence T (n) = nT ( n) + n is O(n log log n).
  3. You are given n objects X1 , X2 , . . . , Xn . It takes constant time to determine whether any two
     objects Xi and Xj are the same. Assume n is a power of 2. Consider the following linear time
     algorithm to check whether more than half of the objects are indeed the same. Partition the
     n objects into n/2 groups of two objects. If a group contains two different objects, discard
     both objects; otherwise, retain one of them. Solve the problem for the remaining objects
     recursively.
     Does the above algorithm really run in linear time? Given n objects in which more than half
     of the objects are indeed the same, does the algorithm will always return the answer yes. Is
     the algorithm correct in the general sense? If not, how would you fix it?
  4. Suppose that you have a ”black-box” worst-case linear-time median subroutine. Show who
     to make use of this black-box subroutine to solve the problem of selecting the k-th smallest
     element for an arbitrary k.
  5. (Data Structures) A 4-ary heap is like a binary heap, but (with one possible exception) nonleaf
     nodes have 4 children instead of 2 children. Under what situation a 4-ary heap would be
     preferred to a binary heap?
 Problems Problems 1, 4 and 5 each carry a weight of 20%. Problem 2 carries 15% and Problem 3
25%. If you can solve Problem 3, you can attempt the bonus problem, which gives extra 5%. Please
make your answers precise and concise.
  1. You are given two sorted lists of size m and n. Give an O(log m + log n) time algorithm for
     computing the median in the union of the two lists.
  2. Recall that the multiplication of two polynomials can be computed in O(n log n) time using
     the FFT algorithm. Show to make use of this result to multiply two large integers with n bits
     in O(n log n) time.
  3. You are given the x- and y-coordinates of n points on a 2-d plane, p1 = (x1 , y1 ), · · · , pn =
                                                                           P
     (xn , yn ). Each point pi carries a positive weights wi such that 1≤i≤n wi = 1. Consider a
     horizontal line L with y-coordinate equal to y. Define the weighted distance between L and
     point pi to be wi |y − yi |. Give a linear-time algorithm to find a horizontal line L such that the
     total weighted distance between L and the n points is minimized. Prove that your algorithm
     is correct.
     Bonus problem (extra 5%): Given a point P = (x, y), define he weighted distance between P
     and point pi to be wi (|y − yi | + |x − xi |). Give a linear-time algorithm to find a point P such
     that the total weighted distance between P and the n points is minimized.
  4. Let X = {x1 , x2 , · · · , xn } be a set of n Boolean variables. Note that each xi can be assigned
     either true or false. We denote x̂i as the complement of xi . Consider any integer m ≤ n and any
     set F = {A1 , A2 , · · · , Am }, where each Ai contains some variables and/or their complements.
     It is assumed that each Ai has at most three elements. For example, A1 = {x2 , x7 , xˆ8 }. Given
                                                  1
   F , we are interested to find an assignment of truth values to each variable of X such that every
   Ai contains at least one element which is true. For example, A1 = {x1 , xˆ2 }, A2 = {xˆ1 , x3 },
   A3 = {xˆ3 , x2 }. Setting x2 = false, x3 = false and x1 = false will make every Ai to have at
   least one element being true.
   In general, such an assignment may not exist, and no polynomial time algorithm for finding
   such an assignment has been known. Thus we consider a restriction to the problem: we assume
   that for any two variables (or their complements) xk and xj in the same set Ai , |k − j| ≤ 5.
   For example, it is not allowed to have Ai = x1 ∨ xˆ2 ∨ xˆ6 .
   Show that with these restriction, a divide-and-conquer algorithm can solve the above assign-
   ment problem in O(nc ) time for some constant c. [Hint. For 1 ≤ j ≤ k ≤ n, let F (j, k) be the
                                                                                             ˆ , · · · , xk , xˆk .
   subset of F containing only those Ai ’s whose elemebts are chosen from xj , xˆj , xj+1 , xj+1
   It is natural to consider three subproblems, F (1, n/2), F (n/2 + 1, n), and F ∗, where F ∗ con-
   tains all the Ai ’s that has at least one variable with index ≤ n/2 and one variable with index
   > n/2.]
5. Let M be an n × n matrix containing distinct real numbers. You can assume that n is a
   power of 2. An entry M [i, j] is said to be a local minimum if it is smaller than its horizontal
   and vertical neighbors. Furthermore, M [i, j] is called the real minimum if it is smaller than
   all other entries in M .
   Argue that the real minimum of M cannot be found in O(n) time. Then show that a local
   minimum can be found in O(n) time using a divide-and-conquer algorithm. Justify your
   solution.
6. Do you collaborate with any students in this course? If so, write down his name. Please be
   reminded that you must write up the solution alone. How many hours have you spent in this
   assignment? Please rate the difficulty of this assignment (1 to 5, 1 means too easy, 3 means
   okay, and 5 for extremely difficult).