Thesquare of a matrix A is its product with itself, AA.

(a) Show that five multiplications are sufficient to compute the square of a 2 x 2 matrix.

(b) What is wrong with the following algorithm for computing the square of an n x n matrix?

“Use a divide-and-conquer approach as in Strassen’s algorithm, except that instead of getting 7 subproblems of size n2, we now get 5 subproblems of size n2 thanks to part (a). Using the same analysis as in Strassen’s algorithm, we can conclude that the algorithm runs in time O (nc) .”

(c) In fact, squaring matrices is no easier than matrix multiplication. In this part, you will show that if n x n matrices can be squared in time S(n) = O(nc), then any two n x n matrices can be multiplied in time O(nc) .

  1. Given two n x n matrices A and B, show that the matrix AB + BA can be computed in time 3S(n) + O(n2 ) .
  2. Given two n x n matrices X and Y, define the 2n x 2n matrices A and B,L as follows:
    A=X000andB=0Y00
    What is AB + BA, in terms of X and Y?
  3. Using (i) and (ii), argue that the product XY can be computed in time 3S(2n) + O(n2 ). Conclude that matrix multiplication takes time O(nc ).

Short Answer

Expert verified
  1. mnopmnop=m2+non(m+p)0(m+p)no+p2,5
  2. The suggested algorithm has insufficient run time to perform the square of the matrix.

  3. (i) Given matrix can be computed in 3S(n) +O(n2 )
    (ii) AB+BA=0XY00
    (iii) The product XYneeds only 2S (2n) + O(n2 )computation time and the matrix multiplication takes O(nc)time.

Step by step solution

01

Number of multiplications required to compute the square of matrix:

Consider the 2 x 2 matrix, mnop,

Compute the square of the above matrix,

mnopmnop=m2+non(m+p)0(m+p)no+p2

In the computation, the multiplications involved are m2, n (m + p), o (m + p), p2 , and no.

Therefore, the five multiplications are sufficient to calculate the square of 2 x 2 matrix.

02

What is wrong with the given algorithm

(b)

A matrix squaring problem of size n xn has 5 sub-problems of size n2. The half of the sub-problems (that is, three of the five sub-problems) are engaged in the product of n2×n2matrices, according to the divide and conquer approach. There are five sub-problems in all, each of which is n2 in size. Each sub-operation of a problem has been denoted by T Because the two sets of matrices are divided and conquered, this procedure will take O(n2) time to run. As a result, this method does not execute in "O(n O(nlog23) time.

As a result, the suggested algorithm's running time is insufficient for computing the square of a n x n matrix.

03

show that the matrix AB + BA can be computed in time 3S(n) + O(n2).

(c)

i.

Consider the two n x n matrices, A and B .

Calculate, AB + BA as follows,

AB+BA=(A+B)(A+B)-AA-BB ,

The computation involves three squared terms, that can be computed in 3S(n) times. The other arithmetic operations can be computed in O(n2) time.

Therefore, the computation of AB + BA can be computed in 3S(n) + O(n2) time.

04

show the matrix AB + BA in terms of X and Y 

(c)

ii.

Consider the two n x n matrices, A and B .

A=X000,B=0Y00AB+BA=X000+0Y00X000+0Y00-X000+X0000Y00+0Y00=0XY00 ,

Therefore, the representation of AB + BA , in terms of X and Y is0XY00

05

show the matrix AB + BA in terms of X and Y 

(c)

iii.

Consider the product of XY as follows,

0XY00=XY00XY00-X000X000-0Y000Y00

Since, 0Y000Y00=0,

The product will be,0XY00=XY00XY00-X000X000

The product has two squares and a arithmetic opertation.

Therefore,The product XYneeds only 2S(2n) + O(n2)computation time and the matrix multiplication takes O(nc)time.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

You are given an array of nelements, and you notice that some of the elements are duplicates; that is, they appear more than once in the array. Show how to remove all duplicates from the array in time O(nlogn) .

An array A[1...n] is said to have a majority element if more than half of its entries are the same. Given an array, the task is to design an efficient algorithm to tell whether the array has a majority element, and, if so, to find that element. The elements of the array are not necessarily from some ordered domain like the integers, and so there can be no comparisons of the form “ is A[i]>A[j] ?”. (Think of the array elements as GIF files, say.) However you can answer questions of the form: “is ..?” in constant time.

(a) Show how to solve this problem in O(nlogn) time. (Hint: Split the array A into two arrays A1and A2of half the size. Does knowing the majority elements of A1and A2help you figure out the majority element of A? If so, you can use a divide-and-conquer approach.)

(b) Can you give a linear-time algorithm? (Hint: Here’s another divide-and-conquer approach:• Pair up the elements of A arbitrarily, to get n/2 pairs• Look at each pair: if the two elements are different, discard both of them; if they are the same, keep just one of them . Show that after this procedure there are at most n/2 elements left, and that they have a majority element if A does.)

What is the sum of the nth roots of unity? What is their product if n is odd? If n is even?

In this problem we will develop a divide-and-conquer algorithm for the following geometric task.

CLOSEST PAIRInput: A set of points in the plane, {p1=(x1;y1),p2=(x2,y2),...,pn=(xn,yn)}

Output: The closest pair of points: that is, the pair PiPjfor which the distance between piand pj, that is,

(xi-xi)2+z(yi-yi)2,

is minimized.

For simplicity, assume that n is a power of two, and that all the x-coordinates role="math" localid="1659237354869" xi are distinct, as are the y-coordinates.

Here’s a high-level overview of the algorithm:

.Find a value for which exactly half the points have xi<x, and half have xi>x. On this basis, split the points into two groups, L and R.

• Recursively find the closest pair in L and in R. Say these pairs are pL·qLLand pR·qRRwith distances dLand dR respectively. Let d be the smaller of these two distances.

• It remains to be seen whether there is a point in Land a point in R that are less than distance dapart from each other. To this end, discard all points with xi<x-dor xi>x+d and sort the remaining points by y-coordinate.

• Now, go through this sorted list, and for each point, compute its distance to the seven subsequent points in the list. Let pM·qMbe the closest pair found in this way.

• The answer is one of the three pairs role="math" localid="1659237951608" {pL,qL},{pR,qR}{pM,qM}, whichever is closest.

(a) In order to prove the correctness of this algorithm, start by showing the following property: any square of size d×d in the plane contains at most four points of L.

(b) Now show that the algorithm is correct. The only case which needs careful consideration is when the closest pair is split between L and R.

(c) Write down the pseudocode for the algorithm, and show that its running time is given by the recurrence:

T(n)=2T(nl2)+0(nlogn)

Show that the solution to this recurrence is o(nlogzn).

(d) Can you bring the running time down to O(nlogn)?

How many lines, as a function of n (in (.)form), does the following program print? Write a recurrence and solve it. You may assume is a power of . function f (n) if n > 1:

print_line (‘‘still going’’)

f (n/2)

f (n/2)

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free