Graphs
Graphs
deg(v) 2 E
vV
• Corollary: Any undirected graph has an
even number of vertices of odd degree.
Directed Adjacency
• Let G be a directed (possibly multi-) graph,
and let e be an edge of G that is (or maps
to) (u,v). Then we say:
– u is adjacent to v, v is adjacent from u
– e comes from u, e goes to v.
– e connects u to v, e goes from u to v
– the initial vertex of e is u
– the terminal vertex of e is v
Directed Degree
• Let G be a directed graph, v a vertex of G.
– The in-degree of v, deg(v), is the number of
edges going to v.
– The out-degree of v, deg(v), is the number of
edges coming from v.
– The degree of v, deg(v):deg(v)+deg(v), is the
sum of v’s in-degree and out-degree.
Directed Handshaking Theorem
• Let G be a directed (possibly multi-) graph
with vertex set V and edge set E. Then:
1
vV
deg (v) deg (v) deg(v) E
vV
2 vV
• Note that the degree of a node is unchanged
by whether we consider its edges to be
directed or undirected.
Special Graph Structures
Special cases of undirected graph structures:
• Complete graphs Kn
• Cycles Cn
• Wheels Wn
• n-Cubes Qn
• Bipartite graphs
• Complete bipartite graphs Km,n
Complete Graphs
• For any nN, a complete graph on n
vertices, Kn, is a simple graph with n nodes
in which every node is adjacent to every
other node: u,vV: uv{u,v}E.
K1 K2 K3 K4
K5 K6
n 1
n(n 1)
Note that Kn has i 2 edges.
i 1
Cycles
• For any n3, a cycle on n vertices, Cn, is a
simple graph where V={v1,v2,… ,vn} and
E={{v1,v2},{v2,v3},…,{vn1,vn},{vn,v1}}.
C3 C4 C5 C6 C8
C7
How many edges are there in Cn?
Wheels
• For any n3, a wheel Wn, is a simple graph
obtained by taking the cycle Cn and adding
one extra vertex vhub and n extra edges
{{vhub,v1}, {vhub,v2},…,{vhub,vn}}.
W3 W4 W5 W6 W8
W7
How many edges are there in Wn?
n-cubes (hypercubes)
• For any nN, the hypercube Qn is a simple
graph consisting of two copies of Q n-1
connected together at corresponding nodes.
Q0 has 1 node.
Q0
Q1 Q2 Q4
Q3
Number of vertices: 2n. Number of edges:Exercise to try!
n-cubes (hypercubes)
• For any nN, the hypercube Qn can be
defined recursively as follows:
– Q0={{v0},} (one node and no edges)
– For any nN, if Qn=(V,E), where V={v1,…,va}
and E={e1,…,eb}, then Qn+1=(V{v1´,…,va´},
E{e1´,…,eb´}{{v1,v1´},{v2,v2´},…,
{va,va´}}) where v1´,…,va´ are new vertices, and
where if ei={vj,vk} then ei´={vj´,vk´}.
Bipartite Graphs
• Def’n.: A graph G=(V,E) is bipartite (two-
part) iff V = V1∩V2 where V1V2= and
eE: v1V1,v2V2: e={v1,v2}.
• In English: The graph can
be divided into two parts
in such a way that all edges
go between the two parts. V1 V2
This definition can easily be adapted for the
case of multigraphs and directed graphs as well. Can represent with
zero-one matrices.
Complete Bipartite Graphs
• For m,nN, the complete bipartite graph
Km,n is a bipartite graph where |V1| = m,
|V2| = n, and E = {{v1,v2}|v1V1 v2V2}.
– That is, there are m nodes K4,3
in the left part, n nodes in
the right part, and every
node in the left part is
connected to every node Km,n has _____ nodes
in the right part. and _____ edges.
Subgraphs
• A subgraph of a graph G=(V,E) is a graph
H=(W,F) where WV and FE.
G H
Graph Unions
• The union G1G2 of two simple graphs
G1=(V1, E1) and G2=(V2,E2) is the simple
graph (V1V2, E1E2).
a
a b c b c
d e d f
§8.3: Graph Representations &
Isomorphism
• Graph representations:
– Adjacency lists.
– Adjacency matrices.
– Incidence matrices.
• Graph isomorphism:
– Two graphs are isomorphic iff they are
identical except for their node names.
Adjacency Lists
• A table with 1 row per vertex, listing its
adjacent vertices. Adjacent
a b Vertex Vertices
a b, c
c d b a, c, e, f
e
f c a, b, f
d
e b
f c, b
Directed Adjacency Lists
• 1 row per node, listing the terminal nodes of
each edge incident from that node.
Adjacency Matrices
• A way to represent simple graphs
– possibly with self-loops.
• Matrix A=[aij], where aij is 1 if {vi, vj} is an
edge of G, and is 0 otherwise.
• Can extend to pseudographs by letting each
matrix elements be the number of links
(possibly >1) between the nodes.
Graph Isomorphism
• Formal definition:
– Simple graphs G1=(V1, E1) and G2=(V2, E2) are
isomorphic iff a bijection f:V1V2 such that
a,bV1, a and b are adjacent in G1 iff f(a) and
f(b) are adjacent in G2.
– f is the “renaming” function between the two
node sets that makes the two graphs identical.
– This definition can easily be extended to other
types of graphs.
Graph Invariants under Isomorphism
B D
C
Equivalent multigraph
The original problem
Euler Path Theorems
• Theorem: A connected multigraph has an
Euler circuit iff each vertex has even degree.
– Proof:
• (→) The circuit contributes 2 to degree of each node.
• (←) By construction using algorithm on p. 580-581
• Theorem: A connected multigraph has an
Euler path (but not an Euler circuit) iff it has
exactly 2 vertices of odd degree.
– One is the start, the other is the end.
Euler Circuit Algorithm
• Begin with any arbitrary node.
• Construct a simple path from it till you get
back to start.
• Repeat for each remaining subgraph,
splicing results back into original cycle.
Round-the-World Puzzle
• Can we traverse all the vertices of a
dodecahedron, visiting each once?`