You are on page 1of 20

Graphs

COMPSCI 230 — Discrete Math

March 23, 2017

COMPSCI 230 — Discrete Math Graphs March 23, 2017 1 / 20


Overview

1 Graphs

2 Graph Nomenclature

3 Graph Examples

4 The Adjacency Matrix

5 Tours

6 Euler and Hamilton Circuits

COMPSCI 230 — Discrete Math Graphs March 23, 2017 2 / 20


Graphs

(Undirected) Graphs
• Graphs are items together with 𝑎 𝑏
binary relations
• Items are called vertices (or nodes)
• Relations are called edges (or arcs)
𝑐 𝑑
• Formally:
• 𝐺 = (𝑉 , 𝐸)
• 𝐺 is an ordered pair
𝐺 = (𝑉 , 𝐸)
• 𝑉 is a set of vertices
𝑉 = {𝑎, 𝑏, 𝑐, 𝑑}
• Every element of 𝐸 is an
𝐸 = {{𝑎, 𝑏}, {𝑎, 𝑐}, {𝑎, 𝑑},
unordered pair (a set) from
𝑉 ×𝑉 {𝑏, 𝑐}, {𝑐, 𝑑}1 , {𝑐, 𝑑}2 ,
• Note the two distinct edges {𝑑, 𝑑}}
between 𝑐 and 𝑑

COMPSCI 230 — Discrete Math Graphs March 23, 2017 3 / 20


Graph Nomenclature

Vertices and Edges


𝑎 𝑏

𝑐 𝑑

• The two copies of {𝑐, 𝑑} are parallel edges


• {𝑑, 𝑑} is a loop
• 𝑎 and 𝑏 are adjacent to each other (neighbors of each other)
• {𝑎, 𝑏} is incident to 𝑎 and 𝑏
• The degree of a vertex is the number of edge-ends incident to it:
deg(𝑎) = 3; deg(𝑏) = 2; deg(𝑐) = 4; deg(𝑑) = 5
• A graph is simple if it has no loops and no parallel edges

COMPSCI 230 — Discrete Math Graphs March 23, 2017 4 / 20


Graph Nomenclature

Paths
𝑒1
𝑎 𝑏

𝑒7
𝑒3

𝑒6
𝑒2 𝑒5

4
𝑒
𝑒9 𝑒10
𝑒8 𝑐 𝑑 𝑒

• 𝐺 = (𝑉 , 𝐸) = ({𝑎, 𝑏, 𝑐, 𝑑, 𝑒}, {𝑒1 , … 𝑒10 }) is a graph


• The sequence (𝑎, 𝑒2 , 𝑐, 𝑒8 , 𝑐, 𝑒4 , 𝑏, 𝑒6 , 𝑒, 𝑒6 , 𝑏) is a path from 𝑎 to 𝑏
• (𝑎, 𝑒2 , 𝑐, 𝑒4 , 𝑏, 𝑒6 , 𝑒) is a simple path from 𝑎 to 𝑒 (no repeated vertices)
• (𝑎, 𝑒1 , 𝑏, 𝑒6 , 𝑒) is a shortest path from 𝑎 to 𝑒
• (𝑎, 𝑒3 , 𝑑, 𝑒5 , 𝑏, 𝑒7 , 𝑒, 𝑒10 , 𝑑, 𝑒3 , 𝑎) is a closed path (first = last)
• (𝑎, 𝑒2 , 𝑐, 𝑒8 , 𝑐, 𝑒9 , 𝑑, 𝑒3 , 𝑎) is a circuit (non-empty closed path with distinct edges)
• (𝑎, 𝑒2 , 𝑐, 𝑒4 , 𝑏, 𝑒5 , 𝑑, 𝑒3 , 𝑎) is a polygon (connected graph with only degree-2
vertices; degree counted in the path)
• A polygon is a circuit, but not vice versa
• A graph is connected if there is a path between any two of its vertices

COMPSCI 230 — Discrete Math Graphs March 23, 2017 5 / 20


Graph Nomenclature

Subgraphs
𝑒1
𝑎 𝑏

𝑒7
𝑒3

𝑒6
𝑒2 𝑒5

4
𝑒
𝑒9 𝑒10
𝑒8 𝑐 𝑑 𝑒

