Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 28.2, Problem 1E
Program Plan Intro
To show that multiplying and squaring matrices have the same difficulty: an
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
3. Explain why the next matrix in Floyd’s algorithm can be written over its predecessor (i.e., when calculating D(k) from D(k-1), we do not need another matrix but can change D(k-1) into D(k).
We are given a code symmetry, that takes an n x n matrix as its argument. It returns true if the matrix is symmetric and false if it is not. The run time of the code is calculated by counting how many times the /= comparison is executed.
procedure symmetry(M)
for x:=1 to (n-1)
for y:=(i+1) to n
if mxy /= myx then return false
else return true
(a) Calculate the best case run time for symmetry (will be a number).
(b) Calculate the worst case run time for symmetry (will be a polynomial in n, it will be helpful to draw matrices of different sizes and compare the number of comparisons to find a pattern).
(c) Determine the worst case run time in big O notation
(d) Using the following definition of big O notation, prove the answer to (c)
Definition: Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f(x) is O(g(x)) if there are constants C and k such that whenever x > k. [This is…
Consider an n by n matrix, where each of the n2 entries is a
positive integer.
If the entries in this matrix are unsorted, then determining
whether a target number t appears in the matrix can only be done
by searching through each of the n2 entries. Thus, any search
algorithm has a running time of O(n²).
However, suppose you know that this n by n matrix satisfies the
following properties:
• Integers in each row increase from left to right.
• Integers in each column increase from top to bottom.
An example of such a matrix is presented below, for n=5.
4 7 11 15
2 5 8 12 19
3 6 9 16 22
10 13 14 17 24
1
18 21 23 | 26 | 30
Here is a bold claim: if the n by n matrix satisfies these two
properties, then there exists an O(n) algorithm to determine
whether a target number t appears in this matrix.
Determine whether this statement is TRUE or FALSE. If the
statement is TRUE, describe your algorithm and explain why your
algorithm runs in O(n) time. If the statement is FALSE, clearly
explain why no…
Knowledge Booster
Similar questions
- Create a 3-by-3 matrix. A = [1 7 3; 2 9 12; 5 22 7]; Calculate the right eigenvectors, V, the eigenvalues, D, and the left eigenvectors, W. [V,D,W] eig(A) %3!arrow_forwardLet m be a matrix with n rows and n columns whose entries are either 1 or 0. recall that the element of m on row i and column j is denoted by mij . the diagonal entries of m are {mii} for 1 ≤ i ≤ n. We call M permutable if it is possible to swap some of the rows and some of columns so that all diagonal entries are 1. Design a polynomial time algorithm that decides whether a binary matrix M is permutable or not. Note that we can swap any two rows or two columns. Also, the order in which these swaps are done is not important.arrow_forwardFollowing code is a part of an algorithm where A = [a; ;] is an N x N matrix with a;i = a(i, j), x, y, b are vectors of length N. Count the total number of operations (addition/subtraction and multi- plication/division) for the code below in terms of N (Give a simplified answer in terms of N): Begin Algorithm fct = 2 sum for i = 1 to N x(i) y(i) = Fa end i loop for j = 1 to N suml = 0 for k = j+1 to N suml = suml+a(j,k) * y(k) end k loop r(j) end j loop sum = 10 + sum1 * fct b(j)-sum a(j, j) End Algorithmarrow_forward
- Write the Python code to find the transitive closure when given zero-one matrix. DO NOT use the Warshall Algorithm in this code. Pseudo code: A := MR B := A for i := 2 to n A:= A ⊙ MR B:= B ∨ A return B (the zero-one matrix for R*)arrow_forwardArray P = [40, 30, 25, 10, 35, 5, 20] Suppose the dimension of 6 matrices (A1, A2 … A6) are given by array P A1 is a P[0] x P[1] matrix A2 is a P[1] x P[2] matrix . . . A6 is a P[5] x P[6] a) Find the minimum number of scalar multiplications necessary to calculate the product of all the 6 matrices (A1.A2.A3.A4.A5.A6) and show the parenthesization for this multiplication. • Solve the problem manually (you need not to write any code) using bottom-up tabulation approach. Compute and show the ‘m’ matrix and ‘s’ matrix to solve your problem.arrow_forwardFind the generalized time functions of the following code snippet Matrics_Multiplication (A, B) { // nx m matrix A // m x p matrix B // n×p matrix C // C= AB 1. Let C be a new matrix of the appropriate size 2. For i from 1 to n: For j from 1 to p: 3. 4. Let sum = 0 For k from 1 to m: 5. Set sum + sum + Ajk × Bj 6. 7. Set Cj - sum 8. Return C }arrow_forward
- Sparse matrix-vector multiplication in Python is similar to numpy.dot operation, however the provided @ operator is used. Let us consider multiplying a 5 by 5 sparse matrix with a 5 by 3 sparse matrix shown below. 01000 00010 10001 10000 01000 100 001 x 000 010 100 The Python code to implement multiplication of these two sparse matricesarrow_forwardWrite pseudo-code algorithms for matrix addition, scalar multiplication, and product of two matrices in 3*3 matrix.arrow_forwardWrite pseudo-code algorithms for each of the matrix operations (matrix addition, scalar multiplication and product of two matrices),and matrix should be 3*3arrow_forward
- This question is about the Matrix Chain Multiplication problem. You are given four matrices with the following dimensions.arrow_forwardTrue or False The inverse of a matrix M can be calculated in Python with the command Inverse=np.linalg.inv(M)arrow_forwardWhat is the worst-case running time complexity of matrix substraction? select one: a.O(n^2.5) b.O(2n) c.O(n^2) d.O(3^n)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education