CS 432, Algorithms
Problem Set #2, Fall 2005


To turn in:

Turn in solutions to the four problems below.
Important: Put the answer to each question on a separate sheet of paper (or one problem on front and another on the back). This is to make grading easier for us.

Collaboration Rules for This Assignment:

You may talk about the problems with other students in the course and TAs, or you can work alone. If you talk with or collaborate with other students, you must list their names at the first page of your paper. (Failure to do so violates the collaboration policy for CS432.) If you work alone, write a pledge that you worked alone without collaboration on the assignment.

If you collobarate with other students, a group of three students (and no more) may agree to turn in a group write-up of the solutions. List all group members on the paper, and pledge that all members made a reasonable contribution to working out the solutions. However, any of the group members may choose to turn in an individual write-up of the solutions. If you choose to do this, you cannot not simply copy all or part of another group member's write-up. (We will investigate this if we observe it.) You should still list your collaborators on the first page of your paper.

The goal of collaboration among students is simple. you can help each other learn. If what you do for another student simply lets them turn in the assignment without helping them learn in the process, this is not acceptable.


Problem Rec1) Use the either the Main Theorem or Master Theorem to give the order-class for each of the following recurrences. If you can't use either one of the theorems for a problem, just write "not applicable" and explain why.

(A) T(n) = 2T(n/2) + n

(B) T(n) = 2T(n/4) + n lg n

(C) T(n) = T(n/2) + lg n

Problem DC1) Examine the code and explanation on pp. 229-231 for the divide-and-conquer solution for the closest-pair of points problems.

(A) Write a clear explanation about how the algorithm sorts the points "in the strip" by their y-coordinate. Your explanation should include anything you feel is odd, unclear, or incorrect about the code given in the textbook.

(B) Show how you would modify the code so that it does not do the unnecessary distance calculation for any point "in the strip" that is on the same side of the dividing line L as the current point v[k]. Also, state how this improves the order class of the algorithm's complexity.

Problem Sort1) Your friend Alex has learned about the median-of-three method for choosing the pivot element for quicksort. Alex claims that using this changes the order-class complexity of quicksort in the worst-case. You're not sure you agree.

(A) Write the recurrence relation for the worst-case performance for Quicksort with this enhancement. Assume you are using a partition algorithm that requires n-1 comparisons for a list of size n.

(B) Give a convincing argument either for or against Alex's claim.


Problem Sort2) (Make sure you answer contains all three parts labeled a, b and c below.)
Lomuto's partition algorithm (p. 245) and Hoare's partition algorithm (p. 269) both work in linear time in terms of number of comparisons. We could also count how often they swap elements. For each algorithm, (a) determine what a worst-case input would look like, and (b) give a formula for the number of element swaps it does in this case. (c) Compare the two algorithms and say which might be preferable if sort required swapping large data items.