Docsity

Sparse Matrices: Data Structures and Implementation, Slides of Computer Science

Partial preview of the text

Download Sparse Matrices: Data Structures and Implementation and more Slides Computer Science in PDF only on Docsity!

Abstract Data Types

Sparse Matrices

Sparse Matrices

−

−

0 0 0 15

0 4 0 0

12 5 0 0

0 0 11 0

Sparse matrices have a large number of zero

elements in proportion to the number of nonzero

elements.

Storing in n x n array will have a lot of wasted

space.

Alternative: circular lists storing only nonzero

elements.

Circular linked list

Linked Representation for Matrix

Sparse Matrix Data Structure

#define MAX_SIZE 50 /* size of largest matrix */ typedef enum {head, entry} tagfield; typedef struct matrix_node *matrix_pointer; typedef struct entry_node { int row; int col; int value; }; typedef struct matrix_node { matrix_pointer down; matrix_pointer right; tagfield tag; union { matrix_pointer next; entry_node entry; } u; }; matrix_pointer hdnode[MAX_SIZE];