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.

depend on the implementation of the underly<strong>in</strong>g map. However, most algorithms<br />

use a small constant number of decorations. Thus, the decorable position methods<br />

will run <strong>in</strong> O(1) worst-case time no matter how we implement the embedded map.<br />

Code Fragment 13.2: An <strong>in</strong>terface def<strong>in</strong><strong>in</strong>g an ADT<br />

for decorable positions. Note that we don't use<br />

generic parameterized types for the <strong>in</strong>herited Map<br />

methods, s<strong>in</strong>ce we don't know <strong>in</strong> advance the types of<br />

the decorations <strong>and</strong> we want to allow for objects of<br />

many different types as decorations.<br />

Us<strong>in</strong>g decorable positions, the complete DFS traversal algorithm can be described<br />

<strong>in</strong> more detail, as shown <strong>in</strong> Code Fragment 13.3.<br />

Code Fragment 13.3: DFS on a graph with<br />

decorable edges <strong>and</strong> vertices.<br />

A Generic DFS Implementation <strong>in</strong> <strong>Java</strong><br />

815

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

Saved successfully!

Ooh no, something went wrong!