You are on page 1of 9

10/15/20

The MATHEMATICS of GRAPHS


Seven bridges crossed the Pregel river and connected four different
Most of the SLIDES were created DR ROMINA YAP land areas of Konigsberg.
Many ci?zens of the ?me aBempted to take a stroll that would lead
them across each bridge and return them to the star?ng point
without traversing the same bridge twice.
None of them could do it, no maBer where they choose to start.

The Seven Bridges of Königsberg GRAPH


•  A GRAPH is a collec?on of points called ver<ces or nodes, and
connec?ng segments called edges. Some?mes the edges are given
orienta?ons and are represented by arrows, or are given values or
weights.

Is it possible to take a walk around Königsberg such that one ends


where one started and each bridge is crossed exactly once?
hBps://medium.com/basecs/k%C3%B6nigsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12

Example: Constructing a graph


The Seven Bridges of Königsberg The ff table lists 5 students at a college. An “x” indicates that the two students
par?cipate in the same study group this semester.

(a) Draw a graph to represent this informa?on, where each vertex represents a
student and an edge connects two ver?ces if the corresponding students study
together.

1
10/15/20

•  The posi?on of the ver?ces, the lengths of the edges, and the shape
of the edges do not maBer in a graph. What we look at is the number
of ver?ces and which of them are joined by edges.

a) Which student is involved in the most study groups with the others?
b) Which student has only one study group in common with the others?
c) How many study groups does Laura have in common with the others?
ANS. a) Amber; b) Kayla ; c) 2

Example: Determine whether the graphs are equivalent GRAPHS that model different
applications
•  Composi?on of two teams. •  A telephone network
•  How many lines need to be cut to
Ellen disconnect the system?
Tina

Amy
The two graphs represent the same connec?ons among the ver?ces.
Edges: AC, AE, BD, BE, CE, DE Lucille

Jen Sally

GRAPHS that model different GRAPHS that model different


applications applications
•  People and the jobs that they can •  A rough map of five ci?es and •  The cost of travelling from one store branch to another.
take on the roads that link them •  If an inspector needs to visit all the branches in a single day, what is the
•  Is it possible to match one person •  Can a travelling salesman visit each cheapest route that he can take? B2
to one job so all persons have jobs? city exactly once and return to his 114
star?ng point? 115
Abel Boni Kardo Diego Enciong B1
120 B3

80 176 60
95 241
104

188 B4
Staff Graphic Copy- B5
writer Auditor Programmer
Trainer Designer

2
10/15/20

e1
Formal Notations U V
V(G) = {U, V, W, X, Y}
e3 e2
Y
• A graph G consists of two finite sets V(G) and E(G) and E(G) = { e1, e2, e3, e4 }
W
e4
denote the graph as G = (V(G), E(G)) X
•  V(G) is the vertex set of G, which is necessarily a non-empty set
•  E(G) is the edge set of G, which could be empty •  Edge e2 is incident to vertex X.
•  Vertex U and V are adjacent to each other.
e1
U V e1 ! UV or VU •  Edges e1 and e2 are adjacent to each other.
V(G) = {U, V, W, X, Y}
e3 e2
e2 ! UX or XU
Y e3 ! UW or WU
E(G) = { e1, e2, e3, e4 }
W
e4
e4 ! WX or XW
X

e1 V
U
e7
•  Edges e4 and e5 are mul<ple edges. •  The graphs below have edges that form the same connec?on of
e3 e2 e6 ver?ces in each graph. Thus, they are equal because they have the
Y •  Edge e7 is a loop. same vertex set and the same set of edges.
e4 •  A graph is called simple if it has no loops
W
X and no mul?ple edges.
e5

•  The blue graph above is connected.


•  The green graph on the len is not •  Two graphs are called equivalent if their ver?ces can be (re)labelled
connected. to make them equal.

How to represent a GRAPH


K5 U V
•  Drawing
Y
An empty graph A complete graph. A bipar<te graph
X
W
A complete graph with n
ver?ces is denoted by Kn. •  Adjacency matrix
U V W X Y
•  How many edges does a complete graph with n U 0 1 2 1 0
ver?ces have? V 1 2 0 0 0
•  What do you think is a complete bipar<te graph? W 2 0 0 1 0
•  Note: A complete bipar?te graph whose ver?ces X 1 0 1 0 0
can be grouped into two non-intersec?ng sets is
denoted by Kn, m. Y 0 0 0 0 0
•  Is the graph on the right a bipar?te graph?

3
10/15/20

How to represent a GRAPH


15 V
U
•  Drawing: Weighted Graphs 9
2
8
Y

W 9 X
EULER CIRCUITS
•  Adjacency matrix
U V W X Y
U 0 15 8 2 0
V 15 0 0 0 9
W 8 0 0 9 0
X 2 0 9 0 0
Y 0 9 0 0 0

