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.

computers. In this case, it is probably not appropriate for all the edges to be equal to<br />

each other, for some connections <strong>in</strong> a computer network are typically much faster<br />

than others (for example, some edges might represent slow phone-l<strong>in</strong>e connections<br />

while others might represent high-speed, fiber-optic connections). Likewise, we<br />

might want to use a graph to represent the roads between cities, <strong>and</strong> we might be<br />

<strong>in</strong>terested <strong>in</strong> f<strong>in</strong>d<strong>in</strong>g the fastest way to travel cross-country. In this case, it is aga<strong>in</strong><br />

probably not appropriate for all the edges to be equal to each other, for some <strong>in</strong>tercity<br />

distances will likely be much larger than others. Thus, it is natural to consider graphs<br />

whose edges are not weighted equally.<br />

A weighted graph is a graph that has a numeric (for example, <strong>in</strong>teger) label w(e)<br />

associated with each edge e, called the weight of edge e. We show an example of a<br />

weighted graph <strong>in</strong> Figure 13.13.<br />

Figure 13.13: A weighted graph whose vertices<br />

represent major U.S. airports <strong>and</strong> whose edge weights<br />

represent distances <strong>in</strong> miles. This graph has a path from<br />

JFK to LAX of total weight 2,777 (go<strong>in</strong>g through ORD <strong>and</strong><br />

DFW). This is the m<strong>in</strong>imum weight path <strong>in</strong> the graph<br />

from JFK to LAX.<br />

In the rema<strong>in</strong><strong>in</strong>g sections of this chapter, we study weighted graphs.<br />

13.6 Shortest Paths<br />

Let G be a weighted graph. The length (or weight) of a path is the sum of the weights<br />

of the edges of P. That is, if P = ((v 0 ,v 1 ),(v 1 ,v 2 ), ..., (vk −1 ,vk)), then the length of P,<br />

denoted w(P), is def<strong>in</strong>ed as<br />

841

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

Saved successfully!

Ooh no, something went wrong!