Let us switch to a new topic:
Let us switch to a new topic:
Graphs
Graphs
Introduction to Graphs Introduction to Graphs
Definition:
Definition: A A simple graphsimple graph G = (V, E) consists of V, G = (V, E) consists of V, a nonempty set of vertices, and E, a set of
a nonempty set of vertices, and E, a set of unordered pairs
unordered pairs of distinct elements of V called of distinct elements of V called edges.
edges.
For each e
For each eE, e = {u, v} where u, v E, e = {u, v} where u, v  V.V.
An undirected graph (not simple) may contain loops.
An undirected graph (not simple) may contain loops.
An edge e is a loop if e = {u, u} for some u
An edge e is a loop if e = {u, u} for some uV.V.
Introduction to Graphs Introduction to Graphs
Definition:
Definition: A A directed graph directed graph G = (V, E) consists of G = (V, E) consists of a set V of vertices and a set E of edges that are
a set V of vertices and a set E of edges that are ordered pairs of elements in V.
ordered pairs of elements in V.
For each e
For each eE, e = (u, v) where u, v E, e = (u, v) where u, v  V.V.
An edge e is a loop if e = (u, u) for some u
An edge e is a loop if e = (u, u) for some uV.V.
A simple graph is just like a directed graph, but A simple graph is just like a directed graph, but with no specified direction of its edges.
with no specified direction of its edges.
Graph Models Graph Models
Example I:
Example I: How can we represent a network of How can we represent a network of (bi
(bi--directional) railways connecting a set of cities?directional) railways connecting a set of cities?
We should use a
We should use a simple graphsimple graph with an edge {a, b} with an edge {a, b}
indicating a direct train connection between cities indicating a direct train connection between cities a and b.
a and b.
New York New York
Boston Boston
L
Lüübeckbeck Toronto
Toronto
Hamburg Hamburg
Graph Models Graph Models
Example II:
Example II: In a roundIn a round--robin tournament, each robin tournament, each team plays against each other team exactly once.
team plays against each other team exactly once.
How can we represent the results of the How can we represent the results of the
tournament (which team beats which other team)?
tournament (which team beats which other team)?
We should use a
We should use a directed graphdirected graph with an edge (a, b) with an edge (a, b) indicating that team a beats team b.
indicating that team a beats team b.
Penguins Penguins
Bruins Bruins
L
Lüübeck Giantsbeck Giants Maple Leafs
Maple Leafs
Graph Terminology Graph Terminology
Definition:
Definition: Two vertices u and v in an undirected Two vertices u and v in an undirected graph G are called
graph G are called adjacentadjacent (or (or neighborsneighbors) in G if ) in G if {u, v} is an edge in G.
{u, v} is an edge in G.
If e = {u, v}, the edge e is called
If e = {u, v}, the edge e is called incident withincident with the the vertices u and v. The edge e is also said to
vertices u and v. The edge e is also said to connectconnect u and v.
u and v.
The vertices u and v are called
The vertices u and v are called endpointsendpoints of the of the edge {u, v}.
edge {u, v}.
Graph Terminology Graph Terminology
Definition:
Definition: The The degreedegree of a vertex in an of a vertex in an
undirected graph is the number of edges incident undirected graph is the number of edges incident with it, except that a loop at a vertex contributes with it, except that a loop at a vertex contributes twice to the degree of that vertex.
twice to the degree of that vertex.
In other words, you can determine the degree of a In other words, you can determine the degree of a vertex in a displayed graph by
vertex in a displayed graph by counting the linescounting the lines that touch it.
that touch it.
The degree of the vertex v is denoted by
The degree of the vertex v is denoted by deg(v).deg(v).
Graph Terminology Graph Terminology
A vertex of degree 0 is called
A vertex of degree 0 is called isolatedisolated, since it is , since it is not adjacent to any vertex.
not adjacent to any vertex.
Note:
Note: A vertex with a A vertex with a looploop at it has at least at it has at least degree 2 and, by definition, is
degree 2 and, by definition, is not isolatednot isolated, even if , even if it is not adjacent to any
it is not adjacent to any otherother vertex.vertex.
A vertex of degree 1 is called
A vertex of degree 1 is called pendantpendant. It is . It is adjacent to exactly one other vertex.
adjacent to exactly one other vertex.
Graph Terminology Graph Terminology
Example:
Example: Which vertices in the following graph are Which vertices in the following graph are isolated, which are pendant, and what is the
isolated, which are pendant, and what is the maximum degree? What type of graph is it?
maximum degree? What type of graph is it?
aa b
b cc
d
d ff hh
gg ff jj
e e
Solution:
Solution: Vertex f is isolated, and vertices a, d and Vertex f is isolated, and vertices a, d and j are pendant. The maximum degree is deg(g) = 5.
j are pendant. The maximum degree is deg(g) = 5.
This graph is a pseudograph (undirected, loops).
This graph is a pseudograph (undirected, loops).
Graph Terminology Graph Terminology
Let us look at the same graph again and determine Let us look at the same graph again and determine the number of its edges and the sum of the
the number of its edges and the sum of the degrees of all its vertices:
degrees of all its vertices:
aa b
b cc
d
d ii hh
gg ff jj
e e
Result:
Result: There are 9 edges, and the sum of all There are 9 edges, and the sum of all degrees is 18. This is easy to explain: Each new degrees is 18. This is easy to explain: Each new
Graph Terminology Graph Terminology
The Handshaking Theorem:
The Handshaking Theorem: Let G = (V, E) be an Let G = (V, E) be an undirected graph with e edges. Then
undirected graph with e edges. Then 2e =
2e = vvVV deg(v)deg(v)
Example:
Example: How many edges are there in a graph How many edges are there in a graph with 10 vertices, each of degree 6?
with 10 vertices, each of degree 6?
Solution:
Solution: The sum of the degrees of the vertices is The sum of the degrees of the vertices is 6
610 = 60. According to the Handshaking Theorem, 10 = 60. According to the Handshaking Theorem, it follows that 2e = 60, so there are 30 edges.
it follows that 2e = 60, so there are 30 edges.
Graph Terminology Graph Terminology
Theorem:
Theorem: An undirected graph has an even number An undirected graph has an even number of vertices of odd degree.
of vertices of odd degree.
Proof:
Proof: Let V1 and V2Let V1 and V2 be the set of vertices of be the set of vertices of even and odd degrees, respectively (Thus V1
even and odd degrees, respectively (Thus V1  V2 = V2 =
, and V1 , and V1 V2 = V). V2 = V).
Then by Handshaking theorem Then by Handshaking theorem
2|E| =
2|E| = vvVV deg(v) = deg(v) = vvV1V1 deg(v) + deg(v) + vvV2V2 deg(v) deg(v) Since both 2|E| and
Since both 2|E| and vvV1V1 deg(v) are even, deg(v) are even,
vvV2V2 deg(v) must be even. deg(v) must be even.
Since deg(v) if odd for all v
Since deg(v) if odd for all vV2, |V2| must be even.V2, |V2| must be even.
Graph Terminology Graph Terminology
Definition:
Definition: When (u, v) is an edge of the graph G When (u, v) is an edge of the graph G with directed edges, u is said to be
with directed edges, u is said to be adjacent toadjacent to v, v, and v is said to be
and v is said to be adjacent fromadjacent from u. u.
The vertex u is called the
The vertex u is called the initial vertexinitial vertex of (u, v), of (u, v), and v is called the
and v is called the terminal vertexterminal vertex of (u, v).of (u, v).
The initial vertex and terminal vertex of a loop are The initial vertex and terminal vertex of a loop are the same.
the same.
Graph Terminology Graph Terminology
Definition:
Definition: In a graph with directed edges, the In a graph with directed edges, the inin-- degree
degree of a vertex v, denoted by of a vertex v, denoted by degdeg--(v)(v), is the , is the number of edges with v as their
number of edges with v as their terminal vertexterminal vertex..
The
The outout--degreedegree of v, denoted by of v, denoted by degdeg++(v)(v), is the , is the number of edges with v as their initial vertex.
number of edges with v as their initial vertex.
Question:
Question: How does adding a loop to a vertex How does adding a loop to a vertex change the in
change the in--degree and outdegree and out--degree of that degree of that vertex?
vertex?
Answer:
Answer: It increases both the inIt increases both the in--degree and the degree and the
Graph Terminology Graph Terminology
Example:
Example: What are the inWhat are the in--degrees and outdegrees and out--
degrees of the vertices a, b, c, d in this graph:
degrees of the vertices a, b, c, d in this graph:
aa bb
cc d
d deg
deg--(a) = 1(a) = 1 deg
deg++(a) = 2(a) = 2
deg
deg--(b) = 4(b) = 4 deg
deg++(b) = 2(b) = 2
deg
deg--(d) = 2(d) = 2 deg
deg++(d) = 1(d) = 1
deg
deg--(c) = 0(c) = 0 deg
deg++(c) = 2(c) = 2
Graph Terminology Graph Terminology
Theorem:
Theorem: Let G = (V, E) be a graph with directed Let G = (V, E) be a graph with directed edges. Then:
edges. Then:
vvVV degdeg--(v) = (v) = vvVV degdeg++(v) = |E|(v) = |E|
This is easy to see, because every new edge This is easy to see, because every new edge increases both the sum of in
increases both the sum of in--degrees and the sum degrees and the sum of out
of out--degrees by one. degrees by one.
Special Graphs Special Graphs
Definition:
Definition: The The complete graphcomplete graph on n vertices, on n vertices, denoted by K
denoted by Knn, is the simple graph that contains , is the simple graph that contains exactly one edge between each pair of distinct exactly one edge between each pair of distinct vertices.
vertices.
K
K11 KK22 KK33 KK44 KK55
Special Graphs Special Graphs
Definition:
Definition: The The cyclecycle CCnn, n , n  3, consists of n 3, consists of n vertices v
vertices v11, v, v22, …, v, …, vnn and edges {vand edges {v11, v, v22}, {v}, {v22, v, v33}, …, }, …, {v
{vnn--11, v, vnn}, {v}, {vnn, v, v11}.}.
C
C33 CC44 CC55 CC66
Special Graphs Special Graphs
Definition:
Definition: We obtain the We obtain the wheelwheel WWnn when we add when we add an additional vertex to the cycle C
an additional vertex to the cycle Cnn, for n , for n  3, and 3, and connect this new vertex to each of the n vertices connect this new vertex to each of the n vertices in C
in Cnn by adding new edges.by adding new edges.
W
W33 WW44 WW55 WW66
Special Graphs Special Graphs
Definition:
Definition: The The nn--cube, cube, denoted by Qdenoted by Qnn, is the , is the graph that has vertices representing the 2
graph that has vertices representing the 2nn bit bit strings of length n. Two vertices are adjacent if strings of length n. Two vertices are adjacent if and only if the bit strings that they represent and only if the bit strings that they represent differ in exactly one bit position.
differ in exactly one bit position.
Q
Q11 QQ QQ
0
0 11
00
00 0101
11 11 10
10
000
000 001001
101 100 101
100
010
010 011011
111 111 110
110
Special Graphs Special Graphs
Definition:
Definition: A simple graph is called A simple graph is called bipartitebipartite if its if its vertex set V can be partitioned into two disjoint vertex set V can be partitioned into two disjoint nonempty sets V
nonempty sets V11 and Vand V22 such that every edge in such that every edge in the graph connects a vertex in V
the graph connects a vertex in V11 with a vertex in with a vertex in V
V22 (so that no edge in G connects either two (so that no edge in G connects either two vertices in V
vertices in V11 or two vertices in Vor two vertices in V22).).
For example, consider a graph that represents For example, consider a graph that represents each person in a village by a vertex and each each person in a village by a vertex and each marriage by an edge.
marriage by an edge.
This graph is
This graph is bipartitebipartite, because each edge , because each edge connects a vertex in the
connects a vertex in the subset of malessubset of males with a with a vertex in the
vertex in the subset of femalessubset of females (if we think of (if we think of traditional marriages).
traditional marriages).
Special Graphs Special Graphs
Example I:
Example I: Is CIs C33 bipartite?bipartite?
vv11
vv22 vv33
No, because there is no way to No, because there is no way to
partition the vertices into two sets partition the vertices into two sets so that there are no edges with
so that there are no edges with both endpoints in the same set.
both endpoints in the same set.
Example II:
Example II: Is CIs C66 bipartite?bipartite?
vv55 vv11
vv22
vv66 vv11 vv66
vv22 vv55
Yes, because Yes, because we can display we can display C
C like this:like this:
Special Graphs Special Graphs
Definition:
Definition: The The complete bipartite graphcomplete bipartite graph KKm,nm,n is is the graph that has its vertex set partitioned into the graph that has its vertex set partitioned into two subsets of m and n vertices, respectively. Two two subsets of m and n vertices, respectively. Two vertices are connected if and only if they are in
vertices are connected if and only if they are in different subsets.
different subsets.
K
K3,23,2 KK3,43,4
Operations on Graphs Operations on Graphs
Definition:
Definition: A A subgraphsubgraph of a graph G = (V, E) is a of a graph G = (V, E) is a graph H = (W, F) where W
graph H = (W, F) where WV and FV and FE.E.
Note:
Note: Of course, H is a valid graph, so we cannot Of course, H is a valid graph, so we cannot remove any endpoints of remaining edges when remove any endpoints of remaining edges when creating H.
creating H.
Example:
Example:
K
K subgraph of Ksubgraph of K
Operations on Graphs Operations on Graphs
Definition:
Definition: The The unionunion of two simple graphs Gof two simple graphs G11 = = (V
(V11, E, E11) and G) and G22 = (V= (V22, E, E22) is the simple graph with ) is the simple graph with vertex set V
vertex set V11  VV22 and edge set Eand edge set E11  EE22. . The union of G
The union of G11 and Gand G22 is denoted by is denoted by GG11  GG22..
G
G11 GG22 GG1 1  GG2 2 = K= K55