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.

transitive closure<br />

of G by <strong>in</strong>crementally comput<strong>in</strong>g a<br />

series of digraphs , ,..., , where for k = 1,..., n.<br />

This description is actually an example of an algorithmic design pattern known as<br />

dynamic programm<strong>in</strong>g, which is discussed <strong>in</strong> more detail <strong>in</strong> Section 12.5.2. From<br />

the description <strong>and</strong> analysis above we may immediately derive the follow<strong>in</strong>g<br />

proposition.<br />

Proposition 13.19: Let be a digraph with n vertices, <strong>and</strong> let be<br />

represented by a data structure that supports lookup <strong>and</strong> update of adjacency<br />

<strong>in</strong>formation <strong>in</strong> O(1) time. Then the Floyd-Warshall algorithm computes the<br />

transitive closure of <strong>in</strong> O(n 3 ) time.<br />

We illustrate an example run of the Floyd-Warshall algorithm <strong>in</strong> Figure 13.10.<br />

Figure 13.10: Sequence of digraphs computed by the<br />

Floyd-Warshall algorithm: (a) <strong>in</strong>itial digraph =<br />

<strong>and</strong> number<strong>in</strong>g of the vertices; (b) digraph ; (c) ,<br />

(d) ; (e) ; (f) . Note that = = . If<br />

digraph has the edges (v i ,v k ) <strong>and</strong> (v k , v j ), but not<br />

the edge (vi, vj), <strong>in</strong> the draw<strong>in</strong>g of digraph we show<br />

834

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

Saved successfully!

Ooh no, something went wrong!