TERMINOLOGY DEFINITION
•  The degree of a vertex is the number of •  An edge of a graph is called a bridge if its removal from the graph will
edges aBached to it. (Loops are counted add to its number of components.
twice.)
Iden<fy the bridges (if any) in the following graphs.

J K L

In the graph above, what is the N


M O
degree of vertex A? vertex E?
P Q R
What is the degree of each vertex of a complete graph?
S T

DEFINITIONS TERMINOLOGY
•  An Euler circuit of a graph is a circuit that passes through every edge
•  A path in a graph is an alterna?ng exactly once. (The path may cross ver?ces more than once.)
sequence of ver?ces and edges. It can be
seen as a trip from one vertex to another •  A graph that has an Euler circuit is called Eulerian.
by traversing edges.
•  A closed path is a path where the ini?al and Which of the following graphs is Eulerian (i.e., has an Euler circuit)?
final ver?ces are the same. This is also
called a circuit. Examples:
F – G – H – E
W X
A – B – C – E – B
Can you find a path that contains all the edges exactly once? D – B – E – G – D Z

Can you find a path that contains all the ver<ces exactly once? Non-Example:
D – E – H – D
Y

4
10/15/20

The Seven Bridges of Königsberg

• Path B-D-F-G-H-E-C-B-A-D-G-E-B : an EULER CIRCUIT


• Path A-B-C-E-H-G-E-B-D-A : not an EULER CIRCUIT
• Path A-B-C-E-H-G-F-D-A-B-E-G-D-A : not an EULER CIRCUIT To what Graph
Theory ques<on
•  Trace the paths to verify! is this problem
equivalent to?

Is it possible to take a walk around Königsberg such that one ends


where one started and each bridge is crossed exactly once?

The Seven Bridges of Königsberg The Seven Bridges of Königsberg


Is it possible to take a walk around Königsberg such that one ends
where one started and each bridge is crossed exactly once?
Find a path that crosses each bridge exactly once
• Can we start at any vertex, move through each edge
and return to the star?ng point .
once (but not more than once), and return to the
EQUIVALENT TO
star?ng vertex?
FIND AN EULER CIRCUIT in the graph.

Which graph has an Euler Circuit?


Eulerian Graph Theorem
A connected graph is Eulerian if and only if every vertex
of the graph is of even degree.

(a) Ver?ces C and D are of odd degree. By the EGT, the graph does not
have an Euler circuit.
(b) All ver?ces are of even degree. By the EGT, the graph has an Euler
Circuit.

5
10/15/20

Determine whether the graph is Eulerian. If it is, An application of Euler circuits:


find an Euler circuit. If not, explain. Given a SUBWAY MAP, tracks that subway trains traverse as well as the junc?ons
where one can switch trains. Suppose an inspector needs to travel the full
length of each track. Is it possible to plan a journey that traverses the tracks
and returns to the star?ng point, without traveling through any por?on of a
track more than once?

•  Each vertex is of even degree (2,4, or 6). Thus, by EGT, the graph is
Eulerian. By trial and error, we obtain one Euler circuit, as follows:
B-A-F-B-E-F-G-E-D-G-B-D-C-B

WILL THE KONIGSBERG PROBLEM HAVE A SOLUTION IF WE DID NOT


NEED TO RETURN TO THE STARTING POINT?
I.E. FIND A PATH THAT USES EVERY EDGE ONCE AND ONLY ONCE.
(WE CALL SUCH A PATH AN EULER PATH.)
•  Consider the subway map as a graph, with a vertex at each junc?on.
An edge represents a track that runs between two junc?ons. In order
to find a travel route, we need to find an Euler circuit in the graph. Euler showed that even with this relaxed condi?on, the bridge problem
•  Note: The vertex represen?ng the Civic Center junc?on has degree 3. s?ll was not solvable..
Thus, the graph is not Eulerian. So, it is NOT possible for the inspector
to travel the track and return to the star?ng point without traveling
through any por?on of a track more than once.

DEFINITION Euler Path Theorem


An Euler path of a graph is a path that contains all the edges A connected graph contains an Euler path (that is not a circuit)
of the graph exactly once. (Not required to start and end at if and only if the graph has two ver?ces of odd degree with
the same vertex.) all other ver?ces of even degree. Furthermore, every Euler
path must start at one of the ver?ces of odd degree and end
Which of the following graphs has an Euler path? at the other.

W X
Z

6
10/15/20

An application of Eulerian paths An application of Eulerian paths


•  A photographer would like to traverse across all of the roads on the Floor plan of an art gallery:
given 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 OF THE ROADS EXACTLY ONCE?
•  We are looking for an Euler path.
•  Note that 2 ver?ces, A and D, are of ODD degree.
•  The photographer must start from any of A or D. Represent it by a graph. Ver?ces correspond to rooms and edges
•  One Euler path: A-B-C-D-B-F-A-G-F-E-D correspond to doorways.

