Professional Documents
Culture Documents
CH 11
CH 11
CH 11
Introduction to Graphs
22c:19
Is it possible to walk with a route that crosses each bridge exactly once?
1
11/18/2009
A Graph
An edge
A vertex e6 d (or a line)
(or a node,
or a point) e7
e5
e4
c
a
e3
e2
e1
b
Eulers Solution
Question: Is it possible to find a walk that visits each edge exactly once.
e6 d
e7
e5
e4 v
c
a
e3
e2
e1
b
Suppose there is such a walk, there is a starting point and an endpoint point.
Eulers Solution
Question: Is it possible to find a walk that visits each edge exactly once.
e6 d
So, at most two vertices can
e7 have odd number of edges.
e5
e4
c In this graph, every vertex has
a only an odd number of edges,
e3
e2 and so there is no walk which
e1
visits each edge exactly one.
b
Suppose there is such a walk, there is a starting point and an endpoint point.
2
11/18/2009
Eulers Solution
When is it possible to have a walk that visits every edge exactly once?
Eulers Solution
When is it possible to have a walk that visits every edge exactly once?
Eulers Solution
When is it possible to have a walk that visits every edge exactly once?
3
11/18/2009
Eulers Solution
When is it possible to have a walk that visits every edge exactly once?
Euler path
Application 1
22c:19
22c:31
22c:21 22c:22
Application 2
These are all graph problems (shortest path, minimum spanning tree, maximum flow).
4
11/18/2009
Application 3
Application 4
Types of Graphs
5
11/18/2009
Simple Graphs
a
b
A graph G=(V,E) consists of:
A set of vertices, V
f
A set of undirected edges, E
c
V(G) = {a,b,c,d,e,f} e
d
E(G) = {ad,af,bd,be,cd,ce,df}
G
Vertex Degrees
An edge uv is incident on a
b
the vertex u and the vertex v.
f
The neighbour set N(v) of a vertex v
is the set of vertices adjacent to it. c
e.g. N(a)
N( ) = {d
{d,f},
f} N(d) = {a,b,c,f},
{ b f} N(e)N( ) = {b,c}.
{b } e
d
degree of a vertex = # of incident edges
e.g. deg(d) = 4, deg(a)=deg(b)=deg(c)=deg(e)=deg(f)=2.
Degree Sequence
2 1
Is there a graph with degree sequence (2,2,2,2,1)?
Where to go?
NO. Whats wrong with these sequences?
6
11/18/2009
Handshaking Lemma
Lemma.
2|E | = deg(v )
v V
Handshaking Lemma
Lemma.
2|E | = deg(v )
v V
Same Graphs?
99
306 67
99 67 306 145
Same graph (different labels)
306 67 Christos
Sonya
99 Jessica
7
11/18/2009
loop loop
G=(V,E)
isolated vertex
adjacent
multiple
edges
incidence: an edge (directed or undirected) is incident to a vertex
that is one of its end points.
degree of a vertex: number of edges incident to it
Nodes of a digraph can also be said to have an indegree and an outdegree
adjacency: two vertices connected by an edge are adjacent
22
Graph Isomorphism
A bijection.
Hay
Dog Pig
Corn
8
11/18/2009
A bijection.
Hay
Dog Pig
Corn
If there is an edge in the original graph, there is an edge after the mapping.
A bijection.
Hay
Dog Pig
Corn
If there is no edge in the original graph, there is no edge after the mapping.
Graph Isomorphism
bijection f: V1 V2
(u,v) in E1 iff (f (u),f (v)) in E2
If G1 and G2 are isomorphic, do they have the same number of vertices? YES
If G1 and G2 are isomorphic, do they have the same number of edges? YES
If G1 and G2 are isomorphic, do they have the same degree sequence? YES
9
11/18/2009
Exercise
p p g properties
Find some isomorphic-preserving p p
which is satisfied in one graph but not the other.
Non-isomorphic
Exercise
10
11/18/2009
Simple Paths
Connectedness
13 12 26 16 66
E17
E25
10 4 8
3 connected components
Cycles
A cycle (circuit) is a closed path that begins and ends with same vertex.
cycle: v b w w a v
also: a v b w w a
11
11/18/2009
Simple Cycles
cycle: v w v also: w v w
Shortest Paths
u v
Shortest Paths
c
P3
u v
P1 P2
This is a cycle
12
11/18/2009
Summary
x y a
simple path: no vertex can be repeated e
example path: a-b-c-d-e b
path: no edge can be repeated
p trail: a-b-c-d-e-b-d
example
walk: no restriction d
example walk: a-b-d-a-b-c
c
closed: if starting vertex is also ending vertex
length: number of edges in the simple path, path, or walk
Types of graphs
simple graph: an undirected graph with no loops or multiple edges between
the same two vertices
multi-graph: any graph that is not simple
connected graph: all vertex pairs are joined by a path
disconnected graph: at least one vertex pairs is not joined by a path
complete graph: all vertex pairs are adjacent
Kn: the completely connected graph with n vertices
Simple graph a
a e
b
e
b
K5
d
c d
Disconnected graph
with two components c
38
Types of graphs
acyclic graph (forest): a graph with no cycles
tree: a connected, acyclic graph
rooted tree: a tree with a root or distinguished vertex
leaves: the terminal nodes of a rooted tree
directed acyclic graph (dag): a digraph with no cycles
weighted graph: any graph with weights associated with the edges (edge-
weighted) and/or the vertices (vertex-weighted)
b 10 a
5 c
d 8
2 -3
e f
6
39
13
11/18/2009
Digraph definitions
for digraphs only Directed graph
Every edge has a head (starting point) and a b a
tail (ending point)
Walks, trails, and paths can only use edges in
the appropriate direction
In a DAG, every path connects an c
predecessor/ancestor (the vertex
erte at the head
of the path) to its successor/descendents
(nodes at the tail of any path). d
x
parent: direct ancestor (one hop)
w y
child: direct descendent (one hop)
A descendent vertex is reachable from any of v
its ancestors vertices u
z
40
Computer representation
undirected graphs: usually represented as digraphs with two
directed edges per actual undirected edge.
adjacency matrix: a |V| x |V| array where each cell i,j contains
the weight of the edge between vi and vj (or 0 for no edge)
adjacency list: a |V| array where each cell i contains a list of all
vertices adjacent to vi
incidence matrix: a |V| by |E| array where each cell i,j
i j contains
a weight (or a defined constant HEAD for unweighted graphs)
if the vertex i is the head of edge j or a constant TAIL if vertex I
is the tail of edge j
6 1 2 3 4 5
c b a
a b c
8
d
4
a c (8), d (4)
b
a
b t
8
t
4
b c b (6) c 6 t t
2 c 6 d c (2), b (10) d 2 10 t
8 10 d 10 2
4 adjacency incidence
a d adjacency
list matrix
matrix
41
Subgraphs
G=(V,E) is a subgraph of G=(V,E) if V V and E E.
induced subgraph: a subgraph that contains all possible edges
in E that have end points of the vertices of the selected V
a a
b e
e
b
d
d d c
c c Induced subgraph of
G=(V,E) G=({a,c,d},{{c,d}}) G with V = {b,c,d,e}
42
14
11/18/2009
Complement of a graph
The complement of a graph G (V,E) is a graph with the same
vertex set, but with vertices adjacent only if they were not
adjacent in G(V,E)
a a
e e
b b
G G
d d
c c
43
4 3
44
a b c a 3
1 e
d e f b 3 2 4
3
d
g h 5 4
2
i c
45
15
11/18/2009
K4,4
46
c g 1 2
4 3
47
Euler Graphs
Proof by induction.
16
11/18/2009
Proof Idea
1
6
3 5
Proof Idea
1
6
3 5
Proof Idea
1
6
3 5
17
11/18/2009
Proof Idea
1 15
6 12 9
3 5 13 10
16
2 14 11
7
4 8
Now what?
Proof Idea
Common vertex v
1 13
16 10 7
3 15 11 8
14
2 12 9
5
4 6
Complication
18
11/18/2009
Complication
19