CS 4102, Algorithms
Problems Set #2, Spring 2010

Updated: Feb. 11, 2010, 1:15pm


To turn in:

Turn in solutions to these problems.  (Below they're marked with this image: Submit-Button)

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:

  1. There are many problems here. There are five to submit.  For the ones that are not required to be submitted, you can collaborate or discuss in any way with as many people as you wish.
  2. For the required problems that you submit:
    1. You may submit your work on your own or with a partner.  If you work with a partner, you must pledge that both people did approximately equal amounts of work on the required problems.
    2. If you work alone, you can discuss how to solve the problems with one other pair or one other single person.  List the names of these people on your submission.
    3. If you don't understand the question or what it is asking, you can get clarification from other students only if this does not involve saying how the problem might be solved in any way.  If in doubt, don't discuss and see the TA or the instructor.
  3. Fill out the cover sheet on the website and submit it with your homework.

Problems from Algorithms textbook, Section 2.3, pp. 51-54
(Solutions for problems marked "S" begin on page 656)
Problem Tree1: Submit-ButtonSubmit-ButtonFor HW2, turn in both parts (a) and (b) -- this is what I intended from the beginning!

(a) Draw the decision tree for the binary search algorithm with n=17.
(b) Using the tree, calculate the value of A(n) assuming that the target is in the list.  Compare this value to W(n) where n=17.


Problem DC1: Submit-Button

Use very clear pseudo-code or Python and write a divide and conquer algorithm to find both the maximum and the minimum values in an array. See the slides "Recurrences, Divide and Conquer", slide 17, for more details. (We talked about this in class, BTW.) Also, give the recurrence relation for the wost-case number of comparisons and solve this equation. In terms of number of comparisons, how does this compare to the more obvious solution of just linearly searching the array looking for both the largest and smallest element?


Problem Rec1: Recurrence Relations: 

Can you use a theorem to find the order class for these? Or, can you successfully use the iteration method? Assume T(1) = 1 when you want to solve these with the iteration method.

  1. T(n) = T(n/2) + lg n  Submit-Button Submit-ButtonFor HW2, use the iteration method to solve this!
  2. T(n) = T(n/2) + n
  3. T(n) = 2T(n/2) + n (kind of like mergesort)
  4. T(n) = 2T(n/2) + n lg n
  5. T(n) = T(n-1) + n (kind of like like selection sort)
  6. T(n) = T(n/2) + 1 (like binary search)
  7. T(n) = 2T(n-1) + 1 (like Towers of Hanoi)


Problem Rec2: Submit-ButtonSubmit-ButtonNot required to turn this in for HW2.  Turn it when you turn in HW3.  (The grade will count as part of HW2.)

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 Sort1:

Explain convincingly why mergesort is a stable sort.  Explain a small change to the algorithm that would make mergesort unstable but still a correct sorting algorithm.


Problem Sort2:

Explain why mergesort illustrates a design tradeoff in terms of its time and space complexity.