An application of Eulerian paths


Is it possible to take a stroll that passes through every
doorway without going through the same doorway twice?
Represent it by a graph. Ver?ces correspond to rooms and edges •  We are looking for an Euler path!
correspond to doorways.

•  Start at a vertex of odd degree (C or D). By trial and error, one such
path is C-B-F-B-A-F-E-D-C-F-D

The Seven Bridges of Königsberg


• The Eulerian Graph Theorem guarantees that
when all ver?ces of a graph have an even
degree, an Euler circuit exists but it does not tell
us how to find one. (For small cases, we can do
trial and error..)
• A systema?c method that can be used to find
Euler circuits in graphs with large number of
ver?ces: FLEURY’S ALGORITHM
Will this graph have an EULER CIRCUIT?
Will this graph have an EULER PATH?

7
10/15/20

Fleury’s Algorithm
1.  Make sure the graph has either 0 or 2 odd ver?ces.
2.  If there are 0 odd ver?ces, start anywhere.
If there are 2 odd ver?ces, start at one of them. WEIGHTED GRAPHS
3. Trace edges one at a ?me. Once an edge is traced, “delete” it. If you
have a choice between a bridge and a non-bridge, always choose
the non-bridge.
4.  Stop when you run out of edges.
“Don’t burn your bridges.”
An edge of a graph is called a bridge if its removal from the graph will add to its number of components.

The Seven Bridges of Königsberg TERMINOLOGY


Is it possible Is it possible •  A Hamiltonian path of a graph is a path passing through each vertex
to find a path to find a path of the graph exactly once.
where each where each
edge is crossed vertex is visited •  If the path is closed, it is called a Hamiltonian circuit.
exactly once? exactly once?
•  If a graph has a Hamiltonian circuit, it is called Hamiltonian.
NO. W
YES.
A B E
V
X

Euler Path Hamiltonian Path C D


Y
problem problem Z

Dirac’s Theorem
• THERE IS NO STRAIGHTFORWARD CRITERION TO • 
GUARANTEE THAT A GRAPH IS HAMILTONIAN.
NOTE:
This provides only a sufficient condi8on. It’s not a necessary condi8on!

8
10/15/20

Applying Dirac’s theorem Apply Dirac’s theorem to verify that the graph is
The graph shows the available flights of a small airline. An edge Hamiltonian. Then find the Hamiltonian circuit. What does
between two ver?ces in the graph means that the airline has direct the Hamiltonian circuit represent in terms of flights?
flights between the two corresponding ci?es. •  n=6
•  Every vertex has a degree of at least n/2 = 3. By Dirac’s theorem, the
graph is Hamiltonian.
•  By trial and error, one Hamiltonian circuit is
Portland-Boise-BuBe-Salt Lake City-Reno-Sacramento-Portland.
This represents a sequence of flights that visits each city and returns to
the star?ng city without visi?ng any city twice.

Weighted graph • THERE IS NO KNOWN SHORTCUT FOR FINDING THE OPTIMAL


• A graph in which each edge is associated with a value, HAMILTONIAN CIRCUIT IN A WEIGHTED GRAPH.
called a weight. The value can represent any quan?ty • TWO ALGORITHMS: GREEDY ALGORITHM & EDGE-PICKING
desired (e.g number of miles between corresponding ALGORITHM
ci?es). • BOTH ALGORITHMS APPLY ONLY TO COMPLETE GRAPHS
• For each Hamiltonian circuit in that weighted graph, the (graphs in which every possible edge is drawn between
sum of the weights along the edges traversed gives the ver?ces, without any mul?ple edges)
total distance traveled along that route. We can then • THE CIRCUITS FOUND BY THE ALGORITHMS ARE NOT
compare different routes and find the one that requires GUARANTEED TO HAVE THE SMALLEST TOTAL WEIGHT
the shortest total distance. TRAVELING SALESMAN POSSIBLE. BUT THEY ARE OFTEN BETTER THAN YOU WOULD
PROBLEM FIND BY TRIAL AND ERROR..

The Greedy Algorithm The Edge-Picking Algorithm


so called bec it has us choose the ‘cheapest’ option at every chance
we get..
1.  Choose a vertex to start at, then travel 1.  Mark the edge of smallest weight in
along the connected edge that has the the graph. (If two or more edges have
smallest weight. (If two or more edges the same weight, pick any one.)
have the same weight, pick any one.) 2.  Mark the edge of next smallest weight
2.  Aner arriving at the next vertex, travel in the graph, as long as it does not
along the edge of smallest weight that complete a circuit and does not add a
connects to a vertex not yet visited. third marked edge to a single vertex.
Con?nue this process un?l you have 3.  Con?nue this process un?l you can no
visited all ver?ces. longer mark any edges. Then mark the
3.  Return to the star?ng vertex. final edge that completes the
Hamiltonian circuit.

You might also like