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.

vertices <strong>and</strong> m edges, an edge list or adjacency list representation uses O(n + m)<br />

space, whereas an adjacency matrix representation uses O(n 2 ) space.<br />

13.2.1 The Edge List Structure<br />

The edge list structure is possibly the simplest, though not the most efficient,<br />

representation of a graph G. In this representation, a vertex v of G stor<strong>in</strong>g an<br />

element o is explicitly represented by a vertex object. All such vertex objects are<br />

stored <strong>in</strong> a collection V, such as an array list or node list. If V is an array list, for<br />

example, then we naturally th<strong>in</strong>k of the vertices as be<strong>in</strong>g numbered.<br />

Vertex Objects<br />

The vertex object for a vertex v stor<strong>in</strong>g element o has <strong>in</strong>stance variables for:<br />

• A reference to o.<br />

• A reference to the position (or entry) of the vertex-object <strong>in</strong> collection V.<br />

The dist<strong>in</strong>guish<strong>in</strong>g feature of the edge list structure is not how it represents<br />

vertices, however, but the way <strong>in</strong> which it represents edges. In this structure, an<br />

edge e of G stor<strong>in</strong>g an element o is explicitly represented by an edge object. The<br />

edge objects are stored <strong>in</strong> a collection E, which would typically be an array list or<br />

node list.<br />

Edge Objects<br />

The edge object for an edge e stor<strong>in</strong>g element o has <strong>in</strong>stance variables for:<br />

• A reference to o.<br />

• References to the vertex objects associated with the endpo<strong>in</strong>t vertices of e.<br />

• A reference to the position (or entry) of the edge-object <strong>in</strong> collection E.<br />

Visualiz<strong>in</strong>g the Edge List Structure<br />

We illustrate an example of the edge list structure for a graph G <strong>in</strong> Figure 13.3.<br />

Figure 13.3: (a) A graph G; (b) schematic<br />

representation of the edge list structure for G. We<br />

visualize the elements stored <strong>in</strong> the vertex <strong>and</strong> edge<br />

799

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

Saved successfully!

Ooh no, something went wrong!