Question: Write a C++ program or C program (or any other programming language )for Matrix Transpose Algorithm. Algorithm Transpose(a,n) { for i := 1 to n-1

Write a C++ program or C program (or any other programming language )for Matrix Transpose Algorithm.

Algorithm Transpose(a,n)

{

for i := 1 to n-1 do

for j := i+1 to n do

{

t := a[i,j]; a[i,j] := a[j,i]; a[j,i] := t;

}

}

a) Introduce statements to increment count (by using structures if C or C++) at all appropriate points in the algorithm

b) Simplify the resulting algorithm by eliminating the statements. The simplied algorithm should compute the same value for "count" as computed by the algorithm of part (a)

c) What is the exact value of "count" when the algorithm terminates? You may assume that the initial value of "count" = 0

d) Obtain the step count for the given algorithm using the frequency method. Clearly show the step count table.

One example program that times a loop in C is given here:

#include  #include  #include  int main() { struct timeval tt; long tsec,tusec; int f,i,x; float e; x = 0; f = gettimeofday(&tt,0); tsec = tt.tv_sec; tusec = tt.tv_usec; for(i=0;i<10000000;i++) x = x+1; f = gettimeofday(&tt,0); printf("Elapsed: %ld seconds and %ld microseconds ", tt.tv_sec-tsec,tt.tv_usec-tusec); e = (float)(tt.tv_sec - tsec) + (float)(tt.tv_usec - tusec)/1000000; printf("= %g seconds ",e); exit(0); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!