Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data structures for dynamic large sparse matrix in C [closed]

what's the best suitable data structure to use in C for sparse dynamic matrix. I know about the Yale format but it's for static matrices. I need to be able to add rows column and values in it.

like image 630
Random Avatar asked Jun 15 '26 20:06

Random


1 Answers

In general, an array of linked lists. If most of the operations are row-based, each list represent a row, otherwise, each list represent a column. You can get more info here

 typedef struct matrix { 
    node**  rowList;     // rowList is a pointer to the array of rows 
    node** columnList; // column list is a pointer to the array of columns. 
    int  rows, columns;  // store the number of rows and columns of the matrix 
 } matrix


 typedef struct node { 
    int row, column, 
    double value; 
    struct node*  rowPtr; 
    struct node*  colPtr; 
 } node;
like image 70
UmNyobe Avatar answered Jun 21 '26 19:06

UmNyobe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!