11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 12.2 M<strong>at</strong>rix Represent<strong>at</strong>ions 411Cols0 1 3 6Rows00,0 0,1 0,610 231910,3 1,1 1,345 5 9340,44077,1 7,3 7,632 12 7Figure 12.7 The orthogonal list sparse m<strong>at</strong>rix represent<strong>at</strong>ion.the sparse m<strong>at</strong>rix requires. The size of the sparse m<strong>at</strong>rix depends on the numberof non-zero elements (we will refer to this value as NNZ), while the size of thest<strong>and</strong>ard m<strong>at</strong>rix represent<strong>at</strong>ion does not vary. We need to know the (rel<strong>at</strong>ive) sizesof a pointer <strong>and</strong> a d<strong>at</strong>a value. For simplicity, our calcul<strong>at</strong>ion will ignore the spacetaken up by the row <strong>and</strong> column header (which is not much affected by the numberof elements in the sparse array).As an example, assume th<strong>at</strong> a d<strong>at</strong>a value, a row or column index, <strong>and</strong> a pointereach require four bytes. An n × m m<strong>at</strong>rix requires 4nm bytes. The sparse m<strong>at</strong>rixrequires 28 bytes per non-zero element (four pointers, two array indices, <strong>and</strong> oned<strong>at</strong>a value). If we set X to be the percentage of non-zero elements, we can solvefor the value of X below which the sparse m<strong>at</strong>rix represent<strong>at</strong>ion is more spaceefficient. Using the equ<strong>at</strong>ion28X = 4mn<strong>and</strong> solving for X, we find th<strong>at</strong> the sparse m<strong>at</strong>rix using this implement<strong>at</strong>ion is morespace efficient when X < 1/7, th<strong>at</strong> is, when less than about 14% of the elements

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

Saved successfully!

Ooh no, something went wrong!