Pciu Final Graph - Part - 1
Pciu Final Graph - Part - 1
Pciu Final Graph - Part - 1
Introduction to Graphs
Chapter 8- Rosen
Chapter 8,9- Schaum’s Outlines
What is Graph?
• A graph G = (V, E) consists of a set of objects
V = {v1, v2, …} called vertices, and another set
E = {e1, e2, …}, whose elements are called
edges, such that each edge ek is identified with
an unordered pair (v1, v2) of vertices.
• Suppose G = (V, E) is a graph where V1 V4
• V = {v1, v2, v3, v4}
• E = {(v1, v2), (v2, v3), (v3, v1), (v3, v4)}
V2 V3
Applications
7 88
88
77
22 9 1
1 66
9
11 33
5
5 22 33
99 66
2
55 44
44
Applications
• Scheduling
Applications
• Job assignments
People
Jobs
The House-and-Utilities Problem
Applications
• Utilities Problem
H1 H2 H3
W G E
Simple Graph Example
Detroit
New York
San Francisco
Chicago
Denver Washington
Los Angeles
Washington
Pseudographs
Multigraphs
Simple Graphs
Directed Graph
The edges are ordered pairs of (not necessarily
distinct) vertices.
Detroit
Chicago New York
San Francisco
Denver Washington
Los Angeles
Detroit
New York
Chicago
San Francisco
Denver Washington
Los Angeles
Directed
Multigraphs
Directed Graphs
Graph Models
In concurrent
processing,
some statements
must be
executed before
other statements.
A precedence
graph represents
these
relationships.
Hollywood Graph
Chapter 8.2
Graph Terminology
Graph Terminology
• Finite Graph:
• Finite number of vertices had finite number of edges
• Trivial Graph:
– The finite graph with one vertex and no edge
Adjacent Vertices in Undirected
Graphs
• Two vertices, u and v in an undirected graph G are
called adjacent (or neighbors) in G, if {u,v} is an edge
of G.
• An edge e connecting u and v is called incident with
vertices u and v, or is said to connect u and v.
• The vertices u and v are called endpoints of edge {u,v}.
Degree of a Vertex
a g f e
(u, v)
e d f
Find the in-degrees and out-degrees of this digraph.
In-degrees: deg-(a) = 2, deg-(b) = 2, deg-(c) = 3,
deg-(d) = 2, deg-(e) = 3, deg-(f) = 0
Out-degrees: deg+(a) = 4, deg+(b) = 1, deg+(c) = 2,
deg+(d) = 2, deg+(e) = 3, deg+(f) = 0
Handshaking Theorem
In an undirected graph
1
| E | deg( e)
2 eE
An undirected graph has an even number of
vertices of odd degree:
2| E | deg() deg()
eV eV 1
deg()
eV 2
Handshaking Theorem
c d
b
a g f e
• Find the degrees of all the vertices:
deg(a) = 2, deg(b) = 6, deg(c) = 4, deg(d) = 1,
deg(e) = 0, deg(f) = 3, deg(g) = 4
So (2+6+4+1+0+3+4)/2=20/2=10
Theorem 3
• The sum of the in-degrees of all vertices in
a digraph = the sum of the out-degrees =
the number of edges.
• Let G = (V, E) be a graph with directed
edges. Then:
deg v deg v E
vV
vV
Complete Graph
Cycles: C3 C4 C5 C6
Wheel
When a new vertex is added to a cycle Cn and
this new vertex is connected to each of the n
vertices in Cn, we obtain a wheel Wn.
Wheels: W3 W4 W5 W6
Bipartite Graph
A simple graph is called bipartite if its vertex set V
can be partitioned into two disjoint nonempty sets
V1 and V2 such that every edge in the graph
connects a vertex in V1 and a vertex in V2 (so that
no edge in G connects either two vertices in V1 or
two vertices in V2).
a b a
b
c d d
c
e e
Graph Theoretic Foundations
• Bipartite Graph
Graph Theoretic Foundations
• Bipartite Graph
• Complete bipartite graph
Bipartite Graph (Example)
1 2
Is C6 Bipartite?
6 3
Yes. Why? 5 4
Because:
• its vertex set can be partitioned into the two
sets V1 = {v1, v3, v5} and V2 = {v2, v4, v6}
• every edge of C6 connects a vertex in V1
with a vertex in V2
Bipartite Graph (Example)
1
Is K3 Bipartite?
No. Why not?
2 3
Because:
• Each vertex in K3 is connected to every other
vertex by an edge
• If we divide the vertex set of K3 into two disjoint
sets, one set must contain two vertices
• These two vertices are connected by an edge
• But this can’t be the case if the graph is bipartite
Graph Theoretic Foundations
• Subgraphs
K5 C5
Is C5 a subgraph of K5?
Union
• The union of 2 simple graphs G1 = (V1, E1) and
G2 = (V2, E2) is the simple graph with vertex set V
= V1V2 and edge set E = E1E2. The union is
denoted by G1G2.
c c c
b d b f
f b d d
a e a e a e
S5 C5 W5
S5 C5 = W5
CSE 211
Discrete Mathematics
Chapter 8.3
Representing Graphs and
Graph Isomorphism
§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
e b a, c, e, f
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.
0 1
node Terminal nodes
0 3
1 0, 2, 4
2 1
3 3
2 4
4 0,2
Adjacency Matrix
• A simple graph G = (V,E) with n vertices
can be represented by its adjacency matrix,
A, where the entry aij in row i and column j
is:
1 if { vi ,v j } is an edge in G
aij
0 otherwise
Adjacency Matrix Example
c
To
a b c d e f
b d From
f a 0 1 0 0 1 1
b 1 0 1 0 0 1
a e c 0 1 0 1 0 1
d 0 0 1 0 1 1
W5 e 1 0 0 1 0 1
f 1 1 1 1 1 0
{v1,v2}
row column
Adjacency Matrices
• Matrix A=[aij], where aij is 1 if {vi, vj} is an
edge of G, 0 otherwise.
a
a b c d
b a 0 1 1 1
b 1
0 1 0
d
c 1 1 0 0
c
d 1 0 0 0
Adjacency Matrices for pseudo graph
• Matrix A=[aij], where aij is the number of
edges that are associated to {vi, vj}
a b c d
a
b
a 0 3 0 2
b 3
0 1 1
c 0 1 1 2
c
d d 2 1 2 0
Incidence Matrix
• Let G = (V,E) be an undirected graph.
Suppose v1,v2,v3,…,vn are the vertices and
e1,e2,e3,…,em are the edges of G. The
incidence matrix w.r.t. this ordering of V
and E is the nm matrix M = [mij], where
1 if edge e j is incident with vi
mij
0 otherwise
Incidence Matrix Example
• Represent the graph shown with an
incidence matrix.
e1 e2 e3 e4 e5 e6 edges
v1 v2 v3
e6 v11 1 0 0 0 0
e3 v02 0 1 1 0 1
e1 e4
e5 v03 0 0 0 1 1
e2
v14 0 1 0 0 0
v4 v5
v05 1 0 1 1 0
vertices
Incidence matrices
• Matrix M=[mij], where mij is 1 when edge ej
is incident with vi, 0 otherwise
v1 e2 e1 e2 e3 e4 e5
e3 v4
v1 1 1 1 0 0
e1 e4
0
0 1 1 0
v2
e5 v2
v3 1 0 0 0 1
v3
v4 0 1 0 1 1
Isomorphism
u1 u2 v1 v2
u3 u4 v3 v4
G H
e
e c f
f
Are These Isomorphic?
• If isomorphic, label the 2nd graph to show the
isomorphism, else identify difference.
* Same # of
a
vertices
b
* Same # of
edges
d
* Different
c e # of vertices of
degree 2!
(1 vs 3)
Example 11: a more general solution
Invariants
• Invariants – properties that two simple
graphs must have in common to be
isomorphic
– Same number of vertices
– Same number of edges
– Degrees of corresponding vertices are the same
– If one is bipartite, the other must be; if one is
complete, the other must be; and others …
Example
b b
a c a c
e d e d
G H