2. 2
§9.1: Graphs and Graph Models
• Correspond to symmetricCorrespond to symmetric
binary relationsbinary relations RR..
• AA simple graphsimple graph GG=(=(VV,,EE))
consists of:consists of:
– a seta set VV ofof verticesvertices oror nodesnodes ((VV corresponds tocorresponds to
the universe of the relationthe universe of the relation RR),),
– a seta set EE ofof edgesedges // arcsarcs // linkslinks:: unordered pairsunordered pairs ofof
[distinct?][distinct?] elementselements uu,,vv ∈∈ VV, such that, such that uRvuRv..
Visual Representation
of a Simple Graph
§ 9.1 – Graphs and Graph Models
3. 3
• LetLet VV be the set of states in the far-be the set of states in the far-
southeastern U.S.:southeastern U.S.:
–VV={FL, GA, AL, MS, LA, SC, TN, NC}={FL, GA, AL, MS, LA, SC, TN, NC}
• LetLet EE={{={{uu,,vv}|}|uu adjoinsadjoins vv}}
={{FL,GA},{FL,AL},{FL,MS},={{FL,GA},{FL,AL},{FL,MS},
{FL,LA},{GA,AL},{AL,MS},{FL,LA},{GA,AL},{AL,MS},
{MS,LA},{GA,SC},{GA,TN},{MS,LA},{GA,SC},{GA,TN},
{SC,NC},{NC,TN},{MS,TN},{SC,NC},{NC,TN},{MS,TN},
{MS,AL}}{MS,AL}}
Example of a Simple Graph
TN
ALMS
LA
SC
GA
FL
NC
§ 9.1 – Graphs and Graph Models
4. 4
Multigraphs
• Like simple graphs, butLike simple graphs, but there may bethere may be moremore
than onethan one edge connecting two given nodesedge connecting two given nodes..
• AA multigraphmultigraph GG=(=(VV,, EE,, ff ) consists of a set) consists of a set VV
of vertices, a setof vertices, a set EE of edges (as primitiveof edges (as primitive
objects), and a functionobjects), and a function
ff::EE→→{{{{uu,,vv}|}|uu,,vv∈∈VV ∧∧ uu≠≠vv}.}.
• E.g., nodes are cities, edgesE.g., nodes are cities, edges
are segments of major highways.are segments of major highways.
Parallel
edges
§ 9.1 – Graphs and Graph Models
5. 5
Pseudographs
• Like a multigraph, butLike a multigraph, but edges connecting aedges connecting a
node to itself are allowednode to itself are allowed..
• AA pseudographpseudograph GG=(=(VV,, EE,, ff ) where) where
ff::EE→→{{{{uu,,vv}|}|uu,,vv∈∈VV}. Edge}. Edge ee∈∈EE is ais a looploop ifif
ff((ee)={)={uu,,uu}={}={uu}}..
• E.g.E.g., nodes are campsites, nodes are campsites
in a state park, edges arein a state park, edges are
hiking trails through the woods.hiking trails through the woods.
§ 9.1 – Graphs and Graph Models
loops
6. 6
Directed Graphs
• Correspond to arbitrary binary relationsCorrespond to arbitrary binary relations RR,,
which need not be symmetric.which need not be symmetric.
• AA directed graphdirected graph ((VV,,EE) consists of a set of) consists of a set of
verticesvertices VV and a binary relationand a binary relation EE onon VV..
• E.g.E.g.:: VV = people,= people,
EE={(={(xx,,yy) |) | xx lovesloves yy}}
• ee=(=(uu,,vv) ,) ,uu,,vv∈∈VV
§ 9.1 – Graphs and Graph Models
7. 7
Directed Multigraphs
• Like directed graphs, but there may be moreLike directed graphs, but there may be more
than one arc from a node to another.than one arc from a node to another.
• AA directed multigraphdirected multigraph GG=(=(VV,, EE,, ff ) consists) consists
of a setof a set VV of vertices, a setof vertices, a set EE of edges, and aof edges, and a
functionfunction ff::EE→→VV××VV..
• E.g.,E.g., VV=web pages,=web pages,
EE=hyperlinks.=hyperlinks. The WWW isThe WWW is
a directed multigraph...a directed multigraph...
§ 9.1 – Graphs and Graph Models
8. 8
Types of Graphs: Summary
• Summary of the book’s definitions.Summary of the book’s definitions.
• Keep in mind this terminology is not fullyKeep in mind this terminology is not fully
standardized...standardized...
Term
Edge
type
Multiple
edges ok?
Self-
loops ok?
Simple graph Undir. No No
Multigraph Undir. Yes No
Pseudograph Undir. Yes Yes
Directed graph Directed No Yes
Directed multigraph Directed Yes Yes
§ 9.1 – Graphs and Graph Models
10. 10
Adjacency
LetLet GG be an undirected graph with edge setbe an undirected graph with edge set EE..
LetLet ee∈∈EE be (or map to) the pair {be (or map to) the pair {uu,,vv}. Then}. Then
we say:we say:
• uu,, vv areare adjacentadjacent // neighborsneighbors // connectedconnected..
• EdgeEdge ee isis incident withincident with verticesvertices uu andand vv..
• EdgeEdge ee connectsconnects uu andand vv..
• VerticesVertices uu andand vv areare endpointsendpoints of edgeof edge ee..
§ 9.2 – Graph Terminology
11. 11
Degree of a Vertex
• LetLet GG be an undirected graph,be an undirected graph, vv∈∈VV a vertex.a vertex.
• TheThe degreedegree ofof vv, deg(, deg(vv), is its number of), is its number of
incident edges. (Except that any self-loopsincident edges. (Except that any self-loops
are counted twice.)are counted twice.)
• A vertex with degree 0 isA vertex with degree 0 is isolatedisolated..
• A vertex of degree 1 isA vertex of degree 1 is pendantpendant..
§ 9.2 – Graph Terminology
12. 12
Handshaking Theorem
• LetLet GG be an undirected (simple, multi-, orbe an undirected (simple, multi-, or
pseudo-) graph with vertex setpseudo-) graph with vertex set VV and edgeand edge
setset EE. Then. Then
• Corollary: Any undirected graph has anCorollary: Any undirected graph has an
even number of vertices of odd degreeeven number of vertices of odd degree..
Ev
Vv
2)deg( =∑∈
§ 9.2 – Graph Terminology
13. 13
Directed Adjacency
• LetLet GG be a directed (possibly multi-) graph,be a directed (possibly multi-) graph,
and letand let ee be an edge ofbe an edge of GG that is (or maps to)that is (or maps to)
((uu,,vv). Then we say:). Then we say:
– uu isis adjacent toadjacent to vv,, vv isis adjacent fromadjacent from uu
– ee comes fromcomes from uu,, ee goes togoes to vv..
– e connects u to ve connects u to v,, e goes from u to ve goes from u to v
– thethe initial vertexinitial vertex ofof ee isis uu
– thethe terminal vertexterminal vertex ofof ee isis vv
§ 9.2 – Graph Terminology
14. 14
Directed Degree
• LetLet GG be a directed graph,be a directed graph, vv a vertex ofa vertex of GG..
– TheThe in-degreein-degree ofof vv, deg, deg−−
((vv), is the number of), is the number of
edges going toedges going to vv..
– TheThe out-degreeout-degree ofof vv, deg, deg++
((vv), is the number of), is the number of
edges coming fromedges coming from vv..
– TheThe degreedegree ofof vv, deg(, deg(vv))≡≡degdeg−−
((vv)+deg)+deg++
((vv), is the), is the
sum ofsum of vv’s in-degree and out-degree.’s in-degree and out-degree.
§ 9.2 – Graph Terminology
15. 15
Directed Handshaking Theorem
• LetLet GG be a directed (possibly multi-) graphbe a directed (possibly multi-) graph
with vertex setwith vertex set VV and edge setand edge set EE. Then:. Then:
• Note that the degree of a node is unchangedNote that the degree of a node is unchanged
by whether we consider its edges to beby whether we consider its edges to be
directed or undirected.directed or undirected.
Evvv
VvVvVv
=== ∑∑∑ ∈∈
+
∈
−
)deg(
2
1
)(deg)(deg
§ 9.2 – Graph Terminology
17. 17
Complete Graphs
• For anyFor any nn∈∈NN, a, a complete graphcomplete graph onon nn
vertices,vertices, KKnn, is a simple graph with, is a simple graph with nn nodesnodes
in which every node is adjacent to everyin which every node is adjacent to every
other node:other node: ∀∀uu,,vv∈∈VV:: uu≠≠vv↔↔{{uu,,vv}}∈∈EE..
Note that Kn has edges.2
)1(1
1
−
=∑
−
=
nn
i
n
i
K1 K2
K3 K5 K6
K4
§ 9.2 – Graph Terminology
18. 18
Cycles
• For anyFor any nn≥≥3, a3, a cyclecycle onon nn vertices,vertices, CCnn, is a, is a
simple graph wheresimple graph where VV={={vv11,,vv22,… ,,… ,vvnn} and} and
EE={{={{vv11,,vv22},{},{vv22,,vv33},…,{},…,{vvnn−−11,,vvnn},{},{vvnn,,vv11}}.}}.
C3 C4 C5 C6 C7
C8
How many edges are there in Cn?
§ 9.2 – Graph Terminology
19. 19
Wheels
• For anyFor any nn≥≥3, a3, a wheelwheel WWnn, is a simple graph, is a simple graph
obtained by taking the cycleobtained by taking the cycle CCnn and addingand adding
one extra vertexone extra vertex vvhubhub andand nn extra edgesextra edges
{{{{vvhubhub,,vv11}, {}, {vvhubhub,,vv22},…,{},…,{vvhubhub,,vvnn}}.}}.
How many edges are there in Wn?
W3
W5 W6 W7
W8
W4
§ 9.2 – Graph Terminology
20. 20
n-cubes (hypercubes)
• For anyFor any nn∈∈NN, the hypercube, the hypercube QQnn is a simpleis a simple
graph consisting of two copies ofgraph consisting of two copies of QQnn-1-1
connected together at corresponding nodes.connected together at corresponding nodes.
QQ00 has 1 node.has 1 node.
Q0
Q1 Q2 Q3 Q4
Number of vertices: 2n
. Number of edges:Exercise to try!
§ 9.2 – Graph Terminology
21. 21
n-cubes (hypercubes)
• For anyFor any nn∈∈NN, the hypercube, the hypercube QQnn can becan be
defined recursively as follows:defined recursively as follows:
– QQ00={{={{vv00},},∅∅} (one node and no edges)} (one node and no edges)
– For anyFor any nn∈∈NN, if Q, if Qnn==((VV,,EE), where), where VV={={vv11,…,,…,vvaa}}
andand EE={={ee11,…,,…,eebb}, then}, then QQnn+1+1=(=(VV∪∪{{vv11´,…,´,…,vvaa´},´},
EE∪∪{{ee11´,…,´,…,eebb´}´}∪∪{{{{vv11,,vv11´},{´},{vv22,,vv22´},…,´},…,
{{vvaa,,vvaa´}}) where´}}) where vv11´,…,´,…,vvaa´ are new vertices, and´ are new vertices, and
where ifwhere if eeii={={vvjj,,vvkk} then} then eeii´={´={vvjj´,´,vvkk´}.´}.
§ 9.2 – Graph Terminology
22. 22
Bipartite Graphs
• AA simple graphsimple graph GG is calledis called bipartitebipartite if itsif its
vertex setvertex set VV can be partitioned into twocan be partitioned into two
disjoint setsdisjoint sets VV1 andand VV2 such thatsuch that every edgeevery edge
in the graph connects a vertex inin the graph connects a vertex in VV1 and aand a
vertex invertex in VV2(so that no edge in(so that no edge in GG connectsconnects
either two vertices ineither two vertices in VV1 or two vertices inor two vertices in
VV2))
§ 9.2 – Graph Terminology
23. 23
Complete Bipartite Graphs
• TheThe complete bipartite graphcomplete bipartite graph KKm,n that has itsthat has its
vertex set partitioned into two subsets ofvertex set partitioned into two subsets of mm
andand nn vertices, respectively. There is anvertices, respectively. There is an
edge between two verticesedge between two vertices iffiff one vertex isone vertex is
in the first subset and the other is in thein the first subset and the other is in the
second subsetsecond subset..
§ 9.2 – Graph Terminology
24. 24
Subgraphs
• A subgraph of a graphA subgraph of a graph GG=(=(VV,,EE) is a graph) is a graph
HH=(=(WW,,FF) where) where WW⊆⊆VV andand FF⊆⊆EE..
G H
§ 9.2 – Graph Terminology
25. 25
Graph Unions
• TheThe unionunion GG11∪∪GG22 of two simple graphsof two simple graphs
GG11=(=(VV11,, EE11) and) and GG22=(=(VV22,,EE22) is the simple) is the simple
graph (graph (VV11∪∪VV22,, EE11∪∪EE22).).
§ 9.2 – Graph Terminology
26. 26
§9.3: Graph Representations &
Isomorphism
• Graph representations:Graph representations:
– Adjacency lists.Adjacency lists.
– Adjacency matrices.Adjacency matrices.
– Incidence matrices.Incidence matrices.
• Graph isomorphism:Graph isomorphism:
– Two graphs are isomorphic iff they are identicalTwo graphs are isomorphic iff they are identical
except for theirexcept for their node namesnode names..
§ 9.3 – Graph Representations & Isomorphism
27. 27
Adjacency Lists
• A table with 1 row per vertex, listing itsA table with 1 row per vertex, listing its
adjacent vertices.adjacent vertices.
a b
dc
f
e
Vertex
Adjacent
Vertices
a
b
c
d
e
f
§ 9.3 – Graph Representations & Isomorphism
28. 28
Directed Adjacency Lists
• 1 row per node, listing the terminal nodes of1 row per node, listing the terminal nodes of
each edge incident from that node.each edge incident from that node.
§ 9.3 – Graph Representations & Isomorphism
a b
dc
f
e
Initial
Vertex
Terminal
Vertices
a
b
c
d
e
f
29. 29
Adjacency Matrices
• MatrixMatrix AA=[=[aaijij], where], where aaijij isis 11 if {if {vvii,, vvjj} is an} is an
edge ofedge of GG,, 00 otherwise.otherwise.
a b
c d
0001
0011
0101
1110
a b
d c
0212
2110
1103
2030
§ 9.3 – Graph Representations & Isomorphism
31. 31
Graph Isomorphism
• Formal definition:Formal definition:
– Simple graphsSimple graphs GG11=(=(VV11,, EE11) and) and GG22=(=(VV22,, EE22) are) are
isomorphicisomorphic iffiff ∃∃ a bijectiona bijection ff::VV11→→VV22 such thatsuch that ∀∀
aa,,bb∈∈VV11,, aa andand bb are adjacent inare adjacent in GG11 iffiff ff((aa) and) and
ff((bb) are adjacent in) are adjacent in GG22..
– ff is the “renaming” function that makes the twois the “renaming” function that makes the two
graphs identical.graphs identical.
– Definition can easily be extended to other typesDefinition can easily be extended to other types
of graphs.of graphs.
§ 9.3 – Graph Representations & Isomorphism
32. 32
Graph Invariants under Isomorphism
NecessaryNecessary but notbut not sufficientsufficient conditions forconditions for
GG11=(=(VV11,, EE11) to be isomorphic to) to be isomorphic to GG22=(=(VV22,, EE22):):
– ||VV1|=|1|=|VV2|, |2|, |EE1|=|1|=|EE2|.2|.
– The number of vertices with degreeThe number of vertices with degree nn is theis the
same in both graphs.same in both graphs.
– For every proper subgraphFor every proper subgraph gg of one graph, thereof one graph, there
is a proper subgraph of the other graph that isis a proper subgraph of the other graph that is
isomorphic toisomorphic to gg..
§ 9.3 – Graph Representations & Isomorphism
33. 33
Isomorphism Example
• If isomorphic, label the 2nd graph to showIf isomorphic, label the 2nd graph to show
the isomorphism, else identify difference.the isomorphism, else identify difference.
a
b
cd
e
f
b
d
a
e
fc
§ 9.3 – Graph Representations & Isomorphism
34. 34
Are These Isomorphic?
• If isomorphic, label the 2nd graph to showIf isomorphic, label the 2nd graph to show
the isomorphism, else identify difference.the isomorphism, else identify difference.
a
b
c
d
e
* Same # of
vertices
* Same # of
edges
* Different
# of verts of
degree 2!
(1 vs 3)
§ 9.3 – Graph Representations & Isomorphism
35. 35
§9.4: Connectivity
• In an undirected graph, aIn an undirected graph, a path of length npath of length n
from u to vfrom u to v is a sequence of adjacent edgesis a sequence of adjacent edges
going from vertexgoing from vertex uu to vertexto vertex vv..
• A path is aA path is a circuitcircuit ifif u=vu=v..
• A pathA path traversestraverses the vertices along it.the vertices along it.
• A path isA path is simplesimple ifif it contains no edge moreit contains no edge more
than oncethan once..
§ 9.4 – Connectivity
36. 36
Paths in Directed Graphs
• Same as in undirected graphs, butSame as in undirected graphs, but the paththe path
must go in the directionmust go in the direction of the arrows.of the arrows.
§ 9.4 – Connectivity
37. 37
Connectedness
• An undirected graph isAn undirected graph is connectedconnected iffiff there is athere is a
path between every pair of distinct vertices in thepath between every pair of distinct vertices in the
graphgraph..
• Theorem: There is aTheorem: There is a simplesimple path between any pairpath between any pair
of distinct vertices in a connected undirectedof distinct vertices in a connected undirected
graph.graph.
• Connected componentConnected component: connected subgraph: connected subgraph
• AA cut vertexcut vertex oror cut edgecut edge separates 1 connectedseparates 1 connected
component into 2 if removed.component into 2 if removed.
§ 9.4 – Connectivity
38. 38
Directed Connectedness
• A directed graph isA directed graph is strongly connectedstrongly connected iffiff
there is a directed paththere is a directed path fromfrom aa toto bb and fromand from
bb toto aa for any two verticesfor any two vertices aa andand bb..
• It isIt is weakly connectedweakly connected iff the underlyingiff the underlying
undirectedundirected graph (graph (i.e.i.e., with edge directions, with edge directions
removed) is connected.removed) is connected.
• NoteNote stronglystrongly impliesimplies weaklyweakly but not vice-but not vice-
versa.versa.
§ 9.4 – Connectivity
39. 39
Example
• Are the graphsAre the graphs GG andand HH stronglystrongly
connectedconnected?? Are theyAre they weakly connectedweakly connected??
a b
c
de
a b
c
de
G H
§ 9.4 – Connectivity
40. 40
Paths & Isomorphism
• Note that connectedness, and the existenceNote that connectedness, and the existence
of a circuit orof a circuit or simple circuit of lengthsimple circuit of length kk areare
graph invariantsgraph invariants with respect towith respect to
isomorphismisomorphism..
a b
c
de
f
m n
o
pq
r
IsomorphicIsomorphic??
§ 9.4 – Connectivity
41. 41
Counting Paths w Adjacency Matrices
• LetLet AA be the adjacency matrix of graphbe the adjacency matrix of graph GG..
• TheThe numbernumber of paths of lengthof paths of length rr fromfrom vvii toto vvjj
is equal tois equal to ((AArr
))i,ji,j. (The notation (. (The notation (MM))i,ji,j denotesdenotes
mmi,ji,j where [where [mmi,ji,j] =] = MM..))
§ 9.4 – Connectivity
42. 42
Example
• How many paths of length 4 fromHow many paths of length 4 from aa toto dd??
a b
cd
=
0110
1001
1001
0110
A =4
A
§ 9.4 – Connectivity