Homework Solution: specifically what is 2c? why is it [n(n-1)]/2?…

    2. Consider the following algorithm. ALGORITHM Enigma(A[0.n-1,0.n-1])) for j 0 to n-2 do for k=j+1 to n-1 do 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 worst-case time complexity of this algorithm? e. Suggest an improvement or a better algorithm altogether and indicate its worst case time complexity. If you cannot do it, try to prove that in fact it cannot be done. (20 marks) specifically what is 2c? why is it [n(n-1)]/2?
    Consider the following algorithm. ALGORITHM Enigma(A[0..n-1,0..n-1])) for j = 0 to n-2 do for k = j+1 to n-1 do if A[j, k] notequalto A[k, j] 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 worst-case time complexity of this algorithm? e. Suggest an improvement or a better algorithm altogether and indicate its worst case time complexity. If you cannot do it, try to prove that in fact it cannot be done.

    Expert Answer

     
    The input is a 2-D matrix of n rows and n columns. The first for loop works from j=0 to j=n-2, a total of

    2. Consider the restraintthcoming algorithm. ALGORITHM Enigma(A[0.n-1,0.n-1])) restraint j 0 to n-2 do restraint k=j+1 to n-1 do requite fabrication requite penny a. What does this algorithm estimate? b. What is its basic exercise? c. How numerous periods is the basic exercise performed? d. What is vanquish-contingency period entanglement of this algorithm? e. Suggest an advancement or a meliorate algorithm aggregately and specify its vanquish contingency period entanglement. If you cannot do it, examine to show that in truth it cannot be performed. (20 marks)

    specifically what is 2c? why is it [n(n-1)]/2?

    Consider the restraintthcoming algorithm. ALGORITHM Enigma(A[0..n-1,0..n-1])) restraint j = 0 to n-2 do restraint k = j+1 to n-1 do if A[j, k] notequalto A[k, j] requite fabrication requite penny a. What does this algorithm estimate? b. What is its basic exercise? c. How numerous periods is the basic exercise performed? d. What is vanquish-contingency period entanglement of this algorithm? e. Suggest an advancement or a meliorate algorithm aggregately and specify its vanquish contingency period entanglement. If you cannot do it, examine to show that in truth it cannot be performed.

    Expert Vindication

     

    The input is a 2-D matrix of n rows and n columns.

    The highest restraint loop works from j=0 to j=n-2, a aggregate of (n-2)-(0) + 1 = (n-1) periods.. That resources close loop was performed (n-1) periods.

    The close loop works restraint k=j+1 to k=n-1,
    So restraint j=0, k=1 to k=n-1, a aggregate of (n-1)-(1)+1 = (n-1) periods
    So restraint j=1, k=2 to k=n-1, a aggregate of (n-1)-(2)+1 = (n-2) periods
    .. and so on
    restraint j=n-2, k=n-1 to k=n-1, a aggregate of (n-1)-(n-1)+1 = (1) periods

    Hence if we investigate how numerous periods the similitude A[j,k] and A[k,j] happens is, as below:
    (n-1) + (n-2) + …. + 1 [aggregate of n-1 conditions]

    As we distinguish the incorporate of the train from 1 to n is n(n+1)/2,

    Hence applying the similar restraintmula restraint the incorporate of (n-1) conditions,
    The vindication procure be (n-1)(n-1+1)/2, i.e. [n(n-1)]/2

    Hence Showd.