18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Divide and Conquer<br />

Next: Fast Exponentiation Up: Breaking Problems Down Previous: War Story: Text Compression<br />

Divide and Conquer<br />

Divide and conquer was a successful military strategy long before it became an algorithm design<br />

paradigm. Generals observed that it was easier to defeat one army of 50,000 men, followed by another<br />

army of 50,000 men than it was to beat a single 100,000 man army. Thus the wise general would attack<br />

so as to divide the enemy army into two forces and then mop up one after the other.<br />

To use divide and conquer as an algorithm design technique, we must divide the problem into two<br />

smaller subproblems, solve each of them recursively, and then meld the two partial solutions into one<br />

solution to the full problem. Whenever the merging takes less time than solving the two subproblems, we<br />

get an efficient algorithm. Mergesort, discussed in Section , is the classic example of a divide-andconquer<br />

algorithm. It takes only linear time to merge two sorted lists of n/2 elements each of which was<br />

obtained in time.<br />

Divide and conquer is a design technique with many important algorithms to its credit, including<br />

mergesort, the fast Fourier transform, and Strassen's matrix multiplication algorithm. However, with the<br />

exception of binary search, I find it to be a difficult technique to apply in practice. <strong>The</strong>refore, the<br />

examples below will illustrate binary search and its variants, which yield simple algorithms to solve a<br />

surprisingly wide range of problems.<br />

● Fast Exponentiation<br />

● Binary Search<br />

● Square and Other Roots<br />

<strong>Algorithm</strong>s<br />

file:///E|/BOOK/BOOK2/NODE53.HTM (1 of 2) [19/1/2003 1:28:56]

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

Saved successfully!

Ooh no, something went wrong!