Graph Section 15.2

Chapter 15
Graph
Theory
© 2008 Pearson Addison-Wesley.
All rights reserved
Chapter 15: Graph Theory
15.1
15.2
15.3
15.4
Basic Concepts
Euler Circuits
Hamilton Circuits and Algorithms
Trees and Minimum Spanning Trees
15-2-2
© 2008 Pearson Addison-Wesley. All rights reserved
Chapter 1
Section 15-2
Euler Circuits
15-2-3
© 2008 Pearson Addison-Wesley. All rights reserved
Euler Circuits
..
• Konigsberg’s Bridge Problem
• Fleury’s Algorithm
15-2-4
© 2008 Pearson Addison-Wesley. All rights reserved
..
Konigsberg Bridge Problem
..
In the early 1700s, the city of Konigsberg was the
capital of East Prussia. The river Pregel ran through
the city in two branches with an island between the
branches (see figure on next slide).
There were seven bridges joining various parts of
the city. The following problem was well known. Is
it possible for a citizen of Konigsberg to take a stroll
through the city, crossing each bridge exactly once,
and beginning and ending at the same place?
..
15-2-5
© 2008 Pearson Addison-Wesley. All rights reserved
Map of Konigsberg
15-2-6
© 2008 Pearson Addison-Wesley. All rights reserved
Graph of the Map
The vertices represent landmasses. The edges
represent the bridges
C
a
g
b
f
A
c
d
B
e
D
15-2-7
© 2008 Pearson Addison-Wesley. All rights reserved
Euler Path and Euler Circuit
An Euler path in a graph is a path that uses
every edge of the graph exactly once. An
Euler circuit in a graph is a circuit that uses
every edge of the graph exactly once.
15-2-8
© 2008 Pearson Addison-Wesley. All rights reserved
Example: Recognizing Euler Circuits
Consider the graph below.
a) Is A  B  C  D  E  F  A an Euler
circuit?
b) Does the graph have an Euler circuit?
E
F
A
D
B
C
15-2-9
© 2008 Pearson Addison-Wesley. All rights reserved
Example: Recognizing Euler Circuits
Solution
a) No, it does not use edge BD.
b) Yes, the circuit
A BC D E F D BF A
is an Euler circuit.
E
F
A
D
B
C
15-2-10
© 2008 Pearson Addison-Wesley. All rights reserved
Euler and the Bridge Problem
Leonhard Euler published a paper in 1736
that explained why it is impossible to find a
walk of the required kind, and he provided a
simple way for deciding whether a given
graph has an Euler circuit.
15-2-11
© 2008 Pearson Addison-Wesley. All rights reserved
Euler’s Theorem
Suppose we have a connected graph.
1. If the graph has an Euler circuit, then each
vertex of the graph has even degree.
2. If each vertex of the graph has even degree, then
the graph has an Euler circuit.
15-2-12
© 2008 Pearson Addison-Wesley. All rights reserved
Example: Using Euler’s Theorem
Does the graph below have an Euler circuit?
B
C
F
H
A
D
E
G
Solution
Yes, because the graph is connected and each vertex
has even degree.
15-2-13
© 2008 Pearson Addison-Wesley. All rights reserved
Cut Edge
A cut edge in a graph is an edge whose
removal disconnects a component of the
graph.
15-2-14
© 2008 Pearson Addison-Wesley. All rights reserved
Example: Cut Edges
Identify the cut edges in the graph below.
B
A
C
F
D
E
H
G
Solution
CE and GH are cut edges, if either is removed, it
would disconnect the graph.
15-2-15
© 2008 Pearson Addison-Wesley. All rights reserved
Fleury’s Algorithm
Fleury’s algorithm can be used to find an Euler
circuit in any connected graph in which each vertex
has even degree. An algorithm is like a recipe;
follow the steps and you achieve what you need.
15-2-16
© 2008 Pearson Addison-Wesley. All rights reserved
Fleury’s Algorithm
Step 1:
Start at any vertex. Go along any edge
from this vertex to another vertex.
Remove this edge from the graph.
Step 2:
You are now on a vertex on the revised
graph. Choose any edge from this
vertex, but not a cut edge, unless you
have no other option. Go along your
chosen edge. Remove this edge from
the graph.
15-2-17
© 2008 Pearson Addison-Wesley. All rights reserved
Fleury’s Algorithm
Step 3:
Repeat Step 2 until you have used all
the edges and gotten back to the vertex
at which you started.
15-2-18
© 2008 Pearson Addison-Wesley. All rights reserved
Example: Using Fleury’s Algorithm
Find an Euler circuit for the graph below.
B
Solution
A
B
C
F
D
C
F
Remove
BC
A
E
D
E
15-2-19
© 2008 Pearson Addison-Wesley. All rights reserved
Example: Using Fleury’s Algorithm
Solution (continued)
C
B
F
Remove
CF
A
B
D
C
F
Remove
FD
A
E
D
E
15-2-20
© 2008 Pearson Addison-Wesley. All rights reserved
Example: Using Fleury’s Algorithm
Solution (continued)
B
C
F
Remove
DE
A
D
E
Now it is clear to finish with
E  C  D  A  B.
15-2-21
© 2008 Pearson Addison-Wesley. All rights reserved
Example: Using Fleury’s Algorithm
Solution (continued)
The complete Euler circuit is
B  C  F  D  E  C  D  A  B.
Note that a graph that has an Euler circuit always
has more than one Euler circuit.
15-2-22
© 2008 Pearson Addison-Wesley. All rights reserved