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

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

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

All of the methods of the graph ADT that can be implemented with the edge list<br />

structure <strong>in</strong> O(1) time can also be implemented <strong>in</strong> O(1) time with the adjacency<br />

list structure, us<strong>in</strong>g essentially the same algorithms. In addition, be<strong>in</strong>g able to<br />

provide access between vertices <strong>and</strong> edges <strong>in</strong> both directions allows us to speed<br />

up the performance of a number of the graph methods by us<strong>in</strong>g an adjacency list<br />

structure <strong>in</strong>stead of an edge list structure. Table 13.2 summarizes the performance<br />

of the adjacency list structure implementation of a graph, assum<strong>in</strong>g that<br />

collections V <strong>and</strong> E <strong>and</strong> the <strong>in</strong>cidence collections of the vertices are all<br />

implemented with doubly l<strong>in</strong>ked lists. For a vertex v, the space used by the<br />

<strong>in</strong>cidence collection of v is proportional to the degree of v, that is, it is O(deg(v)).<br />

Thus, by Proposition 13.6, the space requirement of the adjacency list structure is<br />

O(n + m).<br />

Table 13.2: Runn<strong>in</strong>g times of the methods of a<br />

graph implemented with the adjacency list structure.<br />

The space used is O(n + m), where n is the number of<br />

vertices <strong>and</strong> m is the number of edges.<br />

Operation<br />

Time<br />

vertices<br />

O(n)<br />

edges<br />

O(m)<br />

endVertices, opposite<br />

O(1)<br />

<strong>in</strong>cidentEdges(v)<br />

O(deg(v))<br />

areAdjacent(v,w)<br />

O(m<strong>in</strong>(deg(v),deg(w))<br />

replace<br />

O(1)<br />

804

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

Saved successfully!

Ooh no, something went wrong!