Graphs. Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices,...
-
Upload
gavin-warren -
Category
Documents
-
view
215 -
download
0
Transcript of Graphs. Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices,...
Graphs
Definition A simple graph G= (V, E) consists of vertices, V, a
nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges.
•- no arrows
•- no loops
•- can't have multiple edges joining vertices
A simple graph
DefinitionA multigraph G=(V, E) consists of a set V of
vertices, a set E of edges, and a function f from E to {{u, v} | u, v V, u v}. The edges e1 and e2 are called multiple or parallel edges if f(e1) = f(e2).
A multigraph
No loop is allowed.
• Multiple edges are allowed.
DefinitionA pseudograph G = (V, E) consists of a set V of
vertices, a set E of edges, and a function f from E to {{u, v} | u, v V}. An edge is a loop if f(e) = {u, v} for some v V.
Definition◦ A directed graph (V, E) consists of a set of a set of
vertices V and a set of edges E that are ordered pairs of elements of V.
Loops, ordered pairs or the same element, are allowed.
Multiple edges in the same direction between two vertices are not allowed.
A directed graph
Definition◦ A directed multigraph G = (V, E) consists of a set
V of vertices, a set E of edges, and a function f from E to {(u, v) | u, v V}. The edges e1 and e2 are multiple edges if f(e1) = f(e2).
•Loops, ordered pairs or the same element, are allowed.
Multiple edges in the same direction between two vertices are allowed.
A directed multigraph
Summary
Type Edges Multiple edges allowed?
Loops allowed?
Simple graph
Undirected No No
Multigraph Undirected Yes No
Pseudograph Undirected Yes Yes
Directed graph
Directed No Yes
Directed multigraph
Directed Yes Yes
There will be an edge (a, b) from team a to team b, if team a beats team b.
• Adjacent:
• Two vertices u and v in an undirected graph G
are called adjacent (or neighbours) if {u, v} is an
edge of G.
• If e = {u, v} the edge e is called incident with u and v. The edge e is also said to connect u and v. The vertices u and v are called endpoints of the edge {u, v}.
15
a bc
de
e1 e2
e3
e4
e5
e6
• Vertex a is adjacent to b because there is an edge e1 that connects vertices a and b.
• Edge e4 is incident with vertices a and d.
• Edge e4 connect vertices a and d.
• Edge e6 connect vertices e and e.
• The degree of a vertex in an undirected
graph is the number of edges incident with
it, except that a loop at a vertex contributes
twice to the degree of that vertex.
• The degree of the vertex v is denoted by
deg(v).
18
What are the degrees of the vertices in the following graph?
•
• ••
• •
•
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
0Vertex of degree zero is called isolated
19
Theorem:Suppose the vertices of graph G are v1, v2, …,
vn, where n is a non-negative integer, then the total degree of G
=deg(v1) + deg(v2) + …. + deg(vn)
= 2 (the number of edges of G).
Total number of edges: 4 Total degree: 1 + 1 + 1 + 5 = 8. Handshaking theorem: 2 x 4 = 8.
21
How many edges are there in a graph with seven vertices each of degree four?• The sum of the degrees of the vertices is
4x7 = 28.
2e = 28
e = 14.
Three methods1.Adjacency lists2.Adjacency matrices3.Incidence matrices
Adjacency lists
Vertex Adjacent Verticesa b,c,eb ac a,d,ed c,ee a,c,d
b
a c
deA simple graph
UNABLE TO REPRESENT MULTIPLE-EDGES.
Initial vertex Terminal verticesa b, c, d, eb b, dc a, c, ede b, c, d
A directed graph
Adjacency matrices
Suppose that G=(V, E) is a simple graph where |V|=n. Suppose that the vertices of G are listed arbitrary as v1,v2,..., vn. The adjacency matrix A of G is a n×n zero-one matrix with 1 as its (i, j)th entry when vi and vj are adjacent, and 0 as its entry when they are not adjacent.
1 if { , ) is an edge of G
0 otherwise
i j
ij
v va
0 1 1 1
1 0 1 0
1 1 0 0
1 0 0 0
a b
c d
G Adjacency matrix for G
Representing multigraph or pseudograph
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
c
d
e
Adjacency Matrix
Incidence Matrices
Let G=(V, E) be an undirected graph. Suppose
that v1, v2, ..., vn are the vertices and e1, e2, ...,
em are the edges G. The incidence matrix of G
is a nx m matrix M=[mij], where
1 when edge is incident with ,
0 otherwise
j i
ij
e vm
1 2 3 4 5 6
1
2
3
4
5
1 1 0 0 0 0
0 0 1 1 0 1
0 0 0 0 1 1
1 0 1 0 0 0
0 1 0 1 1 0
e e e e e e
v
v
v
v
v
Incidence Matrix
Definition
Let n be a nonnegative integer and G a
directed multigraph. A path of length n from u
to v in G is a sequence of edges e1, e2, ..., en
of G such that f(e1)=(x0, x1), f(e2)=(x1, x2),
f(en)=(xn-1, xn), where x0=u and xn=v.
DefinitionWhen there are non multiple edges in the
directed graph, this path is denoted by its
vertex sequence x0, x1, x2, ..., xn.
A path of length greater than zero that begins
and ends at the same vertex is called a circuit
or cycle.
A path or circuit is simple if it does not contain
the same edge more than once.
a, d, c, f, e is a simple path of length 4 since {a, d}, {d, c}, {c, f}, and {f, e} are all edges and no repeated edge.b, c, f, e, b is a circuit of length 4 since this path begins and ends at b.The path a, b, e, d, a, b is of length 5, is not simple since it contains the edge {a, b} twice.Is a, d, e, a, b a simple path?
Paths from v0 to v
7
1. v0 v
1 v
2 v
5 v
7
2. v0 v
1 v
4 v
5 v
4 v
5 v
7
3. v0 v
3 v
4 v
6 v
7
Which path(s) is (are) simple?
DefinitionAn undirected graph is called connected if
there is a path between every pair of distinct vertices of the graph.
G is connected, whereas H is not.
Theorem
There is a simple path between every pair of distinct
vertices of a connected undirected graph.
DefinitionA directed graph is strongly connected if there
is a path from a to b and from b to a whenever a and b are vertices in the graph.
DefinitionA directed graph is weakly connected if there
is a path between any two vertices in the underlying undirected graph.
G is strongly connected because there is a path between any two vertices in this directed graph.
The graph H is not strongly connected. There is no directed path from a to b in this graph. H is weakly connected since there is a path between any two vertices in the underlying undirected graph of H.
Questions
Can we travel along the edges of graph
starting at a vertex and returning to it by
traversing each edge of the graph exactly
once?
Can we travel along the edges of a graph
starting at a vertex and returning to it while
visiting each vertex of the graph exactly
once?
Definition
An Euler circuit in a graph G is a simple circuit
containing every edge of G.
An Euler path in G is a simple path containing
every edge in G.
Note: Both in Euler path and Euler circuit, each edge cannot be repeated more than once.
If a graph has Euler circuit then it must has Euler path, the opposite could be false.
Example
• Theorem 1
• A connected multigraph has an Euler circuit if
and only if each of its vertices has even degree.
• Theorem 2
• A connected multigraph has an Euler path but
not an Euler circuit if and only if it has exactly
two vertices of odd degree.
For graph G1, the degree for each vertex in this graph is even, hence this graph contain Euler circuit.
For graph G2, the degree for vertex e, a are odd, so there is no Euler circuit.
G1 G2
G1 contains exactly two vertices of odd degree, b and d. Hence it has an Euler path that must have b and d as its end points. E.g.:b, c, d, a, b, d.
G2 also contains exactly two vertices of odd degree, d and b. One of the Euler path is b, a, g, b, c, g, f, c, f, e, d.
Definition
• A path x0, x1, ..., xn-1, xn in the graph G = (V,
E) is called a Hamilton path if V={x0, x1, ...,
xn-1, xn} and xixj for 0 ijn
• A circuit x0, x1, ..., xn-1, xn , x0(with n > 1) in a
graph G = (V,E) is called a Hamilton circuit
◦if x0, x1, ..., xn-1 Hamilton path.
Graph G1 has a Hamilton circuit: a, b, c, d, e, a.
There is no Hamilton circuit in G2 because edge (a, b) will be always use twice. E.g.: d, c, b, a, b, d. G2 has Hamilton path, a, b, c, d.
• A graph with a vertex of degree 1 cannot
have a Hamilton circuit.
• If each vertex in a graph is adjacent to
every other vertex there is always a
Hamilton circuit.