Basis: n = 2. T(2) = 2c + T(1) = 3c ≤ (6 ln 2)c [ln 2 = 0.69]
Consider n ≥ 3, and assume true for (n-1).
T(n) = cn + (2/n) ∑j = 1 to n-1 T(j) to be shown ≤ 2c(n+1) ln n
T(n-1) = c(n-1) + (2/(n-1)) ∑j = 1 to n-2 T(j) ≤ 2cn ln (n-1)
T(n) - ((n-1)/n)T(n-1) = c[n - (n-1)2/n] + (2/n)T(n-1)
Note that n - (n-1)2/n = 2 - 1/n
T(n) = (2 - 1/n)c + ((n+1)/n)T(n-1) ≤ (2 - 1/n)c + 2c(n+1) ln(n-1)
Note: (d/dx)ln x = 1/x, 1/n ≤ ln n - ln(n-1) ≤ 1/(n-1), ln(n-1) ≤ ln n - (1/n)
T(n) ≤
(2 - 1/n)c
+ 2c(n+1)(ln n - 1/n)
= 2c(n+1)ln n
+ (2 - 1/n)c
- 2c(n+1)/n
< 2c(n+1)ln n
To multiply two n×n matrices normally takes n scalar multiplications and n-1 scalar additions for each of n2 elements, for a total of Θ(n3) scalar multiplications and Θ(n3) scalar additions.
Strassen, using divide-and-conquer, was able to do better! He found a way of multiplying two n×n matrices using 7 scalar multiplications and 18 scalar additions instead of the normal 8 scalar multiplications and 4 scalar additions.
This might not seem like great progress, but look:
T(n) = 7T(n/2) + 18(n/2)2
It is easy to show that, for some constant k, T(n) ≤ knlg 7 = O(n2.81).
We express the outline of a single building as a triple {L,H,R}, where L,R are the left and right extents of the building and H is its height.
Example: We are given 4 buildings with outlines
| {1,11,5} |
| {2,6,7} |
| {3,13,9} |
| {12,7,16} |
The outline of the collection of these 4 buildings is
How to solve this problem?
One solution is to add building one at a time. It takes O(n) time to find where the left and right ends of the new building are located relative to the buildings already in-place and to adjust the heights in between to become the maximum of {what was there before, the height of the new building}. The total time complexity to handle n buildings will be O(n2).
A faster solution uses divide-and-conquer:
T(n) = 2T(n/2) + O(n)
→ T(n) = O(n lg n)