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 />

The concept of sparsity is useful in combinatorics and application areas such as<br />

network theory, of a low density of significant data or connections.<br />

Huge sparse matrices often appear in science or engineering when solving<br />

partial differential equations.<br />

When storing and manipulating sparse matrices on a computer, it is beneficial<br />

and often necessary to use specialized algorithms and data structures that take<br />

advantage of the sparse structure of the matrix. Operations <strong>using</strong> standard<br />

matrix structures and algorithms are slow and consume large amounts of<br />

memory when applied to large sparse matrices. Sparse data is by nature easily<br />

compressed, and this compression almost always results in significantly less<br />

memory usage. Indeed, some very large sparse matrices are impossible to<br />

manipulate with the standard algorithms.<br />

One example of such a sparse matrix format is the Yale Sparse Matrix Format. It<br />

stores an initial sparse m×n matrix, M, in row form <strong>using</strong> three one‐dimensional<br />

arrays. Let NNZ denote the number of nonzero entries of M. The first array is A,<br />

which is of length NNZ, and holds all nonzero entries of M in left‐to‐right top‐to‐<br />

bottom (row‐major) order. The second array is IA, which is of length m + 1 (i.e.,<br />

one entry per row, plus one). IA(i) contains the index in A of the first nonzero<br />

element of row i. Row i of the original matrix extends from A(IA(i)) to A(IA(i+1)‐<br />

1), i.e. from the start of one row to the last index before the start of the next.<br />

The third array, JA, contains the column index of each element of A, so it also is<br />

of length NNZ.<br />

For example, the matrix<br />

[ 1 2 0 0 ]<br />

[ 0 3 9 0 ]<br />

[ 0 1 4 0 ]<br />

is a three‐by‐four matrix with six nonzero elements, so<br />

A = [ 1 2 3 9 1 4 ] // List of non‐zero matrix element in order<br />

IA = [ 1 3 5 7 ] // IA(i) = Index of the first nonzero element of row i in A<br />

JA = [ 1 2 2 3 2 3 ] // JA(i) = Column position of the non zero element A(i)<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

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

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

Saved successfully!

Ooh no, something went wrong!