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.

Sec. 17.2 Hard Problems 541Our next example of reduction concerns the multiplic<strong>at</strong>ion of two n × n m<strong>at</strong>rices.For this problem, we will assume th<strong>at</strong> the values stored in the m<strong>at</strong>rices are simpleintegers <strong>and</strong> th<strong>at</strong> multiplying two simple integers takes constant time (becausemultiplic<strong>at</strong>ion of two int variables takes a fixed number of machine instructions).The st<strong>and</strong>ard algorithm for multiplying two m<strong>at</strong>rices is to multiply each elementof the first m<strong>at</strong>rix’s first row by the corresponding element of the second m<strong>at</strong>rix’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 total 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 to be in O(n 2 ).Now, consider the case of multiplying two symmetric m<strong>at</strong>rices. A symmetricm<strong>at</strong>rix is one in which entry ij is equal to entry ji; th<strong>at</strong> is, the upper-right triangleof the m<strong>at</strong>rix is a mirror image of the lower-left triangle. Is there something aboutthis restricted case th<strong>at</strong> allows us to multiply two symmetric m<strong>at</strong>rices faster thanin the general case? The answer is no, as can be seen by the following reduction.Assume th<strong>at</strong> we have been given two n × n m<strong>at</strong>rices A <strong>and</strong> B. We can construct a2n × 2n symmetric m<strong>at</strong>rix from an arbitrary m<strong>at</strong>rix A as follows:[ 0 AA T 0Here 0 st<strong>and</strong>s for an n×n m<strong>at</strong>rix composed of zero values, A is the original m<strong>at</strong>rix,<strong>and</strong> A T st<strong>and</strong>s for the transpose of m<strong>at</strong>rix A. 1 Note th<strong>at</strong> the resulting m<strong>at</strong>rix is nowsymmetric. We can convert m<strong>at</strong>rix B to a symmetric m<strong>at</strong>rix in a similar manner.If symmetric m<strong>at</strong>rices could be multiplied “quickly” (in particular, if they couldbe multiplied together in Θ(n 2 ) time), then we could find the result of multiplyingtwo arbitrary n × n m<strong>at</strong>rices in Θ(n 2 ) time by taking advantage of the followingobserv<strong>at</strong>ion: [ 0 AA T 0] [ 0 BTB 0]=].[ ]AB 00 A T B T .In the above formula, AB is the result of multiplying m<strong>at</strong>rices A <strong>and</strong> B together.17.2 Hard ProblemsThere are several ways th<strong>at</strong> a problem could be considered hard. For example, wemight have trouble underst<strong>and</strong>ing the definition of the problem itself. At the beginningof a large d<strong>at</strong>a collection <strong>and</strong> analysis project, developers <strong>and</strong> their clientsmight have only a hazy notion of wh<strong>at</strong> their goals actually are, <strong>and</strong> need to workth<strong>at</strong> out over time. For other types of problems, we might have trouble finding orunderst<strong>and</strong>ing an algorithm to solve the problem. Underst<strong>and</strong>ing spoken English1 The transpose oper<strong>at</strong>ion takes position ij of the original m<strong>at</strong>rix <strong>and</strong> places it in position ji of thetranspose m<strong>at</strong>rix. This can easily be done in n 2 time for an n × n m<strong>at</strong>rix.

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

Saved successfully!

Ooh no, something went wrong!