• ({𝑎, 𝑏, 𝑑, 𝑒}, {𝑒1 , 𝑒3 , 𝑒5 , 𝑒6 }) is a subgraph of 𝐺 (a graph made of


vertices and edges from 𝐺)
• ({𝑎, 𝑏, 𝑐, 𝑑, 𝑒}, {𝑒1 , 𝑒3 , 𝑒5 , 𝑒6 , 𝑒9 }) is a spanning subgraph of 𝐺,
because it covers all the vertices
• ({𝑎, 𝑏, 𝑐, 𝑑, 𝑒}, {𝑒3 , 𝑒5 , 𝑒6 , 𝑒9 }) is a spanning tree of 𝐺:
a spanning subgraph that is also a tree
[A tree is a graph with no polygons]
• Spanning trees arise in graph traversals

COMPSCI 230 — Discrete Math Graphs March 23, 2017 6 / 20


Graph Examples

Where is the Graph?

COMPSCI 230 — Discrete Math Graphs March 23, 2017 7 / 20


Graph Examples

Graphs Abstract Away Geometry

Shady Grove Glenmont Greenbelt

Metro Center Mount Vernon Fort Totten

Rosslyn Chinatown New Carrolton

Pentagon L’Enfant Plaza Stadium

Vienna King Street Largo Town

Franconia Huntington Branch Avenue

COMPSCI 230 — Discrete Math Graphs March 23, 2017 8 / 20


Graph Examples

Transfer Stations Only?

Metro Center Mount Vernon Fort Totten

Rosslyn Chinatown

Pentagon L’Enfant Plaza Stadium

King Street

Shows which transfer station connects to which


transfer station
Can reason about interconnectivity and redundancy

COMPSCI 230 — Discrete Math Graphs March 23, 2017 9 / 20


The Adjacency Matrix

The Adjacency Matrix

Fo Str aza
L’ to on
Pe yn er

iu n
sl nt

na rn

l
r t ee
P

ad te
ou n

En w
os Ce

e
M go

m
K ant

St Tot
C tV
ro

f
nt

g
et

hi

in
M

R
Metro Center 2 1 2
Rosslyn 2 1
Pentagon 1 1 2
Mount Vernon 2 1
Chinatown 1 2 2 1
L’Enfant Plaza 2 1 2 2
King Street 2
Fort Totten 1 1
Stadium 2
Degree 5 3 4 3 6 7 2 2 2

• Number of edges that connect any two entries


• Entries not shown are 0
• The adjacency matrix is symmetric for undirected graphs
• A simple graph has a binary adjacency matrix with zero diagonal
• The sum of each column (or row) is the degree of the corresponding node
• Sum of degrees = 34 = twice the number of edges

COMPSCI 230 — Discrete Math Graphs March 23, 2017 10 / 20


The Adjacency Matrix

Edge Labels

Metro Center Mount Vernon Fort Totten

Rosslyn Chinatown

Pentagon L’Enfant Plaza Stadium

King Street

Could label edges by which metro line connects any


two transfer stations
Every color gives an open path on this graph

COMPSCI 230 — Discrete Math Graphs March 23, 2017 11 / 20


The Adjacency Matrix

Which Transfer Station Connects Which Lines?


n
te
ot Ch
rtT wn ina
Fo to to
ina wn
Ch
Mt. Vernon
Chinatown

Plaza
L'Enfant

za
L'E

Met

Pla
nter
nfa L'E

nt
ro C
nt

e
nf

nfa
ro C
Pla an
tP

L'E
laz

nter
za
Stadium
Met
a

Metro Center

n
go

t
ta
Rosslyn

e
re
n
Pe

St
L'Enfant Plaza

ng
Ki
• What is a vertex or an edge is up to us
• The graph is in the eye of the beholder
• Warning: It does not always make sense to swap vertices with
edges
COMPSCI 230 — Discrete Math Graphs March 23, 2017 12 / 20
Tours

Tours
𝑒1
𝑎 𝑏

𝑒4
𝑒3 𝑒2 𝑒6

𝑒7
5
𝑒
𝑒9
𝑐 𝑑 𝑒
𝑒8

