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.

Analyz<strong>in</strong>g the Prim-Jarn ık Algorithm<br />

Let n <strong>and</strong> m denote the number of vertices <strong>and</strong> edges of the <strong>in</strong>put graph G,<br />

respectively. The implementation issues for the Prim-Jarník algorithm are similar<br />

to those for Dijkstra's algorithm. If we implement the adaptable priority queue Q<br />

as a heap that supports location-aware entries (Section 8.4.2), then we can extract<br />

the vertex u <strong>in</strong> each iteration <strong>in</strong> O(log n) time. In addition, we can update each<br />

D[z] value <strong>in</strong> O(log n) time, as well, which is a computation considered at most<br />

once for each edge (u,z). The other steps <strong>in</strong> each iteration can be implemented <strong>in</strong><br />

constant time. Thus, the total runn<strong>in</strong>g time is O((n +m) log n), which is O(m log<br />

n).<br />

Illustrat<strong>in</strong>g the Prim-Jarn ık Algorithm<br />

We illustrate the Prim-Jarn ık algorithm <strong>in</strong> Figures 13.21 through 13.22.<br />

Figure 13.21: An illustration of the Prim-Jarník MST<br />

algorithm. (Cont<strong>in</strong>ues <strong>in</strong> Figure 13.22.)<br />

861

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

Saved successfully!

Ooh no, something went wrong!