Fast Transpose Sparse Matrix
Fast Transpose Sparse Matrix
#include <stdio.h>
struct SparseMatrix {
};
rowTerms[mat[i].col]++;
startPos[0] = 1;
trans[pos].row = mat[i].col;
trans[pos].col = mat[i].row;
trans[pos].value = mat[i].value;
trans[0].row = mat[0].col;
trans[0].col = mat[0].row;
trans[0].value = numTerms;
int main() {
struct SparseMatrix mat[MAX] = {{3, 3, 3}, {0, 0, 1}, {1, 1, 2}, {2, 2, 3}};
printf("Original Matrix:\n");
printMatrix(mat);
fastTranspose(mat, trans);
printf("\nTransposed Matrix:\n");
printMatrix(trans);
return 0;
OUTPUT:
ALGORITHM:
Step 1:start
Read the matrix's dimensions and non-zero elements from the user.
Create an array rowTerms[] to store the count of how many non-zero elements are present in each
column of the matrix.
Traverse the sparse matrix and count how many non-zero elements are in each column.
Compute the starting positions for each column in the transposed matrix using the rowTerms[] array
and store them in the startPos[] array. The first column starts at index 1 (ignoring 0).
Step 7:stop.