

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


In these problems, you are not required to find c and n 0 and prove the result by induction. It is sufficient to give a proof that appeals to results in the chapter. For example, you can say, without further comment, “5n^2 + 7n ≤ O(n^2 )” or “
∑n j=1 j
(^3) = Θ(∫^ n 0 x
(^3) dx) = Θ(n (^4) )” or “a k-ary tree with height h has Θ(kh) leaves
and nodes” (k > 1). In fact, I’d prefer that you get some practice in this “bigger picture” way of thinking, and not always get bogged down with induction details.
Exercises CLRS 4.2-4 and CLRS 4.2-5 illustrate that, if we use a divide-and-conquer approach to a problem, it is typically better to divide the problem into nearly equal-sized subproblems. The above and the last example of CLRS Section 4.2 also illustrate that it is not necessary that the subproblems be exactly the same size. We now switch from analyzing to designing algorithms. Given a problem of size n, we will break it into two problems, of size a(n) and n − a(n), where a(n) is a “common” function satisfying 1 ≤ a(n) ≤ n/2. We assume the Divide and Recombine cost is linear, so we have recurrence
T (n) = T (a(n)) + T (n − a(n)) + cn.
All other things being equal, we’d want a(n) = n/2 to minimize T (n). But sometimes there is a separate (direct or indirect) cost involved in making a(n) exactly n/2 and it’s easier to choose other a()’s. Below we investigate which a()’s are acceptable while still meeting certain overall cost requirements. Problem:
Restrict attention to functions of the form nr^ (log(n))s, where r and s are constant real numbers, and you only need to find s up to 1, additively. That is, your answer should be numbers r and s with
nr^ (log(n))s^ ≤ a(n) ≤ nr^ (log(n))s+1.
(If you’ve already found exactly the right s, please turn it in, but don’t attempt this if you haven’t started.)
First we show that, if a(n) = n/ log(n), then the requirement T (n) ≤ O(n log^2 (n)) is satisfied. That is, T (n) ≤ O(n log^2 (n)). To do this, we show that the height of the recursion tree (longest path from root to leaf) is at most O(log^2 (n)). Each level of the recursion tree contributes at most cn, so the total cost is O(n log^2 (n)). Write b(n) = a(n)/n, so that b(n) = 1/ log(n). The recurrence becomes
T (n) = T (nb(n)) + T (n(1 − b(n))) + cn.
The longest path in the recurrence tree occurs along the n → n(1 − b(n)) split (the “right spine” of the tree). Along this path, let mi denote the size of the problem at depth i, so that mi+1 = mi(1 − b(mi)), i.e.,
m 0 = n m 1 = n(1 − b(m 0 )) = n(1 − b(n)) m 2 = n(1 − b(m 1 )) = n(1 − b(n(1 − b(n)))) .. .
We first consider i with n/ 2 ≤ mi ≤ n. Because
1 log(n)
= b(n) ≤ b(mi) ≤ b(n/2) =
log(n) − 1
log(n)
we get simplified expressions for mi, namely, mi(1 − 2 / log(n)) ≤ mi+1 ≤ mi(1 − 1 / log(n)), or solving the simple recurrence,
n(1 − 2 / log(n))i^ = m 0 (1 − 2 / log(n))i^ ≤ mi+1 ≤ m 0 (1 − 1 / log(n))i^ = n(1 − 1 / log(n))i.
Using the approximation 1 + x ≈ ex^ if |x| is small, we get mi = neΘ(i/^ log(n)). If mi is deepest, mi ≈ n/2, we need eΘ(i/^ log(n))^ ≈ 1 /2, which happens at i = Θ(log(n)). In particular, we need that there is some constant c 1 such that, for i ≥ c 1 log(n), we have mi ≤ n/2. By repeating the process on mi instead of m 0 = n, we get that, after log(mi) additional levels in the tree, the problem size drops by half again, to mi/ 2 ≤ n/4. After log(n) repetitions of n 7 → n/2, we have reduced the problem size to 1. Since all the mi’s are at most n, the length of this path is log^2 (n). This is what we needed to show. Next, we show that if T (n) = T (n/ log2+(n)) + T (n(1 − 1 / log2+(n))) + cn, then T (n) > ω(n log^2 (n)). Using an argument similar to the above, let mi be the size of the largest problem at depth i in the recursion tree. If mi ≈ n/2, then i ≥ Ω(log2+(n)), using an argument similar to the above. Each problem along the right spine at depth less than i has size at least n/2, which gives a total cost of Ω(n log2+(n)). Thus it follows that a(n) = n/ log(n) or faster growing gives T (n) ≤ O(n log^2 (n)) and a(n) = nlogs(n) for s < −2 gives T (n) > ω(n log^2 (n)). So r = 1 and − 2 ≤ s ≤ −1. Note: It is not necessarily the case that there is a slowest-growing function a(n) = nr^ logs(n) that
satisfies the requirement. There could be some s′^ such that n logs
′ (n) grows too slowly but, for any s > s′, the requirement is satisfied. For a simpler example of this phenomenon, suppose we insist that s = −3 and ask about r. We know that a(n) = n/ log^3 (n) will not satisfy the requirement but for any slower-growing function n^1 −/ log^3 (n), i.e., for any > 0, the requirement will be satisfied. In this case, s < −1 gives T (n) > ω(n log^2 (n)), so the answer is r = 1 and s = −1, i.e., a(n) = n/ log(n).