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
Get the time complexity function from the pseudocode for the addition of the 2 matrices below, and prove whether the big-oh is O(n^2) so that it satisfies the rule f(n) <= c g(n);
/ add two matricesfor(i = 0 ; i < rows; i++){for(j = 0; j < columns; j++)matrix2[i][j] = matrix1[i][j] + matrix2[i][j];}// display the resultfor(i = 0 ; i < rows; i++){for(j = 0; j < columns; j++){printf("%d ", matrix2[i][j]);}printf("\n");}
What 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)
Get the time complexity function from the pseudocode for adding 2 matrices below
// add two matricesfor(i = 0 ; i < rows; i++){for(j = 0; j < columns; j++)matrix2[i][j] = matrix1[i][j] + matrix2[i][j];}// display the resultfor(i = 0 ; i < rows; i++){for(j = 0; j < columns; j++){printf("%d ", matrix2[i][j]);}printf("\n");}
Knowledge Booster
Similar questions
- Determind the complexity of the following implementations of the algorithms for adding, multiplying, and transposing n x n matricesarrow_forward3. 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).arrow_forwardSearch a sorted matrix: The input consistsof a real number x and a matrix A[1..n, 1..m] of nm real numbers such that each rowA[i, 1..m] is sorted and each column A[1..n, j] is sorted. The goal is to find the maximum array entry A[i, j] that is less than or equal to x, or report that all elements of Aare larger than x. Design and analyze an iterative algorithm for this problem that examines as few matrix entries as possible. Becareful if you believe that a simple binarysearch solves the problem. make a lower bound, and recursive algorithm.arrow_forward
- Search a sorted matrix: The input consistsof a real number x and a matrix A[1..n, 1..m] of nm real numbers such that each rowA[i, 1..m] is sorted and each column A[1..n, j] is sorted. The goal is to find the maximum array entry A[i, j] that is less than or equal to x, or report that all elements of Aare larger than x. Design and analyze an iterative algorithm for this problem that examines as few matrix entries as possible. Becareful if you believe that a simple binarysearch solves the problem.arrow_forwardGiven a matrix of size N x M where N is the number of rows and M is the number of columns, write an algorithm to find the shortest path from the top-left cell to the bottom-right cell that passes through all the cells with a prime value and avoids cells with composite values. The algorithm should have a time complexity of O(NM log(max(N,M))).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_forward
- Assume that we have a way of multiplying 2 by 2 matrices using 7 multiplications. Use this, to design a divide and conquer algorithm for multiplying n by n matrices in O(n^log7) time.You should briefly outline the algorithm, write a recurrence relation, and solve it to derive the time complexity.arrow_forwardConsider the following algorithm, which takes as input asequence of n integers a_1, a_2,… , a_n and produces as output a matrix M = {m_(ij)} where m_(ij) is the minimum termin the sequence of integers a_i, a_(i+1),… , a_j for j ≥ i andm_(ij) = 0 otherwise.initialize M so that m_(ij) = a_i if j ≥ i and m_(ij) = 0otherwisefor i := 1 to nfor j := i + 1 to nfor k := i + 1 to jm_(ij) := min(m_(ij), a_k)return M= {m_(ij)} {m_(ij) is the minimum term ofa_i, a_(i+1),… , a_j}a) Show that this algorithm uses O(n^3) comparisons tocompute the matrix M. b) Show that this algorithm uses Ω(n^3) comparisons tocompute the matrix M. Using this fact and part (a),conclude that the algorithms uses Θ(n^3) comparisons.[Hint: Only consider the cases where i ≤ n∕4 andj ≥ 3n∕4 in the two outer loops in the algorithm.]arrow_forwardLet us consider multiplying a 5 by 5 sparse matrix with a 5 by 3 sparse matrix shown in picture. make Python code to implement multiplication of these two sparse matricesarrow_forward
- subject : analysis of algorithm Q.No.1: Consider the following chain of matrices having matrices A, B, C and D. You have to consider the digits of your Registration Number in the order of the matrix as given. Add 2 to the digit if its zero. For example, your Reg_No. 19-Arid-797 has last digit 7, 2nd last digit 9 and 3rd last digit 7. A B C 2 X last digit last digit X 2nd last digit 2nd last digit X 3nd last digit D 3rd Last digit X 4 What will be the minimum number of multiplication to multiply these matrices? Show the order of multiplication as well.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_forwardFind a sorted matrix: The input is a real number x and a matrix A[1..n, 1..m] of nm real numbers, with each row A[i, 1..m] and column A[1..n, j] sorted. The objective is to locate the largest array entry A[i, j] that is less than or equal to x, or to report that all components of A are greater than x. Create and test an iterative method that analyses as few matrix elements as feasible. Be cautious if you assume a simple binary search would fix the problem. Find a sorted matrix: The input is a real number x and a matrix A[1..n, 1..m] of nm real numbers, with each row A[i, 1..m] and column A[1..n, j] sorted. The objective is to locate the largest array entry A[i, j] that is less than or equal to x, or to report that all components of A are greater than x. Create and test an iterative method that analyses as few matrix elements as feasible. Be cautious if you assume a simple binary search would fix the problem.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Operations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks Cole
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole