Graph Theory Part II For Students
Graph Theory Part II For Students
Part II
Hamiltonian Circuits
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.
Remember!!!
Circuit – begins and ends at the same vertex
Euler Circuit – uses every EDGE once
Hamiltonian Circuit – passes through each VERTEX once
Dirac’s Theorem
Unfortunately there is no straight forward criterion to guarantee that a graph is
Hamiltonian, but Dirac’s Theorem may be useful.
Dirac’s Theorem
Consider a connected graph with at least three vertices and no multiple edges (two or
more edges connect the same vertices). Let n be the number of vertices in the graph. If
every vertex has degree of at least n/2, then the graph must be Hamiltonian.
Example 1
The 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 graph is Hamiltonian. Then find a Hamiltonian
circuit. What does the Hamiltonian circuit represent in
terms of flights?
There are 6 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. 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.
Weighted Graphs
A weighted graph is a graph in which each edge is associated with a weight. The value
can represent any quantity desired.
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. Routes may be
compared and find the one that requires the shortest total distance. This is an example
of a famous problem called the traveling salesman problem.
Traveling Salesman Problem
A problem vexes a traveling salesman who has to visit each city exactly once before returning
to his starting point. The salesman wants to take the shortest available route through the
cities, and the problem is simply to identify it. But if the salesman is allowed to pass through
the same city twice, even along the same road twice, as long as it provides him the shortest
route, the problem is now referred to as the practical traveling salesman problem.
Find the shortest tour that starts at city P, visit each other city exactly
once, and returns to city P.
PRQSP 2 + 3 + 6 + 8 = 19
PQSRP 10 + 6 + 2 + 2 = 20 Routes PQRSP and PSRQP results in
PSRQP 8 + 2 + 3 + 10 = 23 the shortest Hamiltonian circuit with a
PRSQP 2 + 2 + 6 + 10 = 20 total length of 19.
PSQRP 8 + 6 + 3 + 2 = 19
PQRSP 10 + 3 + 2 + 8 = 23
Example 2
Supply what is asked in each item. The weights
refer to the distance between six popular cities
that a particular airline flies to.
I. Determine the length covered using the
following routes:
a. Chicago-New York-Dallas-Philadelphia-Atlanta-Washington, D.C.-Chicago
713 + 1374 + 1299 + 670 + 544 + 597 = 5197
b. Chicago-Philadelphia-Dallas-Washington, D.C.-Atlanta-New York-Chicago
665 + 1299 + 1185 + 544 + 748 + 713 = 5154
II. Considering all possible routes, is there an easier way of possibly determining the shortest
route?
Yes, an algorithm may be used. However, there is no known shortcut for finding the
optimal Hamiltonian circuit in a weighted graph.
Greedy Algorithm
This algorithm is only applicable for complete graph. The following steps must be
observed:
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 one.)
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.
Example 3
Use the greedy algorithm to find a 1. Begin at A. The smallest weight is 4.
Hamiltonian circuit in the weighted Connect A to D.
graph provided. Start at vertex A. 2. At D, the edge with the smallest
weight is DB. Connect D to B.
3. At B, the edge with the smallest
weight is BF. Connect B to F.
4. At F, the vertices left are E and C. The
smallest weight is FE. Connect F to E.
5. At E, the only vertex to connect is
C. Then at C, connect to A.
The weight of the Hamiltonian circuit A-
D-B-F-E-C-A is 4 + 2 + 5 + 10 + 6 + 15 = 42.
Edge-Picking Algorithm
This algorithm is only applicable for complete graph. The following steps must be
observed:
1. Mark the edge of the smallest weight in the graph. (if two or more edges have the
same weight, pick any one.)
2. Mark the edge of the next smallest weight in the graph, as long as it does not
complete a circuit and does not add a third marked edge to a single vertex.
3. Continue this process until no edge can be marked any longer. Then, mark the final
edge that completes the Hamiltonian circuit.
Example 4
1. Highlight edge of smallest weight – BD (2)
Use the edge-picking algorithm to find a
Hamiltonian circuit in the weighted 2. The edge of next smallest weight is AD (4).
graph provided. Start at vertex A. 3. The next smallest weight is 5, which
appears twice, AE and FB. Mark both.
4. There are two edges of weight 6. We
cannot mark BC because it would add a
third marked edge to B. Mark only EC.
5. Examining the next smallest weights
would lead to a 3rd marked edge for a
vertex. So, mark the final edge to complete
the Hamiltonian circuit, FC.
The weight of the Hamiltonian circuit A-
D-B-F-C-E-A is 4 + 2 + 5 + 14 + 6 + 5 = 36.
The Chinese Postman Problem
The problem is named not because the postman is Chinese but because the problem was first
seriously studied by Chinese Mathematician Mei-ko Kwan in the 1960s. All edges must be
traversed.
An algorithm for the solution of the Chinese postman problem exists, but is too complicated
to discuss. Instead, a much simpler partial algorithm that will work reasonably well in most
cases observes the following conditions:
1. Find the degree of each vertex of the graph.
2. (a) If all the vertices are of even degree, an Euler circuit which is an acceptable shortest
route exists.
(b) If exactly two vertices are of odd degree, use Dijkstra’s algorithm to find the shortest
path between them. The postman must traverse these edges twice and the others once.
(c) If more than two vertices are of odd degree, this partial algorithm fails. Try looking for
the shortest combination of paths between pairs of them. These are the edges that the
postman must cover twice.
Dijkstra’s Algorithm
1. Label the initial vertex as 0.
2. Box this number (permanent label).
3. Label each vertex connected to the initial vertex wit its weight/distance (temporary
label).
4. Box the smallest number.
5. From the vertex, consider the distance to each connected vertex.
6. If a distance is less than the one already indicated at this vertex, cross out the old
distance and write the new distance. If there is no distance at the vertex, write down
the new one.
7. Repeat from step 4 until the destination vertex is boxed.
4 7
Example 5
What is the length of the shortest path 0 6
between Q and T in the graph?
1. Label Q as 0.
2. Box this number. 2 5
3. Label R as 4 and V as 2.
4. Box the smaller number which is 2 at V. 4. Box the smaller number which is 5 at U.
5. From V, the only connected vertex is U. 5. From U, the only connected vertex is T. Its
Its distance from Q is 5 (2 + 3). distance from Q is 6 (5 + 1).
4. Box the smaller number which is 4 at R. 6. Write 6 at T.
5. From R, the distance to S is 7 (4 + 3) and
7. The number at T is the shortest distance.
to U is 7 (4 + 3).
6. Write 7 at S. Do not write 7 at U as this is The path corresponding to this distance is
greater than the number already there. QVUT.
Example 6
Find the shortest route for the graph There are exactly two odd degree vertices,
below such that all edges must be I and H, and the shortest path between
traversed. The route must begin and them is the direct edge IH. The path must
end at C. pass this edge twice.
There are four odd vertices: Q, P, S, and N. By observation, the shortest combined path
comes from joining Q to P directly, and S to N via O. Hence, the repeated edges must
be QP, SO, and ON with combined length of 120.
Since the edges of the graph have a total length of 800, the roadsweeper’s best route
is 920 long. One such route is JKLMNLSONORKSOPRQPQJ. Other equally valid routes
can be found.
Try these!!!
A. The cost of flying between European cities B. Find the length of an optimal Chines
is shown below. Use both the greedy postman route for the given graph.
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?