11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

528 Chap. 16 P<strong>at</strong>terns of <strong>Algorithm</strong>slogarithm of the sum is read off another logarithmic scale. The part normally consideredexpensive (taking logarithms <strong>and</strong> anti-logarithms) is cheap because it is aphysical part of the slide rule. Thus, the entire multiplic<strong>at</strong>ion process can be donecheaply via a reduction to addition. In the days before electronic calcul<strong>at</strong>ors, sliderules were routinely used by scientists <strong>and</strong> engineers to do basic calcul<strong>at</strong>ions of thisn<strong>at</strong>ure.Now consider the problem of multiplying polynomials. A vector a of n valuescan uniquely represent a polynomial of degree n − 1, expressed asn−1∑P a (x) = a i x i .Altern<strong>at</strong>ively, a polynomial can be uniquely represented by a list of its values <strong>at</strong>n distinct points. Finding the value for a polynomial <strong>at</strong> a given point is calledevalu<strong>at</strong>ion. Finding the coefficients for the polynomial given the values <strong>at</strong> n pointsis called interpol<strong>at</strong>ion.To multiply two n − 1-degree polynomials A <strong>and</strong> B normally takes Θ(n 2 ) coefficientmultiplic<strong>at</strong>ions. However, if we evalu<strong>at</strong>e both polynomials (<strong>at</strong> the samepoints), we can simply multiply the corresponding pairs of values to get the correspondingvalues for polynomial AB.Example 16.5 Polynomial A: x 2 + 1.Polynomial B: 2x 2 − x + 1.Polynomial AB: 2x 4 − x 3 + 3x 2 − x + 1.When we multiply the evalu<strong>at</strong>ions of A <strong>and</strong> B <strong>at</strong> points 0, 1, <strong>and</strong> -1, weget the following results.i=0AB(−1) = (2)(4) = 8AB(0) = (1)(1) = 1AB(1) = (2)(2) = 4These results are the same as when we evalu<strong>at</strong>e polynomial AB <strong>at</strong> thesepoints.Note th<strong>at</strong> evalu<strong>at</strong>ing any polynomial <strong>at</strong> 0 is easy. If we evalu<strong>at</strong>e <strong>at</strong> 1 <strong>and</strong> -1, we can share a lot of the work between the two evalu<strong>at</strong>ions. But we wouldneed five points to nail down polynomial AB, since it is a degree-4 polynomial.Fortun<strong>at</strong>ely, we can speed processing for any pair of values c <strong>and</strong> −c. This seemsto indic<strong>at</strong>e some promising ways to speed up the process of evalu<strong>at</strong>ing polynomials.But, evalu<strong>at</strong>ing two points in roughly the same time as evalu<strong>at</strong>ing one point onlyspeeds the process by a constant factor. Is there some way to generalized these

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

Saved successfully!

Ooh no, something went wrong!