12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

Sec. 17.1 Reductions 565SORTING:Integer ArrayTransform 1Integers1 <strong>to</strong> nIntegerArrayPAIRINGArray of PairsTransform 2SortedInteger ArrayFigure 17.3 The reduction of SORTING <strong>to</strong> PAIRING shown as a “blackbox”diagram.Our next example of reduction concerns the multiplication of two n × n matrices.For this problem, we will assume that the values s<strong>to</strong>red in the matrices are simpleintegers <strong>and</strong> that multiplying two simple integers takes constant time (becausemultiplication of two int variables takes a fixed number of machine instructions).The st<strong>and</strong>ard algorithm for multiplying two matrices is <strong>to</strong> multiply each elemen<strong>to</strong>f the first matrix’s first row by the corresponding element of the second matrix’sfirst column, then adding the numbers. This takes Θ(n) time. Each of the n 2 elementsof the solution are computed in similar fashion, requiring a <strong>to</strong>tal of Θ(n 3 )time. Faster algorithms are known (see the discussion of Strassen’s <strong>Algorithm</strong> inSection 16.3.3), but none are so fast as <strong>to</strong> be in O(n 2 ).Now, consider the case of multiplying two symmetric matrices. A symmetricmatrix is one in which entry ij is equal <strong>to</strong> entry ji; that is, the upper-right triangleof the matrix is a mirror image of the lower-left triangle. Is there something aboutthis restricted case that allows us <strong>to</strong> multiply two symmetric matrices faster thanin the general case? The answer is no, as can be seen by the following reduction.Assume that we have been given two n × n matrices A <strong>and</strong> B. We can construct a2n × 2n symmetric matrix from an arbitrary matrix A as follows:

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

Saved successfully!

Ooh no, something went wrong!