15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Understanding Graphs 379<br />

Figure 5-4:<br />

The Seven<br />

Bridges of<br />

Königsberg<br />

represented<br />

as a graph.<br />

The seven bridges of Konigsberg<br />

The seven bridges of Konigsberg<br />

represented as a graph<br />

A mathematician named Leonhard Euler used a graph to prove that this was<br />

impossible. In the seven bridges problem, one node has five bridges leading<br />

to it (5 degrees) while the other three nodes only have three bridges leading<br />

to it (3 degrees). Euler proved that the only way you could cross every<br />

bridge exactly once was if a graph had, at the most, two nodes with an odd<br />

number of bridges (degrees), and each odd-numbered degree node had to be<br />

the starting and ending point.<br />

Although solving a problem of walking across a bridge exactly once might<br />

seem trivial, knowing how to solve this problem can help design truck or airplane<br />

routes as efficiently as possible.<br />

Finding the shortest path through a graph<br />

After using Euler’s proof to design a graph that can be traversed in a single<br />

path, graph theory can now help you find the shortest path through that<br />

graph.<br />

Book III<br />

Chapter 5<br />

Graphs and Trees<br />

This problem, dubbed the Chinese Postman problem after the Chinese mathematician<br />

Mei-Ko Kuan, involves finding the shortest route a postman can<br />

travel to visit every node in a graph.<br />

The answer to this problem can help airlines choose the shortest routes <strong>for</strong><br />

each airplane route to visit multiple cities. The shorter the route, the less<br />

fuel needed and the lower the operating costs. Another use <strong>for</strong> the Chinese<br />

Postman problem is finding the most efficient way to route e-mail from one<br />

computer to another. In both cases, one node in the graph is the starting<br />

point and a different node is the ending point.

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

Saved successfully!

Ooh no, something went wrong!