• The path
(𝑒, 𝑒7 , 𝑏, 𝑒1 , 𝑎, 𝑒2 , 𝑐, 𝑒5 , 𝑏, 𝑒5 , 𝑐, 𝑒9 , 𝑑, 𝑒4 , 𝑎, 𝑒2 , 𝑐, 𝑒8 , 𝑐, 𝑒3 , 𝑎, 𝑒1 , 𝑏)
is an edge tour of 𝐺, because it traverses every edge
• It is also a vertex tour, because it traverses every vertex
• The path (𝑒, 𝑒7 , 𝑏, 𝑒5 , 𝑐, 𝑒9 , 𝑑, 𝑒4 , 𝑎, 𝑒2 , 𝑐, 𝑒8 , 𝑐, 𝑒3 , 𝑎, 𝑒1 , 𝑏, 𝑒6 , 𝑑) is
an Euler tour of 𝐺, because it traverses every edge exactly once
• The path (𝑎, 𝑒2 , 𝑐, 𝑒9 , 𝑑, 𝑒6 , 𝑏, 𝑒7 , 𝑒) is a Hamilton tour because it
traverses every vertex exactly once

COMPSCI 230 — Discrete Math Graphs March 23, 2017 13 / 20


Euler and Hamilton Circuits

Euler and Hamilton Circuits


𝑒1
𝑎 𝑏

𝑒4
𝑒3 𝑒2 𝑒6

𝑒7
5
𝑒
𝑒9 𝑒10
𝑐 𝑑 𝑒
𝑒8

• The circuit
(𝑑, 𝑒10 , 𝑒, 𝑒7 , 𝑏, 𝑒5 , 𝑐, 𝑒9 , 𝑑, 𝑒4 , 𝑎, 𝑒2 , 𝑐, 𝑒8 , 𝑐, 𝑒3 , 𝑎, 𝑒1 , 𝑏, 𝑒6 , 𝑑)
is an Euler circuit of 𝐺, because it traverses every edge exactly
once
• The circuit (𝑎, 𝑒2 , 𝑐, 𝑒9 , 𝑑, 𝑒10 , 𝑒, 𝑒7 , 𝑏, 𝑒1 , 𝑎) is a Hamilton circuit
because it traverses every vertex exactly once (before returning
to the original vertex)

COMPSCI 230 — Discrete Math Graphs March 23, 2017 14 / 20


Euler and Hamilton Circuits

Euler’s Theorem
• Not every graph has an Euler tour, an Euler circuit, a Hamilton
tour, or a Hamilton circuit
• This simple graph has none of them:

• Euler’s theorems: For a connected graph 𝐺,


• All nodes of even degree ↔ 𝐺 has an Euler circuit (which is
also an Euler tour)
• Exactly two nodes of odd degree ↔ 𝐺 has an open Euler
tour
• Tour starts at one odd-degree node and ends at the other
• No similarly clean characterization of Hamiltonian graphs is
known
COMPSCI 230 — Discrete Math Graphs March 23, 2017 15 / 20
Euler and Hamilton Circuits

Euler Circuit Example


• Domino tiles:

• Place them in sequence so that adjacent numbers


match:

• Can we make a loop that uses all the 28 tiles?

COMPSCI 230 — Discrete Math Graphs March 23, 2017 16 / 20


Euler and Hamilton Circuits

The Domino Graph


• Where is the graph?
• Vertices are the dot numbers, edges are the tiles

6 1

5 2

4 3

• A loop that uses all the 28 tiles is an Euler circuit


• Simple algorithms exist to find Euler circuits
• In this case, it is easy to draw one by hand

COMPSCI 230 — Discrete Math Graphs March 23, 2017 17 / 20


Euler and Hamilton Circuits

A Domino Euler Circuit

COMPSCI 230 — Discrete Math Graphs March 23, 2017 18 / 20


Euler and Hamilton Circuits

Hamilton Circuit Example


• In chess, a single move by the knight is by one cell in
one direction and two in the other

[graph image from commons.wikimedia.org]

• The knight’s graph is the obvious one


• A re-entrant knight’s tour is a sequence of moves
that takes the knight to each square exactly once,
with the first and last cell a knight’s move apart
COMPSCI 230 — Discrete Math Graphs March 23, 2017 19 / 20
Euler and Hamilton Circuits

A Knight’s Hamilton Circuit


• First discovered by al-Adli in 840 A.D.
• This is a Hamilton circuit

[image from http://www.dharwadker.org/pirzada/applications/]

COMPSCI 230 — Discrete Math Graphs March 23, 2017 20 / 20

You might also like