Question

In: Computer Science

1. Write an algorithm to calculate the Matrix multiplication (or write with pseudo code) 2. Write...

1. Write an algorithm to calculate the Matrix multiplication (or write with pseudo code)
2. Write an algorithm to calculate the recursive Matrix multiplication (or write with pseudo code)
3. Find the time complexity of your pseudo code and analyze the differences

Solutions

Expert Solution

Algorithm for matrix multiplication:

Step 1: Start

Step 2: Declare variable i,j and k.

Step 3: Define the size of the matrix in a variable say N.

Step 4: A [][] and B[][] are the matrices and C[][] is the result matrix.

Step 5: Variable i is for knowing the position in the first matrix and variable j is for knowing the position in second matrix.

Step 6: The variable k traverses through both the matrix and multiplication happens.

Step 7:Three For loops are used to iterate through the rows and columns.

Step 8: The for loop fails if its exceeds the size of the matrix.

Step 9: Multiplication happens in a standard way i.e The first row of the ith matrix and first column of jth matrix is multiplied and added altogether.

Step 10: In your main function declare the input values and run the code.

Step 11: Stop

2.Algorithm for recursive matrix multiplication

Step 1: Start

Step 2: Recursive multiplication is the process of dividing the input matrix into sub matrices and then getting the result.

Step 3: Only if the number of columns in a second matrix are equal to the number of rows in the first matrix recursive multiplication happens.

Step 4:Similar to matrix multiplication follow the step 2.

Step 5: Declare a maximum size say 100 as we will be dividing it into sub matrices.

Step 6: Using if statement check the column position using i variable and then check the column position in second matrix by j variable.

Step 7: The above if statements get true then check the position of k variable and if its not exceeded size of matrix then mutliply both and get the result matrix.

Step 8: C[][] will hold the result matrix.

3.In a 2*2 matrix 8 multiplications happen so the time compexity will be 8T(N/2)+O(N^2). Solving the equation you get a time complexity value of O(N^3). Using Strassens method this can be reduced by using divide and conquer method. i.e dividing the input matrix into sub matrices and recursive calls made are reduced to 7 from 8.The time complexity after using this will be O(N^2.87). Usually this procedure is not used and naive multiplying is done.


Related Solutions

Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
Write an algorithm in pseudo code to find one element and delete it in a doubly...
Write an algorithm in pseudo code to find one element and delete it in a doubly linked list. Your algorithm will print the original list, request the user to put in an element to be deleted, then print the final list after the deletion is done. If the element doesn’t exist in the list, print "XXX is not in the list" where "XXX" should be the one you received from the user. Use the following as your test cases to...
Write a recursive algorithm in pseudo-code to compute the “power list” of a given list of...
Write a recursive algorithm in pseudo-code to compute the “power list” of a given list of integers. Assume that the List type has members: int List.length returns the length of the list. void List.push(T n) pushes an element n to the front of the list T List.pop() pops an element from the front of the list. List$$ List$$.concat(List$$ other) returns the concatenation of this list with other. Explain in plain English the reasoning behind your algorithm. Power Lists should be...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java program.
In pseudo-code, design an algorithm for finding baking a cake.
In pseudo-code, design an algorithm for finding baking a cake.
Write the pseudo code for longest common subsequence algorithm in Java. Alg lCS( X , n,...
Write the pseudo code for longest common subsequence algorithm in Java. Alg lCS( X , n, Y, m) Input: String X of length n, String Y of length m Output: return the length of the longest common subsequence between X and Y
*Please give the answers in pseudo code 1) Design an algorithm that will receive two integer...
*Please give the answers in pseudo code 1) Design an algorithm that will receive two integer items from a terminal operator, and display to the screen their sum, difference, product and quotient. Note that the quotient calculation (first integer divided by second integer) is only to be performed if the second integer does not equal zero. 2) Design an algorithm that will read two numbers and an integer code from the screen. The value of the integer code should be...
Write down an algorithm in pseudo-code whose running time where input is an array whose length...
Write down an algorithm in pseudo-code whose running time where input is an array whose length defines the problem size. Take the cost of execution of each line of the algorithm as 1. Make comment about the following paragraph: “You are given two independent algorithms and whose running time complexities are and , respectively. If we add a new line to our algorithm in which it calls the algorithm then the running time complexity of the modified algorithm becomes ”.
Strassen’s algorithm for matrix multiplication relies on using 7 multiplications (instead of 8 as in the...
Strassen’s algorithm for matrix multiplication relies on using 7 multiplications (instead of 8 as in the straightforward algorithm) to multiply a pair of 2 by 2 matrices. Explain why it is not possible to further reduce this number, 7, to anything less than 4, in multiplying a pair of 2 by 2 matrices.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT