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: )
- Algorithms textbook: p. 170, Problem 9
- Problem Tree1.a,
DC1, Rec1.a, Rec2
- For
Tree1, turn in both parts (a) and (b) -- this is what I intended from
the beginning!
- For
Rec1.a, use the iteration method to solve this!
- For
Rec2, you're not required to turn this in for HW2. Turn it when
you turn in HW3. (The grade will count as part of HW2.)
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:
- 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.
- For the required problems that you submit:
- 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.
- 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.
- 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.
- 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)
- Section 4.1, pp. 169f. Problems 2, 9 , 19, 20S
- Section 5.1, pp. 217d. Problem 5S
Problem Tree1: For 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:
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.
- T(n) = T(n/2) + lg n For HW2,
use the iteration method to solve this!
- T(n) = T(n/2) + n
- T(n) = 2T(n/2) + n (kind of like mergesort)
- T(n) = 2T(n/2) + n lg n
- T(n) = T(n-1) + n (kind of like like selection sort)
- T(n) = T(n/2) + 1 (like binary search)
- T(n) = 2T(n-1) + 1 (like Towers of Hanoi)
Problem Rec2: Not
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.