15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

378<br />

Understanding Graphs<br />

An undirected graph<br />

3<br />

5<br />

2<br />

6<br />

3 8<br />

9<br />

Figure 5-3:<br />

The three<br />

types of<br />

graphs.<br />

A directed graph<br />

1<br />

7<br />

A weighted graph<br />

You can also combine weights with direction and create a directed, weighted<br />

graph.<br />

Uses <strong>for</strong> graphs<br />

Graphs are used to model a variety of real-world problems, such as finding<br />

the most efficient way to route e-mail through a computer network to finding<br />

the shortest way <strong>for</strong> airplanes to travel to different cities. Molecular biologists<br />

even use graphs to model the structure of molecules.<br />

Designing a single path with the Seven Bridges of Königsberg<br />

One of the first uses <strong>for</strong> graphs appeared in 1736 in a problem known as the<br />

Seven Bridges of Königsberg. The question was whether it was possible to<br />

walk across all seven bridges of Königsberg exactly once, as shown in<br />

Figure 5-4.

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

Saved successfully!

Ooh no, something went wrong!