0% found this document useful (0 votes)
998 views24 pages

6.2 - Weighted Graphs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
998 views24 pages

6.2 - Weighted Graphs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

4/19/21

CHAPTER

6
The Mathematics
of Graphs

Copyright © Cengage Learning. All rights reserved.

6.2
Section Weighted Graphs

Copyright © Cengage Learning. All rights reserved.

1
4/19/21

Hamiltonian Circuits

We have already looked at paths that use every edge of a


graph exactly once.

A circuit that uses every edge, but never uses the same
edge twice, is called an Euler circuit. (The path may
cross through vertices more than once.)

Path B–D–F–G–H–E–C–B–A–D–G–E–B in Figure 5.5 is


an Euler circuit.

2
4/19/21

Hamiltonian Circuits
In some situations we may be more interested in paths
that visit each vertex once, regardless of whether all
edges are used or not.

Hamiltonian Circuits

Is it possible to visit each


city once and return to the
starting city without visiting
any city twice?

If our priority is to visit each city, we could travel along the


route A–B–C–D–E–F–G–A (abbreviating the cities).

This path visits each vertex once and returns to the starting
vertex without visiting any vertex twice. This type of path is
called a Hamiltonian circuit. 6

3
4/19/21

Hamiltonian Circuits

Unfortunately we do not have a straightforward criterion to


guarantee that a graph is Hamiltonian, but we do have the
following helpful theorem.

We must be careful, however; if our graph does not meet


the requirements of this theorem, it still might be
Hamiltonian.
7

Example 1 – Apply Dirac’s Theorem


The following graph shows the available flights of a small
airline. An edge between two vertices in the graph means
that the airline has direct flights between the two
corresponding cities. Apply Dirac’s theorem to verify that
the following graph is Hamiltonian. Then find a Hamiltonian
circuit. What does the Hamiltonian circuit represent in
terms of flights?

4
4/19/21

Example 1 – Solution

There are six vertices in the graph, so n = 6, and every vertex has a
degree of at least n/2 = 3.

By Dirac’s theorem, the graph is Hamiltonian. This means that the


graph contains a circuit that visits each vertex once and returns to the
starting vertex without visiting any vertex twice.

By trial and error, one Hamiltonian circuit is Portland–Boise–Butte–Salt


Lake City–Reno–Sacramento–Portland, which represents a sequence
of flights that visits each city and returns to the starting city without
visiting any city twice.
9

Answer: The graph has seven vertices, so n=7 and n/2 = 3.5. Several vertices
are of degree less than n/2, so Dirac’s theorem does not apply. Still, a routing
for the document may be possible.

By trial and error, one such route is Los Angeles–New York–Boston–Atlanta–


Dallas–Phoenix–San Francisco– Los Angeles. 10

10

5
4/19/21

Weighted Graphs

11

11

Weighted Graphs
A weighted graph is a graph in which each edge is
associated with a value, called a weight. The value can
represent any quantity we desire.

In the case of distances


between cities, we can
label each edge with the
number of miles between
the corresponding cities,
as in Figure 5.9.
Figure 5.9

(Note that the length of an edge does not necessarily correlate to its weight.)
12

12

6
4/19/21

Weighted Graphs
For each Hamiltonian circuit in the weighted graph, the sum
of the weights along the edges traversed gives the total
distance traveled along that route.

We can then compare different routes and find the one that
requires the shortest total distance. This is an example of a
famous problem called the traveling salesman problem. 13

13

Example 2 – Find Hamiltonian Circuits in a Weighted Graph

The table below lists the distances in miles between six


popular cities that a particular airline flies to. Suppose a
traveler would like to start in Chicago, visit the other five
cities this airline flies to, and return to Chicago. Find three
different routes that the traveler could follow, and find the
total distance flown for each route.

14

14

7
4/19/21

Example 2 – Solution
The various options will be simpler to analyze if we first
organize the information in a graph. Begin by letting each
city be represented by a vertex. Draw an edge between two
vertices if there is a flight between the corresponding cities,
and label each edge with a weight that represents the
number of miles between the two cities.

