Department of Computer and Information Science,
Sponsored Links
This presentation is the property of its rightful owner.
1 / 7

Department of Computer and Information Science, School of Science, IUPUI PowerPoint PPT Presentation


  • 41 Views
  • Uploaded on
  • Presentation posted in: General

Department of Computer and Information Science, School of Science, IUPUI. CSCI 240. Abstract Data Types Sparse Matrices. Dale Roberts, Lecturer IUPUI [email protected] Sparse Matrices. é. ù. 0. 0. 11. 0. ê. ú. 12. 5. 0. 0. ê. ú. -. ê.

Download Presentation

Department of Computer and Information Science, School of Science, IUPUI

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Department of Computer and Information Science,School of Science, IUPUI

CSCI 240

Abstract Data Types

Sparse Matrices

Dale Roberts, Lecturer

IUPUI

[email protected]


Sparse Matrices

é

ù

0

0

11

0

ê

ú

12

5

0

0

ê

ú

-

ê

ú

0

4

0

0

ê

ú

-

0

0

0

15

ë

û

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.


down

head

right

next

row

col

down

entry

right

value

Sparse Matrix Nodes

# of head nodes = # of rows + # of columns

head node

entry node

tag

j

i

aij

aij

tag is used to tell entry, head and aij nodes part


Linked Representation for Matrix

4

4

0

2

11

1

1

1

0

12

5

1

2

-4

3

3

-15

Circular linked list


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


Try creating your data for this matrix


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.


  • Login