Question

In: Computer Science

. We have the following algorithm. Algorithm Novel(X[0..m-1, 0..m-1]) //Input: A matrix X[0..m-1, 0..m-1] of real...

. We have the following algorithm.
Algorithm Novel(X[0..m-1, 0..m-1])
//Input: A matrix X[0..m-1, 0..m-1] of real numbers
for i←0 to m-2 do
for j←i+1 to m-1 do
   if X[i,j] ≠X[j, i]
       return false
return true

a.   What does this algorithm compute?

b. What is its basic operation?

c. How many times is the basic operation executed?


d. What is the efficiency class of this algorithm?

Solutions

Expert Solution

  • Below is the detailed explanation of the above mentioned problem.
  • Algorithm:

Algorithm Novel(X[0..m-1, 0..m-1])
for i←0 to m-2 do
for j←i+1 to m-1 do
if X[i,j] ≠X[j, i]
return false
return true

The above algorithm is trying to check if the given matrix X(of dimension mm) is symmetrix or not i.e, it is checking if all the element at X[i,j] are equal to X[j,i], if not then it is returning false otherwise after full checking it returns true.

A symmetric matrix is a matrix which is equal to it's transpose, so this matrix is symmetrix about left diagonal and on it's diagonal the element can be anything as for left diagonal in X[i,j] i=j so for diagonal X[i,j]=X[j,i] is true always irrrespective of the value.

  • Answers:

a. So this algorithm is checking if the give matrix is symmetrix or not.

b.it's basic operation is to check if element at X[i,j] is equal to X[j,i] i.e, the sole condition for being a symmetrix matrix for all i,j in [0,m-1].

c.So the basic operation is executed (m*(m-1))/2 times (in worst case i.e, if the matrix is symmetric and it can be less if the matrix is asymmetric as we will reach the condition X[i,j] ≠X[j, i] and return from the function) as we can see that the outer for loop runs from u=0 to m-2 i.e, m-1 times and the inner loop runs from i+1 to m-1 i.e, m-i-1 times. So for each outer loop we get inner loop iterations as m-1(when i=0), m-2(when i=1).....................and at last 1(when i=m-2). So in total the sum of this series is 1+2+3+.................m-2+m-1= (m*(m-1))/2. So resultingly the number of times this operation is performed is (m*(m-1))/2.

d. the efficiency class of this algorithm is (m2) i.e, order of m2 , as we can see that the number of times operation is performed is in total (m*(m-1))/2(in worst case if the matrix is symmetric) and 1(in best case if the matrix is asymmetric) so in average case in theta notation we can say that it is (m2)(also by the polynomial theorem) that it belong to this class.

Example of a symmetric matrix(33) ( X[i,j]=X[j,i] for all i,j in [0,m-1])

-1 2 3
2 0 4
3 4 5

Example of a asymmetric matrix(33) ( X[i,j]!=X[j,i] for all i,j in [0,m-1] i.e, in particular X[0,1]!=X[1,0] )

-1 2 3
3 0 4
3 4 5

So if you still have any doubt regarding this solution please feel free to ask it in the comment section below and if it is helpful then please upvote this solution, THANK YOU.


Related Solutions

Convolve the following two signals using the INPUT side algorithm. x[n]= 1, 0, 2, 0, 0,...
Convolve the following two signals using the INPUT side algorithm. x[n]= 1, 0, 2, 0, 0, 0, 2, 1, 0, 1 h[n]= 3, 2, 1 y[n]=?
algorithm binarySearch input bottom, top: a number    a: array a[0] to a[n-1] of numbers    x: a...
algorithm binarySearch input bottom, top: a number    a: array a[0] to a[n-1] of numbers    x: a number output result: true if x in a false otherwise Sideeffect NA Plan if (top < bottom) result := false else // get the middle of the array (refining) middle := (top - bottom)/2 + bottom (refining by +1 or -1 or integer division …) // example what is midpoint between 6 and 8 // (8-6)/2 = 1 we need to add 6 to...
Consider the following algorithm. Algorithm Mystery(n) //Input: A nonnegative integer n S ← 0 for i...
Consider the following algorithm. Algorithm Mystery(n) //Input: A nonnegative integer n S ← 0 for i ← 1 to n do S ← S + i * i return S a. What does this algorithm compute? b. What is its basic operation? c. How many times is the basic operation executed? d. What is the efficiency class of this algorithm? e. Suggest an improvement, or a better algorithm altogether, and indicate its efficiency class. If you cannot do it, try...
Prove that for all real x, we have |x−1|+|x + 2|≥ 3.
Prove that for all real x, we have |x−1|+|x + 2|≥ 3.
Find a real Leontief Input-output matrix for a country and explain about the matrix?
Find a real Leontief Input-output matrix for a country and explain about the matrix?
We have potential of V (x) = ( 0, 0 ≤ x ≤ a.   ∞, elsewhere....
We have potential of V (x) = ( 0, 0 ≤ x ≤ a.   ∞, elsewhere. a) Find the ground state energy and the first and second excited states, if an electron is enclosed in this potential of size a = 0.100 nm. b) Find the ground state energy and the first and second excited states, if a 1 g metal sphere is enclosed in this potential of size a = 10.0 cm. c) Are the quantum effects important for...
Suppose we have the following pdf for the random variable X f(x) ={x 0<=x<=1 c/x^2 1<=x<=...
Suppose we have the following pdf for the random variable X f(x) ={x 0<=x<=1 c/x^2 1<=x<= infinity 0 otherwise } (a) 2 points Find the value c such that f(x) is a valid pdf. (b) 3 points Find the cdf of X. (c) 1 point Find the 75th percentile of X.
In python find matrix M I have the matrix X X=[5.8 3.0 3.7 1.9] and need...
In python find matrix M I have the matrix X X=[5.8 3.0 3.7 1.9] and need to create a matrix M that is 4x150 that has the the values of matrix X inside it for every row M= 5.8 3.0 3.7 1.9 5.8 3.0 3.7 1.9 5.8 3.0 3.7 1.9 5.8 3.0 3.7 1.9 5.8 3.0 3.7 ect 5.8 ect ect 5.8 ect 5.8
True/False: If A is an invertible m x m matrix and B is an m x...
True/False: If A is an invertible m x m matrix and B is an m x n matrix, then AB and B have the same null space. (Hint: AB and B have the same null space means that ABX = 0 if and only if BX = 0, where X is in Rn.)
1. For an m x n matrix A, the Column Space of A is a subspace...
1. For an m x n matrix A, the Column Space of A is a subspace of what vector space? 2. For an m x n matrix A, the Null Space of A is a subspace of what vector space?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT