12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

428 Chap. 12 Lists <strong>and</strong> Arrays RevisitedCols0 1 3 6Rows0A 00 A 06A 011A 11 A 13A 764A 40A 717Figure 12.7 The orthogonal list sparse matrix representation.One approach <strong>to</strong> representing a sparse matrix is <strong>to</strong> concatenate (or otherwisecombine) the row <strong>and</strong> column coordinates in<strong>to</strong> a single value <strong>and</strong> use this as a keyin a hash table. Thus, if we want <strong>to</strong> know the value of a particular position in thematrix, we search the hash table for the appropriate key. If a value for this positionis not found, it is assumed <strong>to</strong> be zero. This is an ideal approach when all queries <strong>to</strong>the matrix are in terms of access by specified position. However, if we wish <strong>to</strong> findthe first non-zero element in a given row, or the next non-zero element below thecurrent one in a given column, then the hash table requires us <strong>to</strong> check sequentiallythrough all possible positions in some row or column.Another approach is <strong>to</strong> implement the matrix as an orthogonal list, as illustratedin Figure 12.7. Here we have a list of row headers, each of which containsa pointer <strong>to</strong> a list of matrix records. A second list of column headers also containspointers <strong>to</strong> matrix records. Each non-zero matrix element s<strong>to</strong>res pointers <strong>to</strong>its non-zero neighbors in the row, both following <strong>and</strong> preceding it. Each non-zero

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

Saved successfully!

Ooh no, something went wrong!