09.09.2014 Views

algorithms

algorithms

algorithms

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 2.3 Each problem of size n is divided into a subproblems of size n/b.<br />

Size n<br />

Branching factor a<br />

Size n/b<br />

Size n/b 2<br />

Depth<br />

log b n<br />

Size 1<br />

Width a log b n = n log b a<br />

subproblems, each of size n/b k (Figure 2.3). The total work done at this level is<br />

a k × O<br />

( n<br />

b k ) d<br />

= O(n d ) ×<br />

( a<br />

b d ) k<br />

.<br />

As k goes from 0 (the root) to log b n (the leaves), these numbers form a geometric series with<br />

ratio a/b d . Finding the sum of such a series in big-O notation is easy (Exercise 0.2), and comes<br />

down to three cases.<br />

1. The ratio is less than 1.<br />

Then the series is decreasing, and its sum is just given by its first term, O(n d ).<br />

2. The ratio is greater than 1.<br />

The series is increasing and its sum is given by its last term, O(n log b a ):<br />

n d ( a<br />

b d ) logb n<br />

3. The ratio is exactly 1.<br />

(<br />

= n<br />

d a<br />

log b n<br />

)<br />

(b log b n ) d<br />

= a log b n = a (log a n)(log b a) = n log b a .<br />

In this case all O(log n) terms of the series are equal to O(n d ).<br />

These cases translate directly into the three contingencies in the theorem statement.<br />

55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!