0% found this document useful (0 votes)
100 views65 pages

7.2 Graphs

The document provides information about solving problems on weighted graphs using greedy and edge-picking algorithms. It begins with an introduction to Hamiltonian circuits and weighted graphs. It then explains the greedy algorithm and provides an example of finding the shortest route between cities using this method. Next, it describes the edge-picking algorithm and works through another example. Finally, it provides exercises for students to practice applying these algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views65 pages

7.2 Graphs

The document provides information about solving problems on weighted graphs using greedy and edge-picking algorithms. It begins with an introduction to Hamiltonian circuits and weighted graphs. It then explains the greedy algorithm and provides an example of finding the shortest route between cities using this method. Next, it describes the edge-picking algorithm and works through another example. Finally, it provides exercises for students to practice applying these algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 65

Thought for the Day:

Psalm 32:7-8
“You are my hiding place, Oh Lord.
You will protect me from trouble and
surround me with songs of
deliverance. You will instruct me and
teach me in the way I should go. You
will counsel me and watch over me.”
Learning Outcomes:
At the end of this section, the students are expected to:

1.solve problems on weighted graphs by greedy


algorithm;
2.solve problems on weighted graphs by edge-
picking algorithm.
We have already looked at paths that use
every edge of a graph exactly once. In
some situations, we may be more
interested in paths that visit each vertex
once, regardless of whether all edges are
used or not.
For instance, consider the following example.
A photographer would like to travel across all
the roads shown on the following map.

The photographer will


rent a car that need
not be returned to the
same city, so the trip
can begin in any city.
Is it possible for the photographer to design a
trip that traverses all the roads exactly once?
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.
Definition 7.2.1 A Hamiltonian circuit is a path
that begins and ends at the same vertex, and
passes through each vertex of a graph exactly
once. A graph that contains a Hamiltonian circuit
is called a Hamiltonian.

Unfortunately, we do not have a straightforward


criterion to guarantee that a graph is Hamiltonian,
but we do have the following helpful theorem.
Example 7.2.1 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?
By the Dirac’s theorem, the graph is
Hamiltonian — 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.
Definition 7.2.2 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 7.2.1 (Note
that the length of an edge
does not necessarily
correlate to its weight.) Figure 7.2.1
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.
Example 7.2.2 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.
The various options
will be simpler to
analyze if we first
organize the
information in a
graph
We begin by
representing each city
by a vertex. And then
we 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.
cont’d
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 algorithms apply only to complete graphs
—graphs in which every possible edge is
drawn between vertices (without any multiple
edges).
For instance, the graph in
Figure 7.2.2 is a complete
graph with six vertices. The
circuits found by the
algorithms are not guaranteed
to have the smallest total
weight possible, but they are
often better than you would
find by trial and error.

Figure 7.2.2
The Greedy Algorithm:
1. Choose a vertex to start at, then travel along
the connected edge that has the smallest weight.
(If two or more edges have the same weight,
pick any).
2. After arriving at the next vertex, travel along
the edge of smallest weight that connects to a
vertex not yet visited. Continue this process until
you have visited all vertices.
3. Return to the starting vertex.
The greedy algorithm is so called because it has
us choose the “cheapest” option at every chance
we get.
Example 7.2.3 Use the greedy algorithm to
find a Hamiltonian circuit in the weighted graph
shown in Figure 7.2.3. Start at vertex A.

Figure 7.2.3
Begin at A. The weights
of the edges from A are
13, 5, 4, 15, and 8. The
smallest is 4. Connect
A to D.
At D, the edge with
the smallest weight
is DB.
Connect D to B.
At B, the edge with
the smallest weight
is BF. Connect B to
F.
At F, the edge with the
smallest weight, 7, is
FD. However, D has
already been visited.
Choose the next
smallest weight, edge
FE. Connect F to E.
At E, the edge with the
smallest weight whose
vertex has not been
visited is C. Connect E
to C.
All vertices have been
visited, so we are at
step 3 of the algorithm.
We return to the starting
vertex by connecting C
to A.
The Edge-Picking Algorithm:
1. Mark the edge of smallest weight in the graph.
(If two or more edges have the same weight, pick
any.)
2. Mark the edge of the next smallest weight in
the graph, provided it does not complete a circuit
and does not add a third marked edge to a single
vertex.
3. Continue this process until you can no longer
mark any edges. Then mark the final edge that
completes the Hamiltonian circuit.
Example 7.2.4 Use the edge-picking algorithm
to find a Hamiltonian circuit in Figure 7.2.3.

Figure 7.2.3
In Example 7.2.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
7.2.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.
Example 7.2.5 The cost of flying between
various European cities is shown in the following
table.
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?
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.
However, we cannot
use this edge, because
it would bring us to a
city we have already
seen. We can take the
next-smallest-weight
edge to Rome.
We cannot yet return
to London, so the next
available edge is to
Vienna, then to Berlin,
and finally back to
London.
If we use the edge-
picking algorithm,
the edges with the
smallest weights
that we can
highlight are
London–Paris and
Madrid–Paris.
There are no more
edges we can mark that
will meet the
requirements of the
algorithm, so we mark
the last edge to
complete the circuit,
Berlin–Madrid.
EXERCISE SET 7.2

1. Use the Dirac’s theorem to determine whether the following graph is


Hamiltonian or not.
2. Use the Greedy algorithm to find a low-cost route that visits each
vertex just once and starts and ends at vertex F.
3. Use the Edge-picking algorithm to find a low-cost route that visits
each vertex just once.
4. Jeff wants to tour Asia. He will start and end his journey in Tokyo and
visit Hongkong, Bangkok, Seoul, and Beijing. The airfares available to
him between cities are given in the table. Draw a weighted graph that
represents the travel costs between cities and use the greedy algorithm
to find a low-cost route.

Tokyo Hongkong Bangkok Seoul Beijing

Tokyo $845 $1275 $470 $880

Hongkong $845 $320 $515 $340

Bangkok $1275 $320 $520 $365

Seoul $470 $515 $520 $225

Beijing $880 $340 $365 $225


REFERENCES
1. Aufmann, R.N.(2018). Mathematics in the Modern World. Rex Book
Store, Inc.
2. Rosen, K. (2011). Discrete Mathematics and its Applications, Seventh
Edition. The McGraw Hill Companies.
3. Bondy, J. (1976). Graph Theory and with Applications. North Holland
Publishing Corporation. 
4. Daligdig, R.M. (2019). Mathematics in the Modern World. Lorimar
Publishing, Inc.
5. Carpio, J.N. and Peralta, B.D. (2018). Mathematics in the Modern World.
Books Atbp. Publishing Corp.
6. Olejan, R.O., Veloria, E.V., Bonghanoy, G.B., Ondaro, J.E.,and
Sumalinog, J.D. (2018). Mathematics in the Modern World. MUTYA
Publishing House, Inc.
7. Manlulu, E.A. and Hipolito, L.M. (2019). A Course Module for
Mathematics in the Modern World. Rex Book Store, Inc.

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