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.

The ma<strong>in</strong> computation of Dijkstra's algorithm is performed by method dijkstra<br />

Visit. An adaptable priority queue Q support<strong>in</strong>g location-aware entries (Section<br />

8.4.2) is used. We <strong>in</strong>sert a vertex u <strong>in</strong>to Q with method <strong>in</strong>sert, which returns the<br />

location-aware entry of u <strong>in</strong> Q. We "attach" to u its entry <strong>in</strong> Q by means of<br />

method setEntry, <strong>and</strong> we retrieve the entry of u by means of method getEntry.<br />

Note that associat<strong>in</strong>g entries to the vertices is an <strong>in</strong>stance of the decorator design<br />

pattern (Section 13.3.2). Instead of us<strong>in</strong>g an additional data structure for the labels<br />

D[u], we exploit the fact that D[u] is the key of vertex u <strong>in</strong> Q, <strong>and</strong> thus D[u] can<br />

be retrieved given the entry for u <strong>in</strong> Q. Chang<strong>in</strong>g the label of a vertex z to d <strong>in</strong> the<br />

relaxation procedure corresponds to call<strong>in</strong>g method replaceKey(e,d), where e is<br />

the location-aware entry for z <strong>in</strong> Q.<br />

851

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

Saved successfully!

Ooh no, something went wrong!