9.0 graphs full set
TRANSCRIPT
-
8/6/2019 9.0 Graphs Full Set
1/63
TERRIN [email protected]
ext 3714
Dept of Computational Science & Mathematics
FCSIT, UNIMAS
TMC1813TMC1813
DISCRETE MATHEMATICSDISCRETE MATHEMATICS[9.0[9.0 Introduction to Graphs]Introduction to Graphs]
Sem I 2010/2011
-
8/6/2019 9.0 Graphs Full Set
2/63
DefinitionsDefinitions
def: A vertexvertexis a point, e.g. in 3-
space,
def: An edgeedge is a space curve
(without self-intersections) joining a
vertex to itself or to another vertex.Such vertices are called endpointsendpoints of
the edge.
def: Two vertices are adjacentadjacentif thereis an edge joining them.
def: A graphgraph is a collection ofverticesvertices (V) and edgesedges (E).
2
-
8/6/2019 9.0 Graphs Full Set
3/63
Type of GraphsType of Graphs
def: A graph is simplesimple if
(1) no self-loops, and
(2) at most one undirectedundirected edgeedge
between any pair of vertices. (better
etymology: simplicial)
3
A simple graphG = (V, E) consists ofV,a nonempty set ofvertices, and E, a setof unordered pairs of distinct elementsofVcalled edges.
A Graph
Asimple Graph
-
8/6/2019 9.0 Graphs Full Set
4/63
Type of Graphs (Cont)Type of Graphs (Cont)
Graphs with multiple edges between pairs of
vertices allowed is called multigraphs.
Definition:
A multigraphmultigraph G = (V, E) consists of a set Vof
vertices, a set Eof edges, and a functionffrom E
to {{u, v} | u, v V, u { v}. The edges e1 and e2are called multiple or parallel edges iff(e1) =f(e2).
4
Every simple graph isalso a multigraph.
-
8/6/2019 9.0 Graphs Full Set
5/63
Type of Graphs (Cont)Type of Graphs (Cont)
Edges from a vertex to itself, or loops, are not
allowed in multigraphs. Graphs with loops arecalledpseudographspseudographs.
Definition:
Apseudographpseudograph G = (V, E) consists of a set Vof
vertices, a set Eof edges, and a functionffrom E
to {{u, v} | u, v V}. An edge is a looploop iff(e) = {u,
v} = {u} for some u V
5
-
8/6/2019 9.0 Graphs Full Set
6/63
Type of Graphs (Cont)Type of Graphs (Cont)
Directed graphs are used to model direction of
edges between vertices. Directed graphs allowed loops of the same vertex
but multiple edges in the same direction
between two vertices are not.
Definition:
A directed graphdirected graph (V, E) consists of a set of
vertices Vand a set of edges Ethat are ordered
pairs of elements ofV.
6
-
8/6/2019 9.0 Graphs Full Set
7/63
Type of Graphs (Cont)Type of Graphs (Cont)
Directed multigraphs allow multiple directed
edges from a vertex to a second vertex.
Definition:
A directeddirected multigraphmultigraph G = (V, E) consists of a
set Vof vertices, a set Eof edges, and a functionffrom Eto {{u, v} | u, v V}. The edges e1 and e2are multiple edgesare multiple edges iff(e1) =f(e2).
7
-
8/6/2019 9.0 Graphs Full Set
8/63
Summary of The Type of GraphsSummary of The Type of Graphs
8
Type Edges Multiple EdgesAllowed LoopsAllowed
Simple Graph
Multigraph
Pseudograph
Directed Graph
Directed
Multigraph
Undirected
Undirected
Undirected
Directed
Directed
No
Yes
Yes
No
Yes
No
No
Yes
Yes
Yes
-
8/6/2019 9.0 Graphs Full Set
9/63
Example: A Computer network graphExample: A Computer network graph
If multiple connection are possiblebetween two machines, we would
have a multigraph If a connection can only be one-way,
then we would have a directed
(multi)graph. 9
Computer 1 Computer 2
Computer 3
Computer 5Computer 4
-
8/6/2019 9.0 Graphs Full Set
10/63
SummarySummary
Type of graphs Simple Graph
Multigraph
Pseudograph
Directed Graph
Directed Multigraph
10
-
8/6/2019 9.0 Graphs Full Set
11/63
TERRIN [email protected]
ext 3714
Dept of Computational Science & Mathematics
FCSIT, UNIMAS
9.2 Graph Terminology9.2 Graph Terminology
Sem I 2007/2008
-
8/6/2019 9.0 Graphs Full Set
12/63
-
8/6/2019 9.0 Graphs Full Set
13/63
Example 1Example 1
What are the degrees of the vertices
in the following graph?
13
b
a
c
f e
d
g
deg(a) =
deg(b) =
deg(c) =
deg(d) =
deg(e) =
deg(f) =
deg(g) =
2
4
4
3
1
4
0
Vertex of degree zero is calledisolated.
Vertex of only 1 degree iscalled pendant.
d is pendant and gis isolated.
-
8/6/2019 9.0 Graphs Full Set
14/63
The Handshaking TheoremThe Handshaking Theorem
Theorem:
Let G = (V, E) be an undirected graph
with e edges. Then
This theorem shows that the sum of
the degrees of the vertices of anundirected graph is even.
14
2e = 7 deg(v)v V
-
8/6/2019 9.0 Graphs Full Set
15/63
Example 2Example 2
How many edges are there in a graph
with seven vertices each of degreefour?
The sum of the degrees of the vertices is
4.7 = 28.
2e = 28, e = 14.
15
-
8/6/2019 9.0 Graphs Full Set
16/63
TheoremTheorem
An undirected graph has an even number of vertices
with odd degrees.
In a directed graph, the in-degree of a
vertex v, denoted by deg(v), is
number of edges with v as theirterminal vertex.
The out-degree ofv, denoted by
deg+(v), is the number of edges with vas their initial vertex.
Theorem: Let G = (V, E) be a directed graph. Then
16 deg(v) = deg
(v) = |E|v V v V
-
8/6/2019 9.0 Graphs Full Set
17/63
-
8/6/2019 9.0 Graphs Full Set
18/63
-
8/6/2019 9.0 Graphs Full Set
19/63
-
8/6/2019 9.0 Graphs Full Set
20/63
nn--CubesCubes The n-dimensional cube, n-cube, denoted by Q
n, is the
graph that has vertices representing the 2n bit strings of
length n.
Two vertices are adjacent if and only if the bit string s
that they represent differ in exactly one position.
Q1 Q2
Q3
20
0 1
00 01
10 11
000
100
011
110 111
010
101
001
-
8/6/2019 9.0 Graphs Full Set
21/63
SubgraphSubgraph
A subgraph of a graph G = (V, E) is a
graph H = (W, F) where W V and F E.
Example: S is a subgraph of K5
21
a
c
e
d
b
a
c
e b
K5S
-
8/6/2019 9.0 Graphs Full Set
22/63
SummarySummary
Adjacency and The Degree of a Vertex
The Handshaking Theorem
Complete Graph
Cycles Wheels
n-Cubes
Subgraph
22
-
8/6/2019 9.0 Graphs Full Set
23/63
-
8/6/2019 9.0 Graphs Full Set
24/63
AdjacencyAdjacency LListist RRepresentationepresentation
DEF: An adjacency list fora vertexvof a
graph Gis a list containing each vertex wofGonce for each edge between vand w.
DEF: An adjacency list representation of a
graph is a table of all the adjacency lists.
24
-
8/6/2019 9.0 Graphs Full Set
25/63
Adjacency ListsAdjacency Lists
Examples:
25
Vertex AdjacentVertices
a
b
c
d
e
b, c, e
a
a,d,e
c,e
a,c,d
Initial Vertex Terminal
Vertex
a
b
c
d
e
b, e
b
a,d,
c,e
-
e d
a c
b
e d
a c
b
-
8/6/2019 9.0 Graphs Full Set
26/63
Adjacency MatricesAdjacency Matrices
Suppose G = (V, E) is a simple graph
where |V| =n. The adjacency matrixA (or AG) of G is the n v n zero-one
matrix.
Matrix AG = [aij], where
26
aij =1 if{vi , vj} is an edge of G0 otherwise
-
8/6/2019 9.0 Graphs Full Set
27/63
AAdjacencydjacency MMatrixatrix RRepresentationepresentation
Adjacency matrix Adjacency matrix
27
0 1 1 0 1
1 0 0 0 0
1 0 0 1 1
0 0 1 0 1
1 0 1 1 0
a b c d ea
b
c
d
e
0 1 0 0 1
0 1 0 0 0
1 0 0 1 0
0 0 1 0 1
0 0 0 0 0
a b c d ea
b
cd
e
e d
a c
e d
a c
bb
-
8/6/2019 9.0 Graphs Full Set
28/63
Adjacency Matrices (Cont)Adjacency Matrices (Cont)
Can also be used to represent graphs
with loops and multiple edges(pseudographs) by letting each matrixelements be the number of links
(possibly >1) between the nodes. When multiple edges are present, the
adjacency matrix is no longer a zero-one matrix.
An entry of this matrix equals to thenumber of edges that are associatedto {ai, aj}.
28
-
8/6/2019 9.0 Graphs Full Set
29/63
Adjacency Matrix for PseudographsAdjacency Matrix for Pseudographs
Example:
Find the adjacency matrix for the
following graph
29
0 3 0 2
3 0 1 10 1 1 2
2 1 2 0
a
d c
b
-
8/6/2019 9.0 Graphs Full Set
30/63
-
8/6/2019 9.0 Graphs Full Set
31/63
IsomorphismIsomorphism
Example:
Determine if the graphs G = (V, E) and H = (W, F)below are isomorphic. Give the possible
correspondence.
31
The functionf(a) = 1,f(b) = 4,f(c) = 3,f(d) = 2 is a 1-to-1 and ontocorrespondence between Vand W. Thisalso preserves adjacency where
(a, b) = (1, 4); (a, b) = (1, 3) and soonHence, the graphs areisomorphicand the possible correspondenceis:
a-1, b-4, c-3 and d-2.
a
c
b
dG
1
3 4
2
H
-
8/6/2019 9.0 Graphs Full Set
32/63
Graph Invariants under IsomorphismGraph Invariants under Isomorphism
Graphs that are not isomorphic are
called invariant. To be isomorphic, three properties
should be met.
Graph G1=(V1, E1) is isomorphic tograph G2=(V2, E2) iff:
|V1| = |V2|, and |E1| = |E2|.
The number of vertices with degreen
is thesame in both graphs.
For every proper subgraph g of graph G1, thereis a proper subgraph of graph G2 that isisomorphic to g.
32
-
8/6/2019 9.0 Graphs Full Set
33/63
Isomorphism ExampleIsomorphism Example
If isomorphic, label the 2nd graph to
show the isomorphism, else identify
difference.
33
ab
cd
e f
b
d
a
e
fc
-
8/6/2019 9.0 Graphs Full Set
34/63
-
8/6/2019 9.0 Graphs Full Set
35/63
SummarySummary
Adjacency List Representation
Adjacency Lists
Adjacency Matrices
Adjacency Matrix Representation Adjacency Matrix for Pseudographs
Graph Isomorphism
Graph Invariants
35
-
8/6/2019 9.0 Graphs Full Set
36/63
TERRIN [email protected]
ext 3714
Dept of Computational Science & Mathematics
FCSIT, UNIMAS
9.4 Connectivity9.4 Connectivity
TMC 1813 Discrete Mathematics
Sem I 2009/2010
-
8/6/2019 9.0 Graphs Full Set
37/63
-
8/6/2019 9.0 Graphs Full Set
38/63
38
8.4: Connectivity
In an undirected graph, apath of length n
from u to vis a sequence of adjacent edgesgoing from vertex u to vertex v.
A path is a circuitif it begins and ends at the
same vertex that is u=vand has length
greater then zero.A path or circuit is also called simple if it
does not contain the same edge more then
once.
A path traverses the vertices along it.
-
8/6/2019 9.0 Graphs Full Set
39/63
39
8.4: Connectivity
a b c
d e f
a,d,c,f,e
isasimplepathoflength 4.
-
8/6/2019 9.0 Graphs Full Set
40/63
6/12/2011
40
8.4: Connectivity8.4: Connectivity
b,c,f,e,b isa
circuit oflength 4.
a b c
d e f
-
8/6/2019 9.0 Graphs Full Set
41/63
41
Paths in Directed Graphs
Same as in undirected graphs, but the path must go inthe direction of the arrows.
For ease of reference the definitions are summarized inthe following table.
Repeated Edge? Repeated Vertex? Start and Ends at
Same Point?
Path yes allowed allowed
Simple path no no no
Circuit yes allow
ed yes
Simple circuit no First and last only yes
-
8/6/2019 9.0 Graphs Full Set
42/63
-
8/6/2019 9.0 Graphs Full Set
43/63
-
8/6/2019 9.0 Graphs Full Set
44/63
44
Directed ConnectednessDirected Connectedness
A directed graph is strongly connectediff there is
a directed path from a to b for any two verticesa and b.
It is weakly connectediff the underlyingundirectedgraph (i.e., with edge directionsremoved) is connected.
Note stronglyimplies weaklybut not vice-versa.
Any strongly connected directed graph is alsoweekly connected.
-
8/6/2019 9.0 Graphs Full Set
45/63
45
Directed ConnectednessDirected ConnectednessAre the directed graphs G and H
shown in figure 5 strongly
connected? Are they weeklyconnected
aa aabb bb
cc cc
dd ddee ee
GG HHStrongly andweakly connected Weakly connected
-
8/6/2019 9.0 Graphs Full Set
46/63
46
Paths & IsomorphismPaths & Isomorphism
Note that connectedness, and the
existence of a circuit or simple circuitof length kare graph invariants with
respect to isomorphism.
-
8/6/2019 9.0 Graphs Full Set
47/63
47
Counting Paths w Adjacency MatricesCounting Paths w Adjacency Matrices
Let A be the adjacency matrix of graph
G.
The number of paths of length kfrom
vito vjis equal to (Ak)i,j.
The notation (M)i,jdenotes mi,jwhere
[mi,j]=M.
-
8/6/2019 9.0 Graphs Full Set
48/63
48
Counting Paths w Adjacency MatricesCounting Paths w Adjacency Matrices
Example
How many paths of length 4 are there from
aa to ddin the simple graph a below?
aa bb
ccdd
-
8/6/2019 9.0 Graphs Full Set
49/63
-
8/6/2019 9.0 Graphs Full Set
50/63
-
8/6/2019 9.0 Graphs Full Set
51/63
TERRIN [email protected]
ext 3714
Dept of Computational Science & Mathematics
FCSIT, UNIMAS
9.5 Euler & Hamilton Paths9.5 Euler & Hamilton Paths
TMC 1813 Discrete Mathematics
l & il hl & il h
-
8/6/2019 9.0 Graphs Full Set
52/63
52
Euler & Hamilton PathsEuler & Hamilton Paths
An EEuler circuituler circuitin a graph G is a simple circuit
containing every edge ofG.
An EEuler pathuler path in G is a simple path containing
every edge ofG.
A HamilHamiltton circuiton circuitis a circuit that traverses each
vertex in G exactly once.
A HamilHamiltton pathon path is a path that traverses each
vertex in G exactly once.
-
8/6/2019 9.0 Graphs Full Set
53/63
H il Ci iH il Ci i
-
8/6/2019 9.0 Graphs Full Set
54/63
54
Hamiltons CircuitHamiltons Circuit
Which of these graph has a Hamilton circuit and
which one has a Hamilton path?
aa bb
cc
dd
ee
aa bb
ccdd
G1G1G2G2
HamiltonHamilton
circuitcircuit
HamiltonHamilton
pathpath
-
8/6/2019 9.0 Graphs Full Set
55/63
E l P th Th
-
8/6/2019 9.0 Graphs Full Set
56/63
56
Euler Path Theorems
Theorem: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. 636
TheoremTheorem: 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.
-
8/6/2019 9.0 Graphs Full Set
57/63
E l Ci it Al ithE l Ci it Al ith
-
8/6/2019 9.0 Graphs Full Set
58/63
58
Euler Circuit AlgorithmEuler Circuit Algorithm
Begin with any arbitrary node.
Construct a simple path from it till youget back to start.
Repeat for each remaining subgraph,
splicing results back into original
cycle.
H il V R dH il V R d hh W ld P lW ld P l
-
8/6/2019 9.0 Graphs Full Set
59/63
59
Hamiltons Voyage RoundHamiltons Voyage Round--thethe--World PuzzleWorld Puzzle
Can we traverse all the vertices of a
dodecahedron, visiting each once?`
Dodecahedron
puzzle
Equivalent
graph
Pegboard version
H ilt i P th ThH ilt i P th Th
-
8/6/2019 9.0 Graphs Full Set
60/63
60
Hamiltonian Path TheoremsHamiltonian Path Theorems
Diracs theoremDiracs theorem: If (but not only if) G
is connected, simple, has nu3 vertices,and vdeg(v)un/2, then G has a
Hamilton circuit.
Ores corollaryOres corollary: IfG is connected,simple, has n3 nodes, and
deg(u)+deg(v)n for every pair u,vof
non-adjacent nodes, then G has aHamilton circuit.
HAMHAM CIRCUIT i NPCIRCUIT i NP l tl t
-
8/6/2019 9.0 Graphs Full Set
61/63
61
HAMHAM--CIRCUIT is NPCIRCUIT is NP--completecomplete
Let HAM-CIRCUIT be the problem:
Given a simple graph G, does G contain aHamiltonian circuit?
This problem has been proven to be
NP-complete! This means, if an algorithm for solving it
in polynomial time were found, it could
be used to solve allNP problems inpolynomial time.
-
8/6/2019 9.0 Graphs Full Set
62/63
FIN!FIN!
-
8/6/2019 9.0 Graphs Full Set
63/63
FIN!FIN!
Tutorial Following week!
9.4 pg.629
4, 8, 14, 20, 24
9.5 pg.643
8, 14, 18, 24, 30,
32, 38, 42, 44