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

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

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

540 Chap. 17 Limits to Comput<strong>at</strong>ionSORTING:Integer Array ATransform 1Integers0 to n−1IntegerArray APAIRINGArray of PairsTransform 2SortedInteger ArrayFigure 17.3diagram.A reduction of SORTING to PAIRING shown as a “blackbox”is multiplied against each digit of the second, this algorithm requires Θ(n 2 ) time.Asymptotically faster (but more complic<strong>at</strong>ed) algorithms are known, but none is sofast as to be in O(n).Next we ask the question: Is squaring an n-digit number as difficult as multiplyingtwo n-digit numbers? We might hope th<strong>at</strong> something about this special casewill allow for a faster algorithm than is required by the more general multiplic<strong>at</strong>ionproblem. However, a simple reduction proof serves to show th<strong>at</strong> squaring is “ashard” as multiplying.The key to the reduction is the following formula:X × Y = (X + Y )2 − (X − Y ) 2.4The significance of this formula is th<strong>at</strong> it allows us to convert an arbitrary instanceof multiplic<strong>at</strong>ion to a series of oper<strong>at</strong>ions involving three addition/subtractions(each of which can be done in linear time), two squarings, <strong>and</strong> a division by 4.Note th<strong>at</strong> the division by 4 can be done in linear time (simply convert to binary,shift right by two digits, <strong>and</strong> convert back).This reduction shows th<strong>at</strong> if a linear time algorithm for squaring can be found,it can be used to construct a linear time algorithm for multiplic<strong>at</strong>ion.

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

Saved successfully!

Ooh no, something went wrong!