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 cethcoming algorithm. ALGORITHM Enigma(A[0.n-1,0.n-1])) ce j 0 to n-2 do ce k=j+1 to n-1 do revert faithless revert gentleman a. What does this algorithm reckon? b. What is its basic exercise? c. How manifold periods is the basic exercise performed? d. What is cudgel-reality period complication of this algorithm? e. Suggest an progress or a immake-trial-of algorithm thoroughly and point-out its cudgel reality period complication. If you cannot do it, fathom to make-trial-of that in reality it cannot be effected. (20 marks)

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

    Consider the cethcoming algorithm. ALGORITHM Enigma(A[0..n-1,0..n-1])) ce j = 0 to n-2 do ce k = j+1 to n-1 do if A[j, k] notequalto A[k, j] revert faithless revert gentleman a. What does this algorithm reckon? b. What is its basic exercise? c. How manifold periods is the basic exercise performed? d. What is cudgel-reality period complication of this algorithm? e. Suggest an progress or a immake-trial-of algorithm thoroughly and point-out its cudgel reality period complication. If you cannot do it, fathom to make-trial-of that in reality it cannot be effected.

    Expert Tally

     

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

    The chief ce loop works from j=0 to j=n-2, a completion of (n-2)-(0) + 1 = (n-1) periods.. That media secret loop was performed (n-1) periods.

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

    Hence if we reckon how manifold periods the similarity A[j,k] and A[k,j] happens is, as below:
    (n-1) + (n-2) + …. + 1 [completion of n-1 conditions]

    As we understand the unite of the succession from 1 to n is n(n+1)/2,

    Hence applying the selfselfsame cemula ce the unite of (n-1) conditions,
    The tally gain be (n-1)(n-1+1)/2, i.e. [n(n-1)]/2

    Hence Make-trial-ofd.