Homework #4

# problems
1 CLRS Exercise 9.3-7 on page 223
Describe an O(n)-time algorithm that, given a set S of n distinct numbers and a positive integer kn, determines the k numbers in S that are closest to the median of S.
2 CLRS Exercise 4.5-1 on page 96
Use the master method to give tight asymptotic bounds for the following recurrences.
a. T(n) = 2T(n/4) + 1
b. T(n) = 2T(n/4) + √n
c. T(n) = 2T(n/4) + n
d. T(n) = 2T(n/4) + n2
3 CLRS Problem 4-1 on page 107
Give asymptotic upper and lower bounds for T(n) in each of the following recurrences. Assume that T(n) is constant for n ≤ 2. Make your bounds as tight as possible, and justify your answers.
  1. T(n) = 2T(n/2) + n4
  2. T(n) = T(7n/10) + n
  3. T(n) = 16T(n/4) + n2
  4. T(n) = 7T(n/3) + n2
  5. T(n) = 7T(n/2) + n2
  6. T(n) = 2T(n/4) + √n
  7. T(n) = T(n-2) + n2
4 DPV Exercise 2.4 on page 71
Suppose you are choosing between the following three algorithms:
  • Algorithm A solves problems by dividing them into five subproblems of half the size, recursively solving each subproblem, and then combining the solutions in linear time.
  • Algorithm B solves problems of size n by recursively solving two subproblems of size n-1 and then combining the solutions in constant time.
  • Algorithm C solves problems of size n by dividing them into nine subproblems of size n/3, recursively solving each subproblem, and then combining the solutions in O(n2) time.
What are the running times of each of these algorithms (in big-O notation), and which would you choose?
5 The Strahler number of a binary tree is defined as follows:
An empty tree has Strahler number 0.  If the binary tree T has subtrees TL and TR, the Strahler number S(T) of T is defined by

max{ S(TL),S(TR) },         if S(TL) ≠ S(TR)

S(TL) + 1,                 otherwise

Give a recursive algorithm to find the Strahler number of a binary tree.

# hard problems
6 CLRS Problem 4-3 on page 108
Give asymptotic upper and lower bounds for T(n) in each of the following recurrences. Assume that T(n) is constant for sufficiently small n. Make your bounds as tight as possible, and justify your answers.
  1. T(n) = 4T(n/3) + n lg n
  2. T(n) = 3T(n/3) + n / lg n
  3. T(n) = 4T(n/2) + n2n
  4. T(n) = 3T(n/3-2) + n/2
  5. T(n) = 2T(n/2) + n / lg n
  6. T(n) = T(n/2) + T(n/4) + T(n/8) + n
  7. T(n) = T(n-1) + 1/n
  8. T(n) = T(n-1) + lg n
  9. T(n) = T(n-2) + 1 / lg n
  10. T(n) = √n T(√n) + n


Last modified: Dec 15, 2019