15

15

Example 2 – Solution
cont’d
A route that visits each city just once corresponds to a
Hamiltonian circuit.

Beginning at Chicago, one such circuit is Chicago–New York–


Dallas–Philadelphia–Atlanta– Washington, D.C.–Chicago.

By adding the weights of


each edge in the circuit,
we see that the total
number of miles traveled
is

713 + 1374 + 1299 + 670 + 544 + 597 = 5197


16

16

8
4/19/21

Example 2 – Solution cont’d


By trial and error, we can identify two additional routes. One is
Chicago–Philadelphia–Dallas–Washington, D.C.–Atlanta–
New York–Chicago.
The total weight of the circuit is
665 + 1299 + 1185 + 544 + 748 + 713 = 5154

A third route is Chicago–Washington, D.C.–Dallas–New


York–Atlanta–Philadelphia–Chicago.

The total mileage is


597 + 1185 + 1374 + 748 + 670 + 665 = 5239

17

17

18

18

9
4/19/21

Find two different routes that visit


each location once and returns to
the Moscone Center and compare
the total travel times.

19

19

Possible Hamiltonian Circuits


#1. Moscone Center–Civic Center–Union Square–
Fisherman’s Wharf–Coit Tower–Embarcadero Plaza–
Moscone Center.
Total travel time: 18 +14+28+14+18+22=114.

#2. Moscone Center–Union Square–


Embarcadero Plaza–Coit Tower–
Fisherman’s Wharf–Civic Center–
Moscone Center
Total travel time:
6+24+18+14+33+18= 113.

20

20

10
4/19/21

Algorithms in Complete Graphs

21

21

Algorithms in Complete Graphs


There is no known shortcut for finding the optimal
Hamiltonian circuit in a weighted graph. There are,
however, two algorithms, the greedy algorithm and the
edge-picking algorithm, that can be used to find a pretty
good solution.

Both of these algorithms apply only to complete graphs—


graphs in which every possible edge is drawn between
vertices (without any multiple edges).

22

22

11
4/19/21

Algorithms in Complete Graphs


For instance, the graph in Figure 5.10 is a complete graph
with six vertices. The circuits found by the greedy
algorithm and the edge-picking algorithm are NOT
guaranteed to have the smallest total weight possible, but
they are often better than you would find by trial and error.

Figure 5.10

23

23

Algorithms in Complete Graphs

The greedy algorithm is so called because it has us


choose the “cheapest” option at every chance we get.

24

24

12
4/19/21

Example 3 – The Greedy Algorithm


Use the greedy algorithm to find a Hamiltonian circuit in the
weighted graph shown in Figure 5.11. Start at vertex A.

Figure 5.11

25

25

Example 3 – Solution
Begin at A. The weights of the At D, the edge with the
edges from A are 13, 5, 4, 15, smallest weight is DB.
and 8. The smallest is 4. Connect D to B.
Connect A to D.

26

26

13
4/19/21

cont’d

At F, the edge with the smallest


weight, 7, is FD. However, D has
already been visited. Choose the
At B, the edge with next smallest weight, edge FE.
the smallest weight is Connect F to E.
BF. Connect B to F.

27

27

cont’d

All vertices have been


visited, so we are at step 3
At E, the edge with the of the algorithm. We return
smallest weight whose to the starting vertex by
vertex has not been visited connecting C to A.
is C. Connect E to C.

28

28

14
4/19/21

Example 3 – Greedy Algorithm cont’d

The Hamiltonian circuit is A–D–B–F–E–C–A.

The weight of the circuit is 4 + 2 + 5 + 10 + 6 + 15 = 42

29

29

Check your progress #3


Use the greedy algorithm to find a Hamiltonian circuit
starting at vertex A in the weighted graph shown below.

Answer: A-D-C-B-E-A
Total weight: 26
30

30

15
4/19/21

Algorithms in Complete Graphs

31

31

Example 4 – The Edge-Picking Algorithm

Use the edge-picking algorithm to find a Hamiltonian circuit


in Figure 5.11.

Figure 5.11

32

32

16
4/19/21

Example 4 – Solution
The edge of next
smallest weight is AD
with weight 4.
We first highlight the edge of
smallest weight, namely BD
with weight 2.

33

33

Example 4 – Solution cont’d

The next smallest weight There are two edges of weight


is 5, which appears twice, 6 (the next smallest weight),
with edges AE and FB. BC and EC. We cannot use BC
We can mark both of them. because it would add a third
marked edge to vertex B. We
mark edge EC.

34

34

17
4/19/21

Example 4 – Solution cont’d

We are now at step 3 of the


algorithm; any edge we mark
will either complete a circuit or add
a third edge to a vertex. So we
mark the final edge to complete the
Hamiltonian circuit, edge FC.
35

35

Example 4 – Edge-Picking Algorithm cont’d

Beginning at vertex A, the Hamiltonian circuit is


A–D–B–F–C–E–A. (In the reverse direction, an equivalent
circuit is A–E–C–F–B–D–A.)
The total weight of the circuit is
4 + 2 + 5 + 14 + 6 + 5 = 36
36

36

18
4/19/21

Check your progress #3


Use the edge-picking algorithm to find a Hamiltonian circuit
in the weighted graph shown below.

Answer: A-D-C-B-E-A
Total weight: 26
37

37

Applications of Weighted Graphs

38

38

19
4/19/21

Applications of Weighted Graphs


In Example 2, we examined distances between cities. This
is just one example of a weighted graph; the weight of an
edge can be used to represent any quantity we like. For
example, a traveler might be more interested in the cost of
flights than the time or distance between cities.

If we labeled each edge of the graph in Example 2 with the


cost of traveling between the two cities, the total weight of a
Hamiltonian circuit would be the total travel cost of the trip.

39

39

Example 5 – An Application of the Greedy and Edge-Picking Algorithms


For example, a traveler might be more interested in the cost of flights
between cities. If we labeled each edge of the graph with the cost of
traveling between the two cities, the total weight of a Hamiltonian circuit
would be the total travel cost of the trip.

The cost of flying between various European cities is shown in the


following table.

40

40

20
4/19/21

Example 5 – An Application of the Greedy and Edge-Picking Algorithms


cont’d

Use both the greedy algorithm and the edge-picking


algorithm to find a low-cost route that visits each city just
once and starts and ends in London. Which route is more
economical?

41

41

Example 5 – Solution
First we draw a weighted graph with vertices representing
the cities and each edge labeled with the price of the flight
between the corresponding cities.

42

42

21
4/19/21

Example 5 – Solution A cont’d


To use the greedy algorithm, start at London and travel
along the edge with the smallest weight.

Answer: L – P – M – R – V – B - L
Total airfare for the trip, is
160 + 215 + 380 + 480 + 375 + 325 = $1935 43

43

Example 5 – Solution #2 cont’d

If we use the edge-picking algorithm, the edges with the


smallest weights that we can highlight first is London–Paris.

Answer: The resulting route is London–Paris–Madrid–Berlin–Vienna–


Rome–London, for a total cost of
160 + 215 + 675 + 375 + 480 + 280 = $2185
(We could also travel this route in the reverse order.) 44

44

22
4/19/21

45

45

Answer

46

46

23
4/19/21

47

47

Exercise
Page 241 Page 255
A map of a park is shown with bridges 1. Use the greedy algorithm to
connecting islands in a river to the find a Hamiltonian circuit
banks. starting at vertex A in the
weighted graph.
a. Represent the map as a graph.
b. Is it possible to take a walk that
2. Use the edge-picking
crosses each bridge once and
algorithm to find a Hamiltonian
returns to the starting point without
circuit in the indicated graph.
crossing any bridge twice? Justify
your answer.

48

48

24

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy