10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

JA = (1, 4, 7, 10, 12, 12, 14)<br />

5. Storage‐by‐Rows<br />

The storage mode used for sparse matrices stored by rows has<br />

three variations, depending on whether the matrix is a general<br />

sparse matrix or a symmetric sparse matrix. This explains these<br />

variations.<br />

For a general sparse matrix A, storage‐by‐rows uses three one‐<br />

dimensional arrays to define the sparse matrix storage, AR, IA, and<br />

JA. Given the m by n sparse matrix A having ne nonzero elements,<br />

the arrays are set up as follows:<br />

• AR of (at least) length ne contains the ne nonzero elements of<br />

the sparse matrix A, stored contiguously. The rows of matrix<br />

A are stored consecutively from 1 to m in AR. The elements in<br />

each row of A are stored in any order in AR.<br />

• IA, an integer array of (at least) length m+1 contains the<br />

relative starting position of each row of matrix A in array AR;<br />

that is, each element IA(i) of the row pointer array indicates<br />

where row i begins in array AR. If all elements in row i are<br />

zero, then IA(i) = IA(i+1). The last element, IA(m+1), indicates<br />

the position after the last element in array AR, which is ne+<strong>1.</strong><br />

• JA, an integer array of (at least) length ne contains the<br />

corresponding column numbers of each nonzero element, aij,<br />

in matrix A.<br />

Consider the following as an example of a 6 by 6 general sparse<br />

matrix A and how it can be stored in arrays AR, IA, and JA.<br />

Given the following matrix A:<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 132 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!