Presentation is loading. Please wait.

Presentation is loading. Please wait.

Abstract Data Types Sparse Matrices CSCI 240

Similar presentations


Presentation on theme: "Abstract Data Types Sparse Matrices CSCI 240"— Presentation transcript:

1 Abstract Data Types Sparse Matrices CSCI 240
Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Sparse Matrices Dale Roberts, Lecturer IUPUI

2 Sparse Matrices ú û ù ê ë é - 15 4 5 12 11
4 5 12 11 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.

3 tag is used to tell entry, head and aij nodes part
Sparse Matrix Nodes # of head nodes = # of rows + # of columns down head right next head node down entry right value row col entry node tag i j aij aij tag is used to tell entry, head and aij nodes part

4 Linked Representation for Matrix
4 4 2 11 1 1 1 12 5 2 1 -4 3 3 -15 Circular linked list

5 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];

6 Try creating your data for this matrix

7 Acknowledgements All of this code is from Horowitz, Sahni, and Anderson-Freed, Fundamentals of Data Structures in C. Some slides were originally developed by Chen, Hsin-His.


Download ppt "Abstract Data Types Sparse Matrices CSCI 240"

Similar presentations


Ads by Google