Transpose of sparse matrix
Consider a matrix
4 0 2 0
A= 0 6 0 0
0 0 5 0
7 0 0 8
|
4 0 0 7
AT= 0 6 0 0
2 0 5 0
0 0 0 8
|
R
|
C
|
value
|
R
|
C
|
value
| |||
0
|
3
|
4
|
6
|
0
|
3
|
4
|
6
| |
1
|
1
|
1
|
4
|
1
|
1
|
1
|
4
| |
2
|
1
|
2
|
2
|
2
|
1
|
4
|
7
| |
3
|
2
|
2
|
6
|
3
|
2
|
2
|
6
| |
4
|
3
|
3
|
5
|
4
|
3
|
1
|
2
| |
5
|
4
|
1
|
7
|
5
|
3
|
3
|
5
| |
6
|
4
|
4
|
8
|
6
|
4
|
4
|
8
| |
From the above two 3 – tuples we observe that in A-3 tuples are in ascending order and columns are in random way whereas in AT – 3 tuples columns are in ascending order and rows become irregular and actual changes depending on the row and column position.
Procedure Transpose(A: array[0..30, 1..3] of integers)
B: array[0..30, 1..3] of integers
I, j, k: integers
Begin
B[0,1]= A[0,2]; { Copy Ist row from A into B such that size MXN becomes
NXM }
B[0,2]= A[0,1];
B[0,3]= A[0,3]
j=1; { J points to B 3-tuples }
for k= 1 to A[0,2] { k represents passes }
begin
for i=1 to A[0,3] { i is a pointer for A 3-tuples }
begin
if A[I,2]= k then
begin
B[j,1]= A[i,2];
B[j,2]= A[I,1];
B[j,3]= A[I,3];
J=j+1;
end
end
end
end
Program for Transpose matrix
Program TransposeMatrix()
A:array[1..30,1..30] of integers ;
B,C:array[0..30,1..3] of integers ;
i, j, m,n: integers;
begin
writeln(“enter size of matrix’);
read(m,n);
writeln(“enter elements into matrix”);
for I =1 to m do
for j = 1 to n do
read(A[I,j]);
createsparematrix(A,m,n,B);
Transpose(B,C);
writeln(“resultant of Transpose is as follows”);
for i=1 to C[0,3] do
begin
for j= 1 to 3 do
begin
write(C[i,j]);
end
writeln;
end
end
No comments:
Post a Comment