23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Performance of the Adjacency Matrix Structure<br />

For graphs with parallel edges, the adjacency matrix representation must be<br />

extended so that, <strong>in</strong>stead of hav<strong>in</strong>g A [i, j] stor<strong>in</strong>g a po<strong>in</strong>ter to an associated edge<br />

(v, w), it must store a po<strong>in</strong>ter to an <strong>in</strong>cidence collection I(v, w), which stores all<br />

the edges from v to w. S<strong>in</strong>ce most of the graphs we consider are simple, will not<br />

consider this complication here.<br />

The (simple) adjacency matrix A allows us to perform method areAdjacent(v,<br />

w) <strong>in</strong> O(1) time. We achieve this runn<strong>in</strong>g time by access<strong>in</strong>g vertices v <strong>and</strong> w to<br />

determ<strong>in</strong>e their respective <strong>in</strong>dices i <strong>and</strong> j, <strong>and</strong> then test<strong>in</strong>g if A[i, j] is null or<br />

806

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

Saved successfully!

Ooh no, something